kiwi.container
1# Copyright (c) 2015 SUSE Linux GmbH. All rights reserved. 2# 3# This file is part of kiwi. 4# 5# kiwi is free software: you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation, either version 3 of the License, or 8# (at your option) any later version. 9# 10# kiwi is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with kiwi. If not, see <http://www.gnu.org/licenses/> 17# 18import importlib 19from abc import ( 20 ABCMeta, 21 abstractmethod 22) 23from typing import Dict 24 25from kiwi.container.base import ContainerImageBase 26from kiwi.exceptions import ( 27 KiwiContainerImageSetupError 28) 29 30 31class ContainerImage(metaclass=ABCMeta): 32 """ 33 **Container Image factory** 34 35 :param string name: container system name 36 :param string root_dir: root directory path name 37 :param dict custom_args: custom arguments 38 """ 39 @abstractmethod 40 def __init__(self) -> None: 41 return None # pragma: no cover 42 43 @staticmethod 44 def new(name: str, root_dir: str, custom_args: Dict=None) -> ContainerImageBase: # noqa: E252 45 name_map = { 46 'docker': 'OCI', 47 'oci': 'OCI', 48 'appx': 'Appx', 49 'wsl': 'Wsl' 50 } 51 args_map = { 52 'docker': [root_dir, 'docker-archive', custom_args], 53 'oci': [root_dir, 'oci-archive', custom_args], 54 'appx': [root_dir, custom_args], 55 'wsl': [root_dir, custom_args] 56 } 57 try: 58 container_image = importlib.import_module( 59 'kiwi.container.{}'.format('oci' if name == 'docker' else name) 60 ) 61 module_name = 'ContainerImage{}'.format(name_map[name]) 62 return container_image.__dict__[module_name](*args_map[name]) 63 except Exception: 64 raise KiwiContainerImageSetupError( 65 'Support for {0} container not implemented'.format(name) 66 )
class
ContainerImage:
32class ContainerImage(metaclass=ABCMeta): 33 """ 34 **Container Image factory** 35 36 :param string name: container system name 37 :param string root_dir: root directory path name 38 :param dict custom_args: custom arguments 39 """ 40 @abstractmethod 41 def __init__(self) -> None: 42 return None # pragma: no cover 43 44 @staticmethod 45 def new(name: str, root_dir: str, custom_args: Dict=None) -> ContainerImageBase: # noqa: E252 46 name_map = { 47 'docker': 'OCI', 48 'oci': 'OCI', 49 'appx': 'Appx', 50 'wsl': 'Wsl' 51 } 52 args_map = { 53 'docker': [root_dir, 'docker-archive', custom_args], 54 'oci': [root_dir, 'oci-archive', custom_args], 55 'appx': [root_dir, custom_args], 56 'wsl': [root_dir, custom_args] 57 } 58 try: 59 container_image = importlib.import_module( 60 'kiwi.container.{}'.format('oci' if name == 'docker' else name) 61 ) 62 module_name = 'ContainerImage{}'.format(name_map[name]) 63 return container_image.__dict__[module_name](*args_map[name]) 64 except Exception: 65 raise KiwiContainerImageSetupError( 66 'Support for {0} container not implemented'.format(name) 67 )
Container Image factory
Parameters
- string name: container system name
- string root_dir: root directory path name
- dict custom_args: custom arguments
@staticmethod
def
new( name: str, root_dir: str, custom_args: Dict = None) -> kiwi.container.base.ContainerImageBase:
44 @staticmethod 45 def new(name: str, root_dir: str, custom_args: Dict=None) -> ContainerImageBase: # noqa: E252 46 name_map = { 47 'docker': 'OCI', 48 'oci': 'OCI', 49 'appx': 'Appx', 50 'wsl': 'Wsl' 51 } 52 args_map = { 53 'docker': [root_dir, 'docker-archive', custom_args], 54 'oci': [root_dir, 'oci-archive', custom_args], 55 'appx': [root_dir, custom_args], 56 'wsl': [root_dir, custom_args] 57 } 58 try: 59 container_image = importlib.import_module( 60 'kiwi.container.{}'.format('oci' if name == 'docker' else name) 61 ) 62 module_name = 'ContainerImage{}'.format(name_map[name]) 63 return container_image.__dict__[module_name](*args_map[name]) 64 except Exception: 65 raise KiwiContainerImageSetupError( 66 'Support for {0} container not implemented'.format(name) 67 )