def create_unordered_dict_from_schema(content_schema, schema_attr_prefix, operand): dict = {} for line in content_schema: key = line[0] val = line[1] if val and (val[0] == LIST_TYPE): schema_attr_prefix = schema_attr_prefix + '_' + key[-1] sub_schema_attr = schema_attr_prefix + '_yaml_schema' sub_dict = create_dict_from_schema(get_schema(sub_schema_attr, operand), schema_attr_prefix, operand) list = [] list.append(sub_dict) line_dict = schema_util.rec_dict_from_list(key, list, True) else: line_dict = schema_util.rec_dict_from_list(key, val, False) dict = schema_util.rec_dict_merge(dict, line_dict) return dict
def get_role_attributes(self, stack_name, role_name, chef_role_name, universe, planet_name): # main app config as dictionary is basis for acquiring role attribtes app_config = self.app_config.app_config # clear list of attributes dictionaries for each role created attr_list = [] service_common = app_config.get( 'common') if app_config is not None else {} if service_common is not None: attr_list.append(service_common) # initialize with service level attributes try: stacks = app_config.get('stacks', {}).get( stack_name, {}) if app_config is not None else {} attr_list.append({k: v for k, v in stacks.items() if k != 'roles'}) except Exception as e: stacks = {} # include role level attributes try: role = stacks.get('roles', {}).get(role_name, {}) attr_list.append( {k: v for k, v in role.items() if k != 'universes'}) except Exception as e: role = {} # include universe level attributes try: universe = role.get('universes', {}).get(universe, {}) attr_list.append( {k: v for k, v in universe.items() if k != 'planets'}) except Exception as e: universe = {} # include planet level attributes (dev, qa, &c.) try: planet = universe.get('planets', {}).get(planet_name, {}) attr_list.append({k: v for k, v in planet.items()}) # HACK to merge the dictionary instead of overwriting merged_dict = {} for i in attr_list: merged_dict = schema.rec_dict_merge(merged_dict, i) # overwrite by merged attr_list.append(merged_dict) except Exception as e: pass # acquire role run list (as list) from artiball stack roles stack_role_config = self.deploy.get_stack_role_config_by_name( stack_name, role_name) chef_role_runlist = stack_role_config['chef_role_runlist'] # format run list per chef's specifications run_list = ['recipe[' + recipe + ']' for recipe in chef_role_runlist] # prepare keyword args role creation chef_role_attr = { "name": chef_role_name, "description": chef_role_name + " description", "json_class": "Chef::Role", "default_attributes": merge_list_of_dicts(attr_list), "override_attributes": {}, "chef_type": "role", "run_list": run_list, "env_run_lists": {} } return chef_role_attr
def get_role_attributes(self, stack_name, role_name, chef_role_name, universe, planet_name): # main app config as dictionary is basis for acquiring role attribtes app_config = self.app_config.app_config # clear list of attributes dictionaries for each role created attr_list = [] service_common = app_config.get('common') if app_config is not None else {} if service_common is not None: attr_list.append(service_common) # initialize with service level attributes try: stacks = app_config.get('stacks', {}).get(stack_name, {}) if app_config is not None else {} attr_list.append({k:v for k, v in stacks.items() if k != 'roles'}) except Exception as e: stacks = {} # include role level attributes try: role = stacks.get('roles', {}).get(role_name, {}) attr_list.append({k:v for k, v in role.items() if k != 'universes'}) except Exception as e: role = {} # include universe level attributes try: universe = role.get('universes', {}).get(universe, {}) attr_list.append({k:v for k, v in universe.items() if k != 'planets'}) except Exception as e: universe = {} # include planet level attributes (dev, qa, &c.) try: planet = universe.get('planets', {}).get(planet_name, {}) attr_list.append({k:v for k, v in planet.items()}) # HACK to merge the dictionary instead of overwriting merged_dict = {} for i in attr_list: merged_dict = schema.rec_dict_merge(merged_dict, i) # overwrite by merged attr_list.append(merged_dict) except Exception as e: pass # acquire role run list (as list) from artiball stack roles stack_role_config = self.deploy.get_stack_role_config_by_name(stack_name, role_name) chef_role_runlist = stack_role_config['chef_role_runlist'] # format run list per chef's specifications run_list = ['recipe[' + recipe + ']' for recipe in chef_role_runlist] # prepare keyword args role creation chef_role_attr = { "name": chef_role_name, "description": chef_role_name + " description", "json_class": "Chef::Role", "default_attributes": merge_list_of_dicts(attr_list), "override_attributes": {}, "chef_type": "role", "run_list" : run_list, "env_run_lists": {} } return chef_role_attr