def get_from_yaml(cls, filename=None, load_order=None, store=True): """ :param filename: name of the yaml file :return: a SSHKeyManager (dict of keys) """ config = None if filename is None: # default = Config.path_expand(os.path.join("~", ".cloudmesh", "cloudmesh.yaml")) # config = ConfigDict("cloudmesh.yaml") filename = "cloudmesh.yaml" config = ConfigDict(filename) elif load_order: config = ConfigDict(filename, load_order) else: Console.error("Wrong arguments") return config_keys = config["cloudmesh"]["keys"] default = config_keys["default"] keylist = config_keys["keylist"] uri = Config.path_expand(os.path.join("~", ".cloudmesh", filename)) d = [] for key in list(keylist.keys()): keyname = key value = keylist[key] if os.path.isfile(Config.path_expand(value)): path = Config.path_expand(value) if store: Key.add_from_path(path, keyname) else: d.append(Key.add_from_path(path, keyname, store=False)) else: keytype, string, comment = SSHkey._parse(value) thekey = { 'uri': 'yaml://{}'.format(uri), 'string': value, 'fingerprint': SSHkey._fingerprint(value), 'name': keyname, 'comment': comment, 'source': 'git', 'kind': 'key' } thekey["type"], thekey["key"], thekey[ "comment"] = SSHkey._parse(value) if thekey["comment"] is None: thekey["comment"] = keyname if store: try: cls.cm.add(thekey) except: Console.error("Key already in db", traceflag=False) else: d.append(thekey) if not store: return d """
def entry(cls, name): banner("Register {}".format(name)) name = str(name) etc_config = ConfigDict("cloudmesh.yaml", etc=True) config = ConfigDict("cloudmesh.yaml") clouds = config["cloudmesh.clouds"] clusters = config["cloudmesh.hpc.clusters"] if name in clouds: name = "cloudmesh.clouds.{}.credentials".format(name) elif name in clusters: name = "cloudmesh.hpc.clusters.{}.credentials".format(name) elif not name.startswith("cloudmesh."): name = "cloudmesh." + name try: etc = etc_config[name] yaml = config[name] # walk yaml for key in etc: if etc[key] == "TBD": result = input("Enter {:} ({:}): ".format(key, yaml[key])) if result != '': yaml[key] = result config.save() except Exception as e: Console.error("Could not find {} in the yaml file".format(name), traceflag=False)
def get_apikey(endpoint): config = ConfigDict("cloudmesh.yaml") cometConf = config["cloudmesh.comet"] defaultUser = cometConf["username"] user = input("Comet nucleus username [%s]: " \ % defaultUser) if not user: user = defaultUser password = getpass.getpass() keyurl = "%s/getkey" % cometConf["endpoints"][endpoint]["nucleus_base_url"] headers = {"ACCEPT": "application/json"} r = requests.get(keyurl, headers=headers, auth=HTTPBasicAuth(user, password)) if r.status_code == 200: keyobj = r.json() api_key = keyobj["key_name"] api_secret = keyobj["key"] config = ConfigDict("cloudmesh.yaml") config.data["cloudmesh"]["comet"]["endpoints"] \ [endpoint]["auth_provider"] = 'apikey' config.data["cloudmesh"]["comet"]["endpoints"] \ [endpoint]["apikey"]["api_key"] = api_key config.data["cloudmesh"]["comet"]["endpoints"] \ [endpoint]["apikey"]["api_secret"] = api_secret config.save() Console.ok("api key retrieval and set was successful!") else: Console.error("Error getting api key. " "Please check your username/password", traceflag=False)
def from_file(cls, filename): """ Replaces the TBD in cloudmesh.yaml with the contents present in FILEPATH's FILE :param filename: :return: """ if not os.path.isfile(os.path.expanduser(filename)): Console.error("{} doesn't exist".format(filename)) return # BUG should use path separator path, filename = filename.rsplit("/", 1) # Config file to be read from from_config_file = ConfigDict(filename, [path]) config = ConfigDict("cloudmesh.yaml") # Merging profile profile = config["cloudmesh"]["profile"] for profile_key in list(profile.keys()): if profile[profile_key] == "TBD": profile[profile_key] = \ from_config_file["cloudmesh"]["profile"][profile_key] config.save() # Merging clouds clouds = config["cloudmesh"]["clouds"] for cloud in list(clouds.keys()): cloud_element = clouds[cloud] for key in list(cloud_element.keys()): if cloud_element[key] == "TBD": cloud_element[key] = \ from_config_file["cloudmesh"]["clouds"][cloud][key] config["cloudmesh"]["clouds"][cloud] = cloud_element credentials = clouds[cloud]["credentials"] for key in credentials: if credentials[key] == "TBD": credentials[key] = \ from_config_file["cloudmesh"]["clouds"][cloud][ "credentials"][key] config["cloudmesh"]["clouds"][cloud]["credentials"] = credentials defaults = clouds[cloud]["default"] for key in defaults: if defaults[key] == "TBD": defaults[key] = \ from_config_file["cloudmesh"]["clouds"][cloud][ "default"][ key] config["cloudmesh"]["clouds"][cloud]["default"] = defaults config.save() Console.ok( "Overwritten the TBD of cloudmesh.yaml with {} contents".format( filename))
def test_001_read(self): HEADING("test if cloudmesh.yaml is loaded") d = ConfigDict("cloudmesh.yaml", verbose=True) assert d["cloudmesh"]["profile"]["firstname"] != "" assert len(d["cloudmesh"]["clouds"]) > 0 try: d = ConfigDict("cloudmesh.yam", verbose=True) print("the file cloudmesh.yam should not exists") assert False except Exception as e: assert str(e).startswith("Could not find")
def test_002_set(self): HEADING("testing to set a value in the dict") shutil.copy(self.etc_yaml, self.tmp_yaml) d = ConfigDict("cloudmesh.yaml", load_order=[self.tmp_dir], verbose=True) d["cloudmesh"]["profile"]["firstname"] = "Gregor" d.save() d = ConfigDict("cloudmesh.yaml", load_order=[self.tmp_dir], verbose=True) assert d["cloudmesh"]["profile"]["firstname"] == "Gregor"
def get_nova_credentials(kind="yaml", cloud=None): d = {} if kind in ["env"]: d['version'] = '2' d['username'] = os.environ['OS_USERNAME'] d['api_key'] = os.environ['OS_PASSWORD'] d['auth_url'] = os.environ['OS_AUTH_URL'] d['project_id'] = os.environ['OS_TENANT_NAME'] d['cacert'] = path_expand(os.environ['OS_CACERT']) elif kind in ["yaml"]: if cloud is None: raise Exception("cloud not specified") config = dict( ConfigDict(filename="~/.cloudmesh/cloudmesh.yaml")["cloudmesh"] ["clouds"][cloud]) cred = dict(config["credentials"]) d['version'] = '2' d['username'] = cred['OS_USERNAME'] d['api_key'] = cred['OS_PASSWORD'] d['auth_url'] = cred['OS_AUTH_URL'] d['project_id'] = cred['OS_TENANT_NAME'] if 'OS_CACERT' in cred: d['cacert'] = path_expand(cred['OS_CACERT']) else: raise Exception("unsupported kind: " + kind) return d
def logon(self, cloudname): """ Logs onto a cloud :param cloudname: :return: """ CloudProviderOpenstackAPI.cloud_pwd[cloudname] = {} d = ConfigDict("cloudmesh.yaml") credentials = d["cloudmesh"]["clouds"][cloudname]["credentials"] os_password = credentials["OS_PASSWORD"] prompt = "Password for cloud - {}:".format(cloudname) if os_password.lower() == "readline": if 'pwd' in CloudProviderOpenstackAPI.cloud_pwd[cloudname]: os_password = CloudProviderOpenstackAPI.cloud_pwd[cloudname][ "pwd"] else: os_password = getpass.getpass(prompt=prompt) elif os_password.lower() == "env": if 'pwd' in CloudProviderOpenstackAPI.cloud_pwd[cloudname]: os_password = CloudProviderOpenstackAPI.cloud_pwd[cloudname][ "pwd"] else: os_password = os.environ.get("OS_PASSWORD", getpass.getpass(prompt=prompt)) # # TODO: pwd is not standing for passwd # CloudProviderOpenstackAPI.cloud_pwd[cloudname]["pwd"] = os_password CloudProviderOpenstackAPI.cloud_pwd[cloudname]["status"] = "Active" return
def test_001_read(self): HEADING("test if cloudmesh.yaml is loaded") d = ConfigDict("cloudmesh.yaml", verbose=True) assert d["cloudmesh"]["profile"]["firstname"] != "" assert len(d["cloudmesh"]["clouds"]) > 0 """
def setup(self): cloud = "cybera-ec2" config = ConfigDict("cloudmesh.yaml") self.credential = config['cloudmesh']['clouds'][cloud]['credentials'] self.clouddefault = config['cloudmesh']['clouds'][cloud]['default'] # pprint(dict(self.credential)) auth_url = self.credential["EC2_URL"] data = re.match(r'^http[s]?://(.+):([0-9]+)/([a-zA-Z/]*)', auth_url, re.M | re.I) host, port, path = data.group(1), data.group(2), data.group(3) print("host: " + host) print("port: " + port) print("path: " + path) extra_args = {'path': path} cls = get_driver(Provider.EC2_US_EAST) self.driver = cls(self.credential['EC2_ACCESS_KEY'], self.credential['EC2_SECRET_KEY'], host=host, port=port, **extra_args) print("DRIVER", self.driver) assert "libcloud.compute.drivers.ec2.EC2NodeDriver object at" in str( self.driver)
def list(cls, filename, info=False, output='table'): """ lists clouds from cloudmesh.yaml file :param filename: :type filename: string :return: """ config = ConfigDict("cloudmesh.yaml") clouds = config["cloudmesh"]["clouds"] if info: Console.ok("Cloudmesh configuration file: {}".format(filename)) print("") d = {} for i, key in enumerate(clouds.keys()): d[i] = { "id": i, "cloud": key, "iaas": config["cloudmesh"]["clouds"][key]["cm_type"], "version": config["cloudmesh"]["clouds"][key]["cm_type_version"] or "N/A" } return Printer.dict_printer(d, order=['id', 'cloud', 'iaas', 'version'], output=output)
def check_yaml_for_completeness(cls, filename): """ outputs how many values has to be fixed in cloudmesh.yaml file :param filename: the file name :type filename: string :return: """ if filename is None: filename = "cloudmesh.yaml" config = ConfigDict(filename) content = config.yaml Console.ok("Checking the yaml file") count = 0 output = [] for line in content.split("\n"): if "TBD" in line: output.append(textwrap.dedent(line)) count += 1 if count > 0: Console.error("The file has {:} values to be fixed".format(count)) print("") for line in output: Console.error(" " + line, prefix=False)
def var_replacer(self, line, c='$'): vars = self.var_finder(line, c=c) for v in vars["normal"]: value = str(Var.get(v)) line = line.replace(c + v, value) # replace in line the variable $v with value for v in vars["os"]: name = v.replace('os.', '') if name in os.environ: value = os.environ[name] line = line.replace(c + v, value) else: Console.error("can not find environment variable {}".format(v)) if c + v in line: value = os.environ(v) # replace in line the variable $v with value for v in vars["dot"]: try: config = ConfigDict("cloudmesh.yaml") print(config["cloudmesh.profile"]) value = config[v] line = line.replace(c + v, value) except Exception as e: Console.error( "can not find variable {} in cloudmesh.yaml".format(value)) return line
def list(cls, filename, cloud, info=False, output='table'): """ lists clouds from cloudmesh.yaml file :param filename: :type filename: string :return: """ config = ConfigDict("cloudmesh.yaml") clouds = config["cloudmesh"]["clouds"] if info: Console.ok("Cloudmesh configuration file: {}".format(filename)) print("") d = {} for i, key in enumerate(clouds.keys()): d[i] = { "id": i, "cloud": key, "iaas": config["cloudmesh"]["clouds"][key]["cm_type"], "version": config["cloudmesh"]["clouds"][key]["cm_type_version"] or "", # "active": "*" if key in config["cloudmesh"]["active"] else "", "active": config["cloudmesh"]["active"].index(key) + 1 if key in config["cloudmesh"]["active"] else "", "default": "*" if key == cloud else "" } return Printer.Printer.write( d, order=['id', 'default', 'cloud', 'iaas', 'version', 'active'], output=output)
def upload(cls, cloud=None, group=None): if cloud is None: clouds = ConfigDict("cloudmesh.yaml")["cloudmesh"]["active"] else: clouds = [cloud] if group is None: rules = cls.list(output='dict') groups = set() for g in rules: r = rules[g] groups.add(r["group"]) groups = list(groups) else: groups = [group] for cloud in clouds: for g in groups: cls.delete_all_rules_cloud(cloud, g) group = cls.get(name=g, cloud=cloud) group_cloud = cls.get_group_cloud(cloud, g) if not group_cloud: cls.add_group_cloud(cloud, g) rules = cls.list_rules(group=g, output="dict") if rules: for ruleid in rules: rule = rules[ruleid] rulename = rule["name"] cls.add_rule_cloud(cloud, g, rulename) '''
def set_level(log_level): """ sets th eloglevel in the database and the loglevel file from cloudmesh.yaml :param log_level: the loglevel :return: """ # TODO: BUG: This seems inconsistent with our use as it mixes db and # cloudmesh.yaml. level = log_level.upper() Default.set(key=LogUtil.LOG_LEVEL_KEY, value=log_level, category=LogUtil.category) # get log level obj log_level_obj = LogUtil.get_level_obj(log_level) # Read the ConfigDict config = ConfigDict("cloudmesh.yaml") log_file = config["cloudmesh"]["logging"]["file"] # Set the logger config logging.basicConfig(format=LogUtil.FORMAT, level=log_level_obj, filename=path_expand(log_file)) LOGGER.info("Set log level to: " + log_level) return "Ok."
def initialize(self, cloudname, user=None): """ reads the details for the initialization from the cloudname defined in the yaml file Azure cloud requires subscription_id and service management certificate to initialize the provider :param cloudname: :param user: :return: """ confd = ConfigDict("cloudmesh.yaml") cloudcred = confd['cloudmesh']['clouds']['azure']['credentials'] subscription_id = cloudcred['subscriptionid'] certificate_path = cloudcred['managementcertfile'] # DEBUGGING INFO # pprint("subscriptionid:"+subscription_id) # pprint("certificate_path:"+certificate_path) self.provider = ServiceManagementService(subscription_id, certificate_path) self.default_image = confd['cloudmesh']['clouds']['azure']['default'][ 'image'] self.default_flavor = confd['cloudmesh']['clouds']['azure']['default'][ 'flavor'] self.cloud = "azure" self.cloud_details = confd['cloudmesh']['clouds']['azure'] self.location = confd["cloudmesh"]["clouds"]["azure"]["default"][ "location"]
def __init__(self, cloudname, user=None, flat=True): super(CloudProvider, self).__init__(cloudname, user=user) try: d = ConfigDict("cloudmesh.yaml") if not cloudname in d["cloudmesh"]["clouds"]: raise ValueError("the cloud {} is not defined in the yaml file. failed." .format(cloudname)) cloud_details = d["cloudmesh"]["clouds"][cloudname] if cloud_details["cm_type"] == "openstack": provider = CloudProviderOpenstackAPI( cloudname, cloud_details, flat=flat) self.provider = provider self.provider_class = CloudProviderOpenstackAPI if cloud_details["cm_type"] == "ec2": provider = CloudProviderLibcloudEC2( cloudname, cloud_details, flat=flat) self.provider = provider self.provider_class = CloudProviderLibcloudEC2 if cloud_details["cm_type"] == "azure": raise ValueError("azure cloud provider yet implemented. failed.") TODO.implement() except Exception as e: Error.traceback(e)
def construct_ip_dict(cls, ip_addr, name="kilo"): try: d = ConfigDict("cloudmesh.yaml") cloud_details = d["cloudmesh"]["clouds"][name] # Handle Openstack Specific Output if cloud_details["cm_type"] == "openstack": ipaddr = {} for network in ip_addr: index = 0 for ip in ip_addr[network]: ipaddr[index] = {} ipaddr[index]["network"] = network ipaddr[index]["version"] = ip["version"] ipaddr[index]["addr"] = ip["addr"] index += 1 return ipaddr # Handle EC2 Specific Output if cloud_details["cm_type"] == "ec2": print("ec2 ip dict yet to be implemented") TODO.implement() # Handle Azure Specific Output if cloud_details["cm_type"] == "azure": print("azure ip dict yet to be implemented") TODO.implement() except Exception as e: Error.error("error in vm construct dict", traceback=True)
def logon(cls, username=None, password=None): config = ConfigDict("cloudmesh.yaml") cometConf = config["cloudmesh.comet"] cls.set_endpoint(cometConf["active"]) cls.set_base_uri(cometConf["endpoints"][cls.endpoint]["nucleus_base_url"]) cls.set_api_version(cometConf["endpoints"][cls.endpoint]["api_version"]) cls.set_auth_provider() # print (cls.endpoint) # print (cls.base_uri) # print (cls.api_version) # print (cls.auth_provider) ret = False if "USERPASS" == cls.auth_provider: # for unit testing only. if username is None: username = cometConf["endpoints"][cls.endpoint]["userpass"]["username"] if username == '' or username == 'TBD': username = cometConf["username"] if password is None: password = cometConf["endpoints"][cls.endpoint]["userpass"]["password"] if password.lower() == "readline": password = getpass.getpass() elif password.lower() == "env": password = os.environ.get("COMET_PASSWORD", getpass.getpass()) if cls.token is None: if cls.auth_uri: if cls.tunnelled: authuri = "%s/login/" % cls.local_auth_uri else: authuri = "%s/login/" % cls.auth_uri data = {"username": username, "password": password} r = requests.post(authuri, data=json.dumps(data), headers=cls.HEADER, verify=cls.verify) try: cls.token = r.json()["key"] cls.AUTH_HEADER['Authorization'] = "Token {:}".format( cls.token) except: ret = False ret = cls.token else: ret = cls.token elif "APIKEY" == cls.auth_provider: # print ("API KEY based auth goes here") cls.api_key = cometConf["endpoints"][cls.endpoint]["apikey"]["api_key"] cls.api_secret = cometConf["endpoints"][cls.endpoint]["apikey"]["api_secret"] cls.api_auth = HTTPSignatureAuth(secret=cls.api_secret, headers=["nonce", "timestamp"]) # # api key based auth does not maintain a session # once values specified, considered as AuthNed. if cls.api_key and cls.api_secret and cls.api_auth: ret = True else: print("The specified AUTH Provider Not Currently Supported") pass return ret
def load(cls, filename): config = ConfigDict(filename=filename)["cloudmesh"] clouds = config["clouds"] # FINDING DEFAULTS FOR CLOUDS for cloud in clouds: db = { "image": cls.get(name="image", category=cloud), "flavor": cls.get(name="flavor", category=cloud), } defaults = clouds[cloud]["default"] for attribute in ["image", "flavor"]: value = db[attribute] if attribute in defaults: value = db[attribute] or defaults[attribute] empty = cls.get(name=attribute, category=cloud) if empty is None: cls.set(attribute, value, category=cloud) # FINDING DEFAUlTS FOR KEYS # keys: # default: id_rsa # keylist: # id_rsa: ~/.ssh/id_rsa.pub # key_db = SSHKeyDBManager() name_key = cls.key # # SET DEFAULT KEYS # if "keys" in config: keys = config["keys"] name = keys["default"] if name in keys["keylist"]: value = name_key or keys["keylist"][name] # key_db.add(value, keyname=name) # Check if the key is already set exist_key = cls.key # Set the key only if there is no existing value in the DB. if exist_key is None: cls.set_key(name) else: if cls.key is not None and cls.user is not None: pass elif cls.key is None and cls.user is not None: cls.key = cls.user else: Console.error( "Please define a key first, e.g.: cm key add --ssh <keyname>", traceflag=False)
def set_username(cls, username): """ Method that sets the username in yaml. :param username: :return: """ config = ConfigDict("cloudmesh.yaml") config['cloudmesh']['profile']['username'] = username config.save()
def __init__(self): self.__dict__ = self.__shared_state if self.initialized is None: self.filename = Config.path_expand(os.path.join("~", ".cloudmesh", "cloudmesh.db")) self.create() self.create_tables() self.start() self.user = ConfigDict(filename="cloudmesh.yaml")["cloudmesh.profile.user"]
def setup(self): config = ConfigDict("cloudmesh.yaml") self.data = { "cloud": "kilo", } self.data["tenant"] = config["cloudmesh.clouds"][ self.data["cloud"]]["credentials"]["OS_TENANT_NAME"] pass
def set_auth_provider(cls, auth_provider=None): # try to load from yaml file if not specified if not auth_provider: config = ConfigDict("cloudmesh.yaml") cometConf = config["cloudmesh.comet"] auth_provider = cometConf["endpoints"][cls.endpoint]["auth_provider"].upper() # value not set in yaml file, use USERPASS as default if not auth_provider: auth_provider = "USERPASS" cls.auth_provider = auth_provider
def do_var(self, arg, arguments): """ Usage: var list var delete NAMES var NAME=VALUE var NAME Arguments: NAME Name of the variable NAMES Names of the variable separated by spaces VALUE VALUE to be assigned special vars date and time are defined """ if arguments['list'] or arg == '' or arg is None: # self._list_variables() print(Var.list()) return "" elif arguments['NAME=VALUE'] and "=" in arguments["NAME=VALUE"]: (variable, value) = arg.split('=', 1) if value == "time" or value == "now": value = datetime.datetime.now().strftime("%H:%M:%S") elif value == "date": value = datetime.datetime.now().strftime("%Y-%m-%d") elif value.startswith("default."): name = value.replace("default.", "") value = Default.get(name=name, category="general") elif "." in value: try: config = ConfigDict("cloudmesh.yaml") value = config[value] except Exception as e: Console.error( "can not find variable {} in cloudmesh.yaml".format( value)) value = None # self._add_variable(variable, value) Var.set(variable, value) return "" elif arguments['NAME=VALUE'] and "=" not in arguments["NAME=VALUE"]: try: v = arguments['NAME=VALUE'] # Console.ok(str(self.variables[v])) Console.ok(str(Var.get(v))) except: Console.error('variable {:} not defined'.format( arguments['NAME=VALUE'])) elif arg.startswith('delete'): variable = arg.split(' ')[1] Var.delete(variable) # self._delete_variable(variable) return ""
def cloudmesh_clouds(request): config = ConfigDict(filename="cloudmesh.yaml") clouds = config["cloudmesh.clouds"] active = config["cloudmesh.active"] default = Default.get_cloud() data = {} attributes = [ 'cm_label', 'cm_host', 'cm_heading', 'cm_type', 'cm_type_version' ] for cloud in clouds: name = {'cloud': cloud} data[cloud] = {} for attribute in attributes: data[cloud][attribute] = clouds[cloud][attribute] print clouds[cloud]['cm_type'] if clouds[cloud]['cm_type'] == "ec2": data[cloud]['username'] = clouds[cloud]['credentials']['userid'] elif clouds[cloud]['cm_type'] == "azure": data[cloud]['username'] = '******' elif clouds[cloud]['cm_type'] == "openstack": data[cloud]['username'] = clouds[cloud]['credentials'][ 'OS_USERNAME'] if cloud in active: data[cloud]['active'] = 'yes' else: data[cloud]['active'] = 'no' if cloud in [default]: data[cloud]['default'] = 'yes' else: data[cloud]['default'] = 'no' data[cloud]['info'] = ", ".join([ url('d', '/cm/cloud/{cloud}/'.format(**name)), url('i', '/cm/image/{cloud}/'.format(**name)), url('f', '/cm/flavor/{cloud}/'.format(**name)), url('v', '/cm/vm/{cloud}/'.format(**name)) ]) order = [ 'default', 'active', 'cm_label', 'info', 'username', 'cm_host', 'cm_heading', 'cm_type', 'cm_type_version' ] header = [ 'Default', 'Active', 'Label', 'Info', 'Username', 'Host', 'Description', 'Type', 'Version' ] pprint(data) context = { 'data': data, 'title': "Cloud List", 'order': order, 'header': header, } return render(request, 'cloudmesh_portal/dict_table.jinja', context)
def __init__(self, context): """ Init Method :param context: :return: """ self.context = context if self.context.debug: print("Init ConfigEnv") ConfigEnv.yaml_data = ConfigDict("cloudmesh.yaml") ConfigEnv.env_config_data = {"OS_AUTH_URL": None}
def test_004_yaml(self): HEADING("test if yaml is produced") d = ConfigDict("cloudmesh.yaml", verbose=True) result = d.yaml try: assert result.startswith("meta") except Exception as e: print("not valid yaml file.") assert False
def ec2(cls, cloud, zipfile): def sanitize(name): return name.replace(".zip", "").replace("@", "_") def find_exports(filename): with open(filename, "r") as f: content = f.read() data = {} for line in content.split("\n"): if line.startswith("export "): line = line.replace("export ", "") attribute, value = line.split("=", 1) value = value.replace("${NOVA_KEY_DIR}/", "") # remove comments data[attribute] = value.split("#")[0].strip() return data base = sanitize(os.path.basename(zipfile)) dest = sanitize( os.path.join(path_expand("~"), ".cloudmesh", "clouds", cloud, os.path.basename(zipfile))) Console.msg("Unzip file {} -> {}".format(zipfile, dest)) r = Shell.unzip(zipfile, dest) rcfile = os.path.join(dest, "ec2rc.sh") data = find_exports(rcfile) data["DEST"] = dest data["CLOUD"] = cloud d = { "cm_heading": "{CLOUD}, EC2".format(**data), "cm_host": None, "cm_label": "{CLOUD}_ec2".format(**data), "cm_type": "ec2", "cm_type_version": "ec2", "credentials": { "EC2_ACCESS_KEY": "{EC2_ACCESS_KEY}".format(**data), "EC2_SECRET_KEY": "{EC2_SECRET_KEY}".format(**data), "keyname": "TBD_not_used", "userid": "TBD_not_used", "EC2_URL": "{EC2_URL}".format(**data), "EC2_USER_ID": "{EC2_USER_ID}", "EC2_PRIVATE_KEY": "{DEST}/pk.pem".format(**data), "EC2_CERT": "{DEST}/cert.pem".format(**data), "NOVA_CERT": "{DEST}/cacert.pem".format(**data), "EUCALYPTUS_CERT": "{DEST}/cacert.pem".format(**data), }, "default": { "flavor": "m1.small", "image": "None", } } from pprint import pprint config = ConfigDict("cloudmesh.yaml") config["cloudmesh"]["clouds"][cloud] = d config.save()