def app_config(self): filename = os.path.join(self.get_appconfig_path(), self.config_file) if os.path.isfile(filename): app_config = read_yaml_from_file(filename) # TODO: decision ==> stacks converted at instantiation or on-demand stacks = convert_stack_roles_to_dict(app_config.get('stacks')) app_config['stacks'] = stacks return app_config
def init_from_file(cls, id, blueprint_file): # attempt to read file contents try: blueprint = read_yaml_from_file(blueprint_file) except IOError: raise skybase.exceptions.StateDBRecordNotFoundError(id) else: definition = blueprint.get('definition') stacks = blueprint.get('stacks') return cls(id, definition, stacks)
def get_saltapi_authtoken(runner_cfg, planet_name=None): # acquire salt api connection api_creds = read_yaml_from_file(get_creds_file()) api = SkySaltAPI( username=api_creds['username'], password=api_creds['password'], runner_cfg=runner_cfg, planet_name=planet_name, ) api.authorize() return api.authtoken
def init_from_file(cls, service_name, service_dir, filename): # initialize return vars definition = stacks = None # read service from deployment yaml file main_deployment = read_yaml_from_file(filename) # TODO: decision ==> stacks converted at instantiation or on-demand # extract service attributes if main_deployment: definition = main_deployment.get('definition') stacks = convert_stack_roles_to_dict(main_deployment.get('stacks')) return cls(service_name, service_dir, definition, stacks)
def init_from_file(cls, id, metadata_file): # attempt to read file contents try: metadata = read_yaml_from_file(metadata_file) except IOError: raise skybase.exceptions.StateDBRecordNotFoundError(id) else: # map file contents to values and call init name = metadata.get('app_name') version = metadata.get('app_version') build = metadata.get('build_id') artiball = metadata.get('source_artiball') return cls(id, name, version, build, artiball)
def manifest(self): if self.artiball_data_dir and self.artiball_name: # create path to manifest file manifest_file = os.path.join( self.artiball_data_dir, self.artiball_name, ARTIBALL_SCHEMA_ARGS['manifest_file'], ) # return contents of manifest file if exists if os.path.isfile(manifest_file): manifest_data = read_yaml_from_file(yaml_file=manifest_file) if manifest_data: manifest = manifest_data.get('metadata') manifest['chef_cookbook_source'] = manifest_data.get('chef_cookbook_source') return manifest
def init_from_file(cls, schema_name, config_dir=CONFIG_DIR): # prepare configuration filename config_file_name = '/'.join([config_dir, schema_name + '.yaml']) config_file = os.path.expanduser(config_file_name) # read in target configuration filea and attempt to init class try: runner_config_data = read_yaml_from_file(config_file) except (IOError, ScannerError, ParserError) as e: # wrap all expected errors as SkyBaseError type raise SkyBaseConfigurationError(simple_error_format(e)) cfg = cls(schema_name, runner_config_data) return cfg
def manifest(self): if self.artiball_data_dir and self.artiball_name: # create path to manifest file manifest_file = os.path.join( self.artiball_data_dir, self.artiball_name, ARTIBALL_SCHEMA_ARGS['manifest_file'], ) # return contents of manifest file if exists if os.path.isfile(manifest_file): manifest_data = read_yaml_from_file(yaml_file=manifest_file) if manifest_data: manifest = manifest_data.get('metadata') manifest['chef_cookbook_source'] = manifest_data.get( 'chef_cookbook_source') return manifest
def render_string_template_from_files(cls, template_file, data_files): ''' Data_Files is a list of dictionaries {'ns': 'namespacename','filename': 'SomeFileName'} :param template_file: :param data_files: :return: ''' with open(template_file, 'r') as tf: template_string = tf.read() data_dict = {} for df in data_files: data_dict[df['ns']] = schema.read_yaml_from_file(df['filename']) rendered = cls(template_string, **data_dict) return rendered
def render_string_template_from_files(cls, template_file, data_files): """ Data_Files is a list of dictionaries {'ns': 'namespacename','filename': 'SomeFileName'} :param template_file: :param data_files: :return: """ with open(template_file, "r") as tf: template_string = tf.read() data_dict = {} for df in data_files: data_dict[df["ns"]] = schema.read_yaml_from_file(df["filename"]) rendered = cls(template_string, **data_dict) return rendered
def sky_full_rendering(template_file, user_data_files, render_space_files, key_value_dict): ''' :param template_file: main Jinja template :param user_data_files: Jinja templates to be included into main Jinja Template :param name_space_files: list of yaml data file to be used for rendering dict {'names_space': 'filename'} :param key_value_list: List of [ 'keyname'='keyvalue' ] which is converted to dict and keynames are available for rendering :return: ''' result = '' # main template source_template = template_file # process userdata templates so they can be inserted into the main template # for each file do jinja rendering for f in user_data_files: pass # first assemble dictionary of dict to user for rendering: data_dict = dict() for df in render_space_files: data_dict[df['ns']] = schema.read_yaml_from_file(df['filename']) data_dict.update(key_value_dict) with open(template_file, 'r') as tf: template_string = tf.read() rendered_template = JinjaRenderer(template_string, **data_dict) result = rendered_template.body return result
def _load_yaml_data(self): return read_yaml_from_file(yaml_file=self.get_yaml_filename())