def load_config(config_details): """Load the configuration from a working directory and a list of configuration files. Files are loaded in order, and merged on top of each other to create the final configuration. Return a fully interpolated, extended and validated configuration. """ processed_files = [ process_kraftfile(config_file, config_details.environment) for config_file in config_details.config_files ] config_details = config_details._replace(config_files=processed_files) main_file = config_details.config_files[0] if main_file.config is None: raise CannotReadKraftfile(main_file.filename) name = load_mapping(config_details.config_files, 'get_name', 'name', config_details.working_dir) if name is None or len(name) == 0: name = get_project_name(config_details.working_dir, None, config_details.environment) unikraft = load_mapping(config_details.config_files, 'get_unikraft', 'unikraft', config_details.working_dir) arguments = load_mapping(config_details.config_files, 'get_arguments', 'arguments', config_details.working_dir) before = load_mapping(config_details.config_files, 'get_before', 'before', config_details.working_dir) after = load_mapping(config_details.config_files, 'get_after', 'after', config_details.working_dir) targets = load_mapping(config_details.config_files, 'get_targets', 'targets', config_details.working_dir) libraries = load_mapping(config_details.config_files, 'get_libraries', 'libraries', config_details.working_dir) volumes = load_mapping(config_details.config_files, 'get_volumes', 'volumes', config_details.working_dir) networks = load_mapping(config_details.config_files, 'get_networks', 'networks', config_details.working_dir) if isinstance(unikraft, six.string_types): core = Unikraft(version=unikraft) else: core = Unikraft(**unikraft) return Config( specification=main_file.version, name=name, arguments=arguments, before=before, after=after, unikraft=core, targets=TargetManager(targets, core), libraries=LibraryManager(libraries), volumes=VolumeManager(volumes), networks=NetworkManager(networks), )
def __init__(ctx, self, *args, **kwargs): super(Application, self).__init__(*args, **kwargs) # Determine name from localdir if self._name is None and self._localdir is not None: self._name = os.path.basename(self._localdir) self._config = kwargs.get('config', None) # Determine how configuration is passed to this class if self._config is None: unikraft = kwargs.get("unikraft", dict()) if not isinstance(unikraft, Unikraft): unikraft = Unikraft(unikraft) targets = kwargs.get("targets", dict()) if not isinstance(targets, TargetManager): targets = TargetManager(targets) libraries = kwargs.get("libraries", dict()) if not isinstance(unikraft, LibraryManager): libraries = LibraryManager(libraries) networks = kwargs.get("networks", dict()) if not isinstance(networks, NetworkManager): networks = NetworkManager(networks) volumes = kwargs.get("volumes", dict()) if not isinstance(volumes, VolumeManager): volumes = VolumeManager(volumes) self._config = Config( name=kwargs.get('name', None), arguments=kwargs.get("arguments", None), before=kwargs.get("before", None), after=kwargs.get("after", None), unikraft=unikraft, targets=targets, libraries=libraries, volumes=volumes, networks=networks, ) # Check the integrity of the application if self.config.unikraft is None: raise MissingComponent("unikraft") # Initialize the location of the known binaries for target in self.config.targets.all(): binname = target.binary_name(self.config.name) binary = os.path.join(self.localdir, UNIKRAFT_BUILDDIR, binname) if binname is not None: target.binary = binary if self._config is None: self._config = dict()
def unikraft(self, unikraft=None): if unikraft is None: return if isinstance(unikraft, dict): unikraft = Unikraft(**unikraft) elif not isinstance(unikraft, Unikraft): logger.warn("Cannot apply Unikraft to configuration") return self._unikraft = unikraft
def load_config(config_details, use_versions=[]): # noqa: C901 """Load the configuration from a working directory and a list of configuration files. Files are loaded in order, and merged on top of each other to create the final configuration. Return a fully interpolated, extended and validated configuration. """ processed_files = [ process_kraftfile(config_file, config_details.environment) for config_file in config_details.config_files ] config_details = config_details._replace(config_files=processed_files) main_file = config_details.config_files[0] if main_file.config is None: raise CannotReadKraftfile(main_file.filename) name = load_mapping(config_details.config_files, 'get_name', 'name', config_details.working_dir) if name is None or len(name) == 0: name = get_project_name(config_details.working_dir, None, config_details.environment) unikraft = load_mapping(config_details.config_files, 'get_unikraft', 'unikraft', config_details.working_dir) arguments = load_mapping(config_details.config_files, 'get_arguments', 'arguments', config_details.working_dir) before = load_mapping(config_details.config_files, 'get_before', 'before', config_details.working_dir) after = load_mapping(config_details.config_files, 'get_after', 'after', config_details.working_dir) targets = load_mapping(config_details.config_files, 'get_targets', 'targets', config_details.working_dir) libraries = load_mapping(config_details.config_files, 'get_libraries', 'libraries', config_details.working_dir) volumes = load_mapping(config_details.config_files, 'get_volumes', 'volumes', config_details.working_dir) networks = load_mapping(config_details.config_files, 'get_networks', 'networks', config_details.working_dir) # Dynamically update the configuration specification based on version # overrides provided by use_versions for use in use_versions: _type, name, _, version = break_component_naming_format(use) if _type is ComponentType.CORE: unikraft['version'] = version for i, conf in enumerate(targets): if _type is ComponentType.ARCH or _type is None: if 'architecture' in conf and \ conf['architecture']['name'] == name: targets[i]['architecture']['version'] = version if _type is ComponentType.PLAT or _type is None: if 'platform' in conf and \ conf['platform']['name'] == name: targets[i]['platform']['version'] = version if _type is ComponentType.LIB or _type is None: for lib, conf in libraries.items(): if lib == name: libraries[lib]['version'] = version core = Unikraft(**unikraft) return Config( specification=main_file.version, name=name, arguments=arguments, before=before, after=after, unikraft=core, targets=TargetManager(targets, core), libraries=LibraryManager(libraries), volumes=VolumeManager(volumes), networks=NetworkManager(networks), )