diff options
author | DR695H <dr695h@att.com> | 2019-05-01 18:52:33 -0400 |
---|---|---|
committer | DR695H <dr695h@att.com> | 2019-05-01 18:53:14 -0400 |
commit | ae6fedd18ad51f175d6a2e2346f284a68b6e4967 (patch) | |
tree | 40cf730e4178000533b83ebffdf6abe04011ce06 /robotframework-onap/eteutils/HEATUtils.py | |
parent | 308b44cc1e6b95df3051e5f7db94389696763cca (diff) |
support python 3
support python 3 in all files, also support python 2 however so
everything should continue to work
Change-Id: I4ace08d2bb0623c0fdc61f2fe39d2339817aa916
Issue-ID: TEST-141
Signed-off-by: DR695H <dr695h@att.com>
Diffstat (limited to 'robotframework-onap/eteutils/HEATUtils.py')
-rw-r--r-- | robotframework-onap/eteutils/HEATUtils.py | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/robotframework-onap/eteutils/HEATUtils.py b/robotframework-onap/eteutils/HEATUtils.py index 15c5689..93d556a 100644 --- a/robotframework-onap/eteutils/HEATUtils.py +++ b/robotframework-onap/eteutils/HEATUtils.py @@ -1,51 +1,52 @@ import json import yaml -import StringIO +import io import copy from hashlib import md5 from paramiko import RSAKey from paramiko.ssh_exception import PasswordRequiredException + class HEATUtils: """ Utilities useful for constructing OpenStack HEAT requests """ def get_yaml(self, template_file): """Template Yaml To Json reads a YAML Heat template file returns a JSON string that can be used included in an Openstack Add Stack Request""" - if isinstance(template_file, basestring): + if isinstance(template_file, str): fin = open(template_file, 'r') yamlobj = yaml.load(fin) return yamlobj return None - + def template_yaml_to_json(self, template_file): """Template Yaml To Json reads a YAML Heat template file returns a JSON string that can be used included in an Openstack Add Stack Request""" - if isinstance(template_file, basestring): + if isinstance(template_file, str): fin = open(template_file, 'r') yamlobj = yaml.load(fin) fin.close() if 'heat_template_version' in yamlobj: datetime = yamlobj['heat_template_version'] yamlobj['heat_template_version'] = str(datetime) - fout = StringIO.StringIO() + fout = io.BytesIO() json.dump(yamlobj, fout) contents = fout.getvalue() fout.close() return contents - + def env_yaml_to_json(self, template_file): """Env Yaml To JSon reads a YAML Heat env file and returns a JSON string that can be used included in an Openstack Add Stack Request""" - if isinstance(template_file, basestring): + if isinstance(template_file, str): fin = open(template_file, 'r') yamlobj = yaml.load(fin) fin.close() if 'parameters' in yamlobj: - fout = StringIO.StringIO() + fout = io.BytesIO() json.dump(yamlobj['parameters'], fout) contents = fout.getvalue() fout.close() return contents return None - + def stack_info_parse(self, stack_info): """ returns a flattened version of the Openstack Find Stack results """ d = {} @@ -56,24 +57,23 @@ class HEATUtils: d['id'] = s['id'] d['name'] = s['stack_name'] d['stack_status'] = s['stack_status'] - return d - - + return d + def match_fingerprint(self, pvt_file, pw, fingerprint): try: sshKey = RSAKey.from_private_key_file(pvt_file, pw) keybytes = md5(sshKey.asbytes()).hexdigest() - printableFingerprint = ':'.join(a+b for a,b in zip(keybytes[::2], keybytes[1::2])) + printableFingerprint = ':'.join(a + b for a, b in zip(keybytes[::2], keybytes[1::2])) return printableFingerprint == fingerprint.__str__() except PasswordRequiredException: - return False - + return False + def match_private_key_file_to_keypair(self, files, keypair): for keyfile in files: if (self.match_fingerprint(keyfile, None, keypair['keypair']['fingerprint'])): return keyfile return None - + def get_openstack_server_ip(self, server, network_name="public", ipversion=4): ipaddr = None try: |