Example #1
0
 def new(name: str, root_dir: str, custom_args: Dict = None):  # noqa: E252
     name_map = {'docker': 'Docker', 'oci': 'OCI', 'appx': 'Appx'}
     try:
         container_setup = importlib.import_module(
             'kiwi.container.setup.{}'.format(name))
         module_name = 'ContainerSetup{}'.format(name_map[name])
         return container_setup.__dict__[module_name](root_dir, custom_args)
     except Exception:
         raise KiwiContainerSetupError(
             'Support for {0} container not implemented'.format(name))
Example #2
0
 def __init__(self, root_dir, custom_args=None):
     if not os.path.exists(root_dir):
         raise KiwiContainerSetupError(
             'Container root directory %s does not exist' % root_dir
         )
     self.root_dir = root_dir
     self.custom_args = {
         'container_name': 'systemContainer'
     }
     self.post_init(custom_args)
Example #3
0
 def __init__(self, root_dir, custom_args=None):
     if not os.path.exists(root_dir):
         raise KiwiContainerSetupError(
             'Container root directory %s does not exist' % root_dir
         )
     self.root_dir = root_dir
     self.custom_args = custom_args or {}
     if 'container_name' not in self.custom_args:
         self.custom_args['container_name'] = 'system-container'
     self.post_init(custom_args)
Example #4
0
    def deactivate_systemd_service(self, name):
        """
        Container system services setup

        Init systems among others also controls services which
        starts at boot time. A container does not really boot.
        Thus some services needs to be deactivated

        :param string name: systemd service name
        """
        service_file = self.root_dir + '/usr/lib/systemd/system/' + name
        if os.path.exists(service_file):
            try:
                Command.run(['ln', '-s', '-f', '/dev/null', service_file])
            except Exception as e:
                raise KiwiContainerSetupError(
                    'Failed to deactivate service %s: %s' % (name, format(e)))
Example #5
0
    def setup_static_device_nodes(self):
        """
        Container device node setup

        Without subsystems like udev running in a container it is
        required to provide a set of device nodes to let the
        system in the container function correctly. This is
        done by syncing the host system nodes to the container.
        That this will also create device nodes which are not
        necessarily present in the container later is a know
        limitation of this method and considered harmless
        """
        try:
            data = DataSync('/dev/', self.root_dir + '/dev/')
            data.sync_data(options=['-a', '-x', '--devices', '--specials'])
        except Exception as e:
            raise KiwiContainerSetupError(
                'Failed to create static container nodes %s' % format(e))