def _get_oses_from_configuration(): """Get all os configs from os configuration dir. Example: { <os_name>: { 'name': <os_name>, 'id': <os_name>, 'os_id': <os_name>, 'deployable': True } } """ configs = util.load_configs(setting.OS_DIR) systems = {} for config in configs: logging.info('get config %s', config) system_name = config['NAME'] parent_name = config.get('PARENT', None) system = { 'name': system_name, 'id': system_name, 'os_id': system_name, 'parent': parent_name, 'parent_id': parent_name, 'deployable': config.get('DEPLOYABLE', False) } systems[system_name] = system parents = {} for name, system in systems.items(): parent = system.get('parent', None) parents[name] = parent for name, system in systems.items(): util.recursive_merge_dict(name, systems, parents) return systems
def _add_roles_from_configuration(): """Get roles from roles config dir and update to adapters.""" configs = util.load_configs(setting.ADAPTER_ROLE_DIR) for config in configs: logging.info('add config %s to role', config) adapter_name = config['ADAPTER_NAME'] adapter = ADAPTERS[adapter_name] adapter_roles = ADAPTERS_ROLES.setdefault(adapter_name, {}) for role_dict in config['ROLES']: role_name = role_dict['role'] display_name = role_dict.get('display_name', role_name) adapter_roles[role_name] = { 'name': role_name, 'id': '%s:%s' % (adapter_name, role_name), 'adapter_id': adapter_name, 'adapter_name': adapter_name, 'display_name': display_name, 'description': role_dict.get('description', display_name), 'optional': role_dict.get('optional', False) } parents = {} for name, adapter in ADAPTERS.items(): parent = adapter.get('parent', None) parents[name] = parent for adapter_name, adapter_roles in ADAPTERS_ROLES.items(): util.recursive_merge_dict(adapter_name, ADAPTERS_ROLES, parents) for adapter_name, adapter_roles in ADAPTERS_ROLES.items(): adapter = ADAPTERS[adapter_name] adapter['roles'] = adapter_roles.values()
def _add_roles_from_configuration(): """Get roles from roles config dir and update to adapters.""" configs = util.load_configs(setting.ADAPTER_ROLE_DIR) for config in configs: logging.info( 'add config %s to role', config ) adapter_name = config['ADAPTER_NAME'] adapter = ADAPTERS[adapter_name] adapter_roles = ADAPTERS_ROLES.setdefault(adapter_name, {}) for role_dict in config['ROLES']: role_name = role_dict['role'] display_name = role_dict.get('display_name', role_name) adapter_roles[role_name] = { 'name': role_name, 'id': '%s:%s' % (adapter_name, role_name), 'adapter_id': adapter_name, 'adapter_name': adapter_name, 'display_name': display_name, 'description': role_dict.get('description', display_name), 'optional': role_dict.get('optional', False) } parents = {} for name, adapter in ADAPTERS.items(): parent = adapter.get('parent', None) parents[name] = parent for adapter_name, adapter_roles in ADAPTERS_ROLES.items(): util.recursive_merge_dict(adapter_name, ADAPTERS_ROLES, parents) for adapter_name, adapter_roles in ADAPTERS_ROLES.items(): adapter = ADAPTERS[adapter_name] adapter['roles'] = adapter_roles.values()
def _get_adapters_from_configuration(): """Get adapters from adapter config dir.""" configs = util.load_configs(setting.ADAPTER_DIR) adapters = {} for config in configs: logging.info('add config %s to adapter', config) if 'OS_INSTALLER' in config: os_installer = OS_INSTALLERS[config['OS_INSTALLER']] else: os_installer = None if 'PACKAGE_INSTALLER' in config: package_installer = PACKAGE_INSTALLERS[ config['PACKAGE_INSTALLER'] ] else: package_installer = None adapter_name = config['NAME'] parent_name = config.get('PARENT', None) adapter = { 'name': adapter_name, 'id': adapter_name, 'parent': parent_name, 'parent_id': parent_name, 'display_name': config.get('DISPLAY_NAME', adapter_name), 'os_installer': os_installer, 'package_installer': package_installer, 'deployable': config.get('DEPLOYABLE', False), 'health_check_cmd': config.get('HEALTH_CHECK_COMMAND', None), 'supported_oses': [], 'roles': [], 'flavors': [] } supported_os_patterns = [ re.compile(supported_os_pattern) for supported_os_pattern in config.get('SUPPORTED_OS_PATTERNS', []) ] for os_name, os in OSES.items(): if not os.get('deployable', False): continue for supported_os_pattern in supported_os_patterns: if supported_os_pattern.match(os_name): adapter['supported_oses'].append(os) break adapters[adapter_name] = adapter parents = {} for name, adapter in adapters.items(): parent = adapter.get('parent', None) parents[name] = parent for name, adapter in adapters.items(): util.recursive_merge_dict(name, adapters, parents) return adapters
def _get_adapters_from_configuration(): """Get adapters from adapter config dir.""" configs = util.load_configs(setting.ADAPTER_DIR) adapters = {} for config in configs: logging.info('add config %s to adapter', config) if 'OS_INSTALLER' in config: os_installer = OS_INSTALLERS[config['OS_INSTALLER']] else: os_installer = None if 'PACKAGE_INSTALLER' in config: package_installer = PACKAGE_INSTALLERS[config['PACKAGE_INSTALLER']] else: package_installer = None adapter_name = config['NAME'] parent_name = config.get('PARENT', None) adapter = { 'name': adapter_name, 'id': adapter_name, 'parent': parent_name, 'parent_id': parent_name, 'display_name': config.get('DISPLAY_NAME', adapter_name), 'os_installer': os_installer, 'package_installer': package_installer, 'deployable': config.get('DEPLOYABLE', False), 'health_check_cmd': config.get('HEALTH_CHECK_COMMAND', None), 'supported_oses': [], 'roles': [], 'flavors': [] } supported_os_patterns = [ re.compile(supported_os_pattern) for supported_os_pattern in config.get('SUPPORTED_OS_PATTERNS', []) ] for os_name, os in OSES.items(): if not os.get('deployable', False): continue for supported_os_pattern in supported_os_patterns: if supported_os_pattern.match(os_name): adapter['supported_oses'].append(os) break adapters[adapter_name] = adapter parents = {} for name, adapter in adapters.items(): parent = adapter.get('parent', None) parents[name] = parent for name, adapter in adapters.items(): util.recursive_merge_dict(name, adapters, parents) return adapters
def _add_flavors_from_configuration(): """Get flavors from flavor config dir and update to adapters.""" configs = util.load_configs(setting.ADAPTER_FLAVOR_DIR) for config in configs: logging.info('add config %s to flavor', config) adapter_name = config['ADAPTER_NAME'] adapter = ADAPTERS[adapter_name] adapter_flavors = ADAPTERS_FLAVORS.setdefault(adapter_name, {}) adapter_roles = ADAPTERS_ROLES[adapter_name] for flavor_dict in config['FLAVORS']: flavor_name = flavor_dict['flavor'] flavor_id = '%s:%s' % (adapter_name, flavor_name) flavor = { 'name': flavor_name, 'id': flavor_id, 'adapter_id': adapter_name, 'adapter_name': adapter_name, 'display_name': flavor_dict.get('display_name', flavor_name), 'template': flavor_dict.get('template', None) } flavor_roles = flavor_dict.get('roles', []) roles_in_flavor = [] for flavor_role in flavor_roles: if isinstance(flavor_role, basestring): role_name = flavor_role role_in_flavor = { 'name': role_name, 'flavor_id': flavor_id } else: role_in_flavor = flavor_role role_in_flavor['flavor_id'] = flavor_id if 'role' in role_in_flavor: role_in_flavor['name'] = role_in_flavor['role'] del role_in_flavor['role'] role_name = role_in_flavor['name'] role = adapter_roles[role_name] util.merge_dict(role_in_flavor, role, override=False) roles_in_flavor.append(role_in_flavor) flavor['roles'] = roles_in_flavor adapter_flavors[flavor_name] = flavor parents = {} for name, adapter in ADAPTERS.items(): parent = adapter.get('parent', None) parents[name] = parent for adapter_name, adapter_roles in ADAPTERS_FLAVORS.items(): util.recursive_merge_dict(adapter_name, ADAPTERS_FLAVORS, parents) for adapter_name, adapter_flavors in ADAPTERS_FLAVORS.items(): adapter = ADAPTERS[adapter_name] adapter['flavors'] = adapter_flavors.values()
def _get_packages_metadata_from_configuration(): """Get package metadata from package metadata config dir.""" packages_metadata = {} env_locals = {} env_locals.update(metadata_validator.VALIDATOR_LOCALS) env_locals.update(metadata_callback.CALLBACK_LOCALS) configs = util.load_configs( setting.PACKAGE_METADATA_DIR, env_locals=env_locals ) for config in configs: adapter_name = config['ADAPTER'] package_metadata = packages_metadata.setdefault(adapter_name, {}) for key, value in config['METADATA'].items(): package_metadata[key] = _get_metadata_from_configuration( key, key, value, PACKAGE_FIELDS ) adapters = adapter_api.ADAPTERS parents = {} for adapter_name, adapter in adapters.items(): parent = adapter.get('parent', None) parents[adapter_name] = parent for adapter_name, adapter in adapters.items(): packages_metadata[adapter_name] = util.recursive_merge_dict( adapter_name, packages_metadata, parents ) return packages_metadata
def _get_oses_metadata_from_configuration(): """Get os metadata from os metadata config dir.""" oses_metadata = {} env_locals = {} env_locals.update(metadata_validator.VALIDATOR_LOCALS) env_locals.update(metadata_callback.CALLBACK_LOCALS) configs = util.load_configs( setting.OS_METADATA_DIR, env_locals=env_locals ) for config in configs: os_name = config['OS'] os_metadata = oses_metadata.setdefault(os_name, {}) for key, value in config['METADATA'].items(): os_metadata[key] = _get_metadata_from_configuration( key, key, value, OS_FIELDS ) oses = adapter_api.OSES parents = {} for os_name, os in oses.items(): parent = os.get('parent', None) parents[os_name] = parent for os_name, os in oses.items(): oses_metadata[os_name] = util.recursive_merge_dict( os_name, oses_metadata, parents ) return oses_metadata
def _get_flavors_metadata_ui_converters_from_configuration(): """Get flavor metadata ui converters from flavor mapping config dir.""" flavors_metadata_ui_converters = {} configs = util.load_configs(setting.FLAVOR_MAPPING_DIR) for config in configs: adapter_name = config['ADAPTER'] flavor_name = config['FLAVOR'] flavors_metadata_ui_converters.setdefault( adapter_name, {})[flavor_name] = config.get('CONFIG_MAPPING', {}) adapters = adapter_api.ADAPTERS parents = {} for adapter_name, adapter in adapters.items(): parent = adapter.get('parent', None) parents[adapter_name] = parent for adapter_name, adapter in adapters.items(): flavors_metadata_ui_converters[adapter_name] = ( util.recursive_merge_dict(adapter_name, flavors_metadata_ui_converters, parents)) return flavors_metadata_ui_converters
def _get_oses_metadata_ui_converters_from_configuration(): """Get os metadata ui converters from os metadata mapping config dir. os metadata ui converter is used to convert os metadata to the format UI can understand and show. """ oses_metadata_ui_converters = {} configs = util.load_configs(setting.OS_MAPPING_DIR) for config in configs: os_name = config['OS'] oses_metadata_ui_converters[os_name] = config.get('CONFIG_MAPPING', {}) oses = adapter_api.OSES parents = {} for os_name, os in oses.items(): parent = os.get('parent', None) parents[os_name] = parent for os_name, os in oses.items(): oses_metadata_ui_converters[os_name] = util.recursive_merge_dict( os_name, oses_metadata_ui_converters, parents) return oses_metadata_ui_converters
def _get_flavors_metadata_ui_converters_from_configuration(): """Get flavor metadata ui converters from flavor mapping config dir.""" flavors_metadata_ui_converters = {} configs = util.load_configs(setting.FLAVOR_MAPPING_DIR) for config in configs: adapter_name = config['ADAPTER'] flavor_name = config['FLAVOR'] flavors_metadata_ui_converters.setdefault( adapter_name, {} )[flavor_name] = config.get('CONFIG_MAPPING', {}) adapters = adapter_api.ADAPTERS parents = {} for adapter_name, adapter in adapters.items(): parent = adapter.get('parent', None) parents[adapter_name] = parent for adapter_name, adapter in adapters.items(): flavors_metadata_ui_converters[adapter_name] = ( util.recursive_merge_dict( adapter_name, flavors_metadata_ui_converters, parents ) ) return flavors_metadata_ui_converters
def _get_oses_metadata_ui_converters_from_configuration(): """Get os metadata ui converters from os metadata mapping config dir. os metadata ui converter is used to convert os metadata to the format UI can understand and show. """ oses_metadata_ui_converters = {} configs = util.load_configs(setting.OS_MAPPING_DIR) for config in configs: os_name = config['OS'] oses_metadata_ui_converters[os_name] = config.get('CONFIG_MAPPING', {}) oses = adapter_api.OSES parents = {} for os_name, os in oses.items(): parent = os.get('parent', None) parents[os_name] = parent for os_name, os in oses.items(): oses_metadata_ui_converters[os_name] = util.recursive_merge_dict( os_name, oses_metadata_ui_converters, parents ) return oses_metadata_ui_converters
def _get_packages_metadata_from_configuration(): """Get package metadata from package metadata config dir.""" packages_metadata = {} env_locals = {} env_locals.update(metadata_validator.VALIDATOR_LOCALS) env_locals.update(metadata_callback.CALLBACK_LOCALS) configs = util.load_configs(setting.PACKAGE_METADATA_DIR, env_locals=env_locals) for config in configs: adapter_name = config['ADAPTER'] package_metadata = packages_metadata.setdefault(adapter_name, {}) for key, value in config['METADATA'].items(): package_metadata[key] = _get_metadata_from_configuration( key, key, value, PACKAGE_FIELDS) adapters = adapter_api.ADAPTERS parents = {} for adapter_name, adapter in adapters.items(): parent = adapter.get('parent', None) parents[adapter_name] = parent for adapter_name, adapter in adapters.items(): packages_metadata[adapter_name] = util.recursive_merge_dict( adapter_name, packages_metadata, parents) return packages_metadata
def _get_oses_metadata_from_configuration(): """Get os metadata from os metadata config dir.""" oses_metadata = {} env_locals = {} env_locals.update(metadata_validator.VALIDATOR_LOCALS) env_locals.update(metadata_callback.CALLBACK_LOCALS) configs = util.load_configs(setting.OS_METADATA_DIR, env_locals=env_locals) for config in configs: os_name = config['OS'] os_metadata = oses_metadata.setdefault(os_name, {}) for key, value in config['METADATA'].items(): os_metadata[key] = _get_metadata_from_configuration( key, key, value, OS_FIELDS) oses = adapter_api.OSES parents = {} for os_name, os in oses.items(): parent = os.get('parent', None) parents[os_name] = parent for os_name, os in oses.items(): oses_metadata[os_name] = util.recursive_merge_dict( os_name, oses_metadata, parents) return oses_metadata