def __init__(self, username, name, subclass_type=None, dir_yaml=None, dir_diag=None, dir_output=None, img_type=None): # init params with default values if subclass_type is None: subclass_type = self.subclass_type_list[0] if dir_yaml is None: dir_yaml = self.guessDefaultConfigLocation() if dir_diag is None: dir_diag = self.guessDefaultDiagLocation() if dir_output is None: dir_output = self.guessDefaultDiagramLocation() if img_type is None: img_type = self.image_type_list[0] # set login username self.set_login_username(username) abs_dir_yaml = cm_path_expand(dir_yaml) abs_dir_diag = cm_path_expand(dir_diag) abs_dir_output = cm_path_expand(dir_output) log.debug("The output directory of rack diagram is {0}".format(abs_dir_output)) # make sure the output directory exist if not path.exists(abs_dir_output): mkdir("-p", abs_dir_output) self.readClustersConfig(abs_dir_yaml) self.readRackConfig(name, abs_dir_yaml, abs_dir_diag) self.setRackImageType(subclass_type, img_type, abs_dir_output) self.initDictServers() self.get_map_progress()
def __init__(self, username, name, subclass_type=None, dir_yaml=None, dir_diag=None, dir_output=None, img_type=None): # init params with default values if subclass_type is None: subclass_type = self.subclass_type_list[0] if dir_yaml is None: dir_yaml = self.guessDefaultConfigLocation() if dir_diag is None: dir_diag = self.guessDefaultDiagLocation() if dir_output is None: dir_output = self.guessDefaultDiagramLocation() if img_type is None: img_type = self.image_type_list[0] # set login username self.set_login_username(username) abs_dir_yaml = cm_path_expand(dir_yaml) abs_dir_diag = cm_path_expand(dir_diag) abs_dir_output = cm_path_expand(dir_output) log.debug("The output directory of rack diagram is {0}".format( abs_dir_output)) # make sure the output directory exist if not path.exists(abs_dir_output): mkdir("-p", abs_dir_output) self.readClustersConfig(abs_dir_yaml) self.readRackConfig(name, abs_dir_yaml, abs_dir_diag) self.setRackImageType(subclass_type, img_type, abs_dir_output) self.initDictServers() self.get_map_progress()
def _generate_globals(self): for name in self.config.get("cloudmesh.inventory"): cluster = self.config.get("cloudmesh.inventory")[name] keys = cluster.keys() element = dict({ 'cm_cluster': name, 'cm_id': name, 'cm_type': "inventory", 'cm_kind': 'server', 'cm_key': 'range', 'cm_value': expand_hostlist(cluster["id"]), 'cm_hostlist': cluster["id"], 'cm_attribute': 'variable' }) self.insert(element) for key in keys: if (type(cluster[key]) is str) and \ (not key in ["id", "network"]): element = dict({ 'cm_cluster': name, 'cm_id': name, 'cm_type': "inventory", 'cm_kind': 'server', 'cm_key': key, 'cm_value': cluster[key], 'cm_attribute': 'variable' }) self.insert(element) elif key == "publickeys": publickeys = cluster[key] for k in publickeys: element = dict({ 'cm_cluster': name, 'cm_id': name, 'cm_type': "inventory", 'cm_kind': 'publickey', 'cm_key': k['name'], 'cm_name': cm_path_expand(k['path']), 'cm_value': cluster[key], 'cm_attribute': 'variable' }) self.insert(element)
def _generate_globals(self): for name in self.config.get("cloudmesh.inventory"): cluster = self.config.get("cloudmesh.inventory")[name] keys = cluster.keys() element = dict({'cm_cluster': name, 'cm_id': name, 'cm_type': "inventory", 'cm_kind': 'server', 'cm_key': 'range', 'cm_value': expand_hostlist(cluster["id"]), 'cm_hostlist': cluster["id"], 'cm_attribute': 'variable' }) self.insert(element) for key in keys: if (type(cluster[key]) is str) and \ (not key in ["id", "network"]): element = dict({'cm_cluster': name, 'cm_id': name, 'cm_type': "inventory", 'cm_kind': 'server', 'cm_key': key, 'cm_value': cluster[key], 'cm_attribute': 'variable' }) self.insert(element) elif key == "publickeys": publickeys = cluster[key] for k in publickeys: element = dict({'cm_cluster': name, 'cm_id': name, 'cm_type': "inventory", 'cm_kind': 'publickey', 'cm_key': k['name'], 'cm_name': cm_path_expand(k['path']), 'cm_value': cluster[key], 'cm_attribute': 'variable' }) self.insert(element)
def read_yaml_config(filename, check=True, osreplace=True): ''' reads in a yaml file from the specified filename. If check is set to true the code will faile if the file does not exist. However if it is set to false and the file does not exist, None is returned. :param filename: the file name :param check: if True fails if the file does not exist, if False and the file does not exist return will be None ''' location = filename if location is not None: location = cm_path_expand(location) if not os.path.exists(location) and not check: return None if check and os.path.exists(location): # test for tab in yaml file if check_file_for_tabs(location): log.error("The file {0} contains tabs. yaml " "Files are not allowed to contain tabs".format(location)) sys.exit() try: if osreplace: result = open(location, 'r').read() t = Template(result) result = t.substitute(os.environ) data = yaml.safe_load(result) else: f = open(location, "r") data = yaml.safe_load(f) f.close() return data except Exception, e: log.error( "The file {0} fails with a yaml read error".format(filename)) log.error(str(e)) print traceback.format_exc() sys.exit()
def read_yaml_config(filename, check=True, osreplace=True): """ reads in a yaml file from the specified filename. If check is set to true the code will faile if the file does not exist. However if it is set to false and the file does not exist, None is returned. :param filename: the file name :param check: if True fails if the file does not exist, if False and the file does not exist return will be None """ location = filename if location is not None: location = cm_path_expand(location) if not os.path.exists(location) and not check: return None if check and os.path.exists(location): # test for tab in yaml file if check_file_for_tabs(location): log.error("The file {0} contains tabs. yaml " "Files are not allowed to contain tabs".format(location)) sys.exit() try: if osreplace: result = open(location, "r").read() t = Template(result) result = t.substitute(os.environ) data = yaml.safe_load(result) else: f = open(location, "r") data = yaml.safe_load(f) f.close() return data except Exception, e: log.error("The file {0} fails with a yaml read error".format(filename)) log.error(str(e)) print traceback.format_exc() sys.exit()