try: if osreplace: result = open(location, 'r').read() t = Template(result) result = t.substitute(os.environ) data = yaml.safe_load(result) data = ordered_load(result, yaml.SafeLoader) else: f = open(location, "r") data = yaml.safe_load(f) data = ordered_load(result, yaml.SafeLoader) 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() else: log.error("The file {0} does not exist.".format(filename)) # sys.exit() return None
# TODO: the try methods at the beginning should be called on teh first # call of this method to load the data. otherwise they should not be # called, e.g. dynamic loading # TODO: the defaults should be read at the beginning and when any # command is used that needs them. a logic needs to be defined so that # defaults are included in other methods after their first loading. a # boolean should help prevent constant reloading. # TODO: when printing flavors or images numbers are given instead of # user readable labels. in case of images the uuid is given try: config = cm_config() except: log.error("There is a problem with the configuration yaml files") try: mongoClass = cm_mongo() except: log.error("There is a problem with the mongo server") class cm_shell_defaults: defDict = {} default_loaded = False def activate_cm_shell_defaults(self): self.register_command_topic('cloud', 'defaults')
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() else: log.error("The file {0} does not exist.".format(filename)) sys.exit() return None
# call of this method to load the data. otherwise they should not be # called, e.g. dynamic loading # TODO: the defaults should be read at the beginning and when any # command is used that needs them. a logic needs to be defined so that # defaults are included in other methods after their first loading. a # boolean should help prevent constant reloading. # TODO: when printing flavors or images numbers are given instead of # user readable labels. in case of images the uuid is given try: config = cm_config() except: log.error("There is a problem with the configuration yaml files") try: mongoClass = cm_mongo() except: log.error("There is a problem with the mongo server") class cm_shell_defaults: defDict = {} default_loaded = False def activate_cm_shell_defaults(self): self.register_command_topic('cloud','defaults')