X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=rwlaunchpad%2Fplugins%2Frwlaunchpadtasklet%2Frift%2Fpackage%2Fconfig.py;fp=rwlaunchpad%2Fplugins%2Frwlaunchpadtasklet%2Frift%2Fpackage%2Fconfig.py;h=0000000000000000000000000000000000000000;hb=4870d0ee29789b859931e4e2c73e13dcb29537d5;hp=9a061160a5ad35213b11b67295f2a8e113f8dfbd;hpb=6f1a3fe149e4a6b9803382cb299c902f4cf58ec9;p=osm%2FSO.git diff --git a/rwlaunchpad/plugins/rwlaunchpadtasklet/rift/package/config.py b/rwlaunchpad/plugins/rwlaunchpadtasklet/rift/package/config.py deleted file mode 100644 index 9a061160..00000000 --- a/rwlaunchpad/plugins/rwlaunchpadtasklet/rift/package/config.py +++ /dev/null @@ -1,93 +0,0 @@ - -# -# Copyright 2016 RIFT.IO Inc -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -import re -import os.path - -from . import package - - -class ConfigExtractionError(Exception): - pass - - -class PackageConfigExtractor(object): - """ This class is reponsible for extracting config data to the correct directory - - In order to remain compatible with the existing ConfigManager, we extract the config - to a known location (RIFT-13282) - """ - DEFAULT_INSTALL_DIR = os.path.join( - os.environ["RIFT_ARTIFACTS"], - "launchpad" - ) - - CONFIG_REGEX = "{prefix}(ns_config|vnf_config)/(?P[^/]+.yaml)$" - - def __init__(self, log, install_dir=DEFAULT_INSTALL_DIR): - self._log = log - self._install_dir = install_dir - - def _get_rel_dest_path(self, descriptor_id, config_name): - dest_rel_path = "libs/{}/config/{}".format(descriptor_id, config_name) - dest_path = os.path.join(self._install_dir, dest_rel_path) - return dest_path - - @classmethod - def package_config_files(cls, package): - config_map = {} - regex = cls.CONFIG_REGEX.format(prefix=package.prefix) - - for file_name in package.files: - match = re.match( - cls.CONFIG_REGEX.format(prefix=package.prefix), file_name, - ) - if match is None: - continue - - config_name = match.group("config_name") - - config_map[config_name] = file_name - - return config_map - - def get_extracted_config_path(self, package_id, config_name): - return os.path.join( - self._get_rel_dest_path(package_id, os.path.basename(config_name)), - ) - - def extract_configs(self, pkg): - """ Extract any configuration files from the DescriptorPackage - - Arguments: - pkg - A DescriptorPackage - - Raises: - ConfigExtractionError - The configuration could not be extracted - """ - descriptor_id = pkg.descriptor_id - - config_files = PackageConfigExtractor.package_config_files(pkg).items() - for config_name, config_file in config_files: - dest_rel_path = self._get_rel_dest_path(descriptor_id, config_name) - dest_path = os.path.join(self._install_dir, dest_rel_path) - - self._log.debug("Extracting %s config to %s", config_name, dest_path) - try: - pkg.extract_file(config_file, dest_path) - except package.ExtractError as e: - raise ConfigExtractionError("Failed to extract config %s" % config_name) from e