示例#1
0
 def validate(self, location: Location, *args: typing.Any,
              **kwargs: typing.Any) -> None:
     """Validate the arguments."""
     self._validate_no_args(location, *args)
     self._validate_kwargs(
         location,
         (
             "outside_match",
             "cluster_match",
             "cluster_name",
             "cluster_id",
             "node_id",
             "gateway",
             "dns",
             "ntp",
         ),
         **kwargs,
     )
     self._require_kwargs(location,
                          ("cluster_name", "cluster_id", "node_id"),
                          **kwargs)
     cluster_id = int(kwargs.get("cluster_id", -1))
     if cluster_id < 1 or cluster_id > 63:
         raise ParseError("cluster_id must be between 1 and 63",
                          location=location)
     node_id = int(kwargs.get("node_id", -1))
     if node_id < 1 or node_id > 63:
         raise ParseError("node_id must be between 1 and 63",
                          location=location)
示例#2
0
    def validate(self, location: Location, *args: typing.Any,
                 **kwargs: typing.Any) -> None:
        """Validate the arguments."""
        self._validate_args_exact(location, 1, '"{}" needs a username.', *args)
        if len(kwargs) == 0:
            raise ParseError("useradd needs keyword arguments",
                             location=location)

        lock = kwargs.get("lock", None)
        if lock not in (True, None, False):
            raise ParseError('"lock" must be either True, False or None.',
                             location=location)
示例#3
0
    def _validate_key_directory(self, location: Location, key_directory: str) -> None:
        if not os.path.isdir(key_directory):
            raise ParseError(
                f'"{self.name}": {key_directory} must be a directory (work directory is {os.getcwd()}).'
            )

        keyfiles = glob.glob(_key_files(key_directory))
        if not keyfiles:
            raise ParseError(
                f'"{self.name}": No ssh_host_*_key files found in {key_directory}.',
                location=location,
            )
示例#4
0
    def _validate_key_directory(self, location: Location,
                                key_directory: str) -> None:
        if not os.path.isdir(key_directory):
            raise ParseError(
                '"{}": {} must be a directory (work directory is {}).'.format(
                    self.name, key_directory, os.getcwd()))

        keyfiles = glob.glob(_key_files(key_directory))
        if not keyfiles:
            raise ParseError(
                '"{}": No ssh_host_*_key files found in {}.'.format(
                    self.name, key_directory),
                location=location)
示例#5
0
    def validate(self, location: Location, *args: typing.Any,
                 **kwargs: typing.Any) -> None:
        """Validate the arguments."""
        if not self._binary(Binaries.SWUPD):
            raise ParseError("No swupd_init binary was found.")

        self._validate_no_arguments(location, *args, **kwargs)
示例#6
0
    def __call__(
        self,
        location: Location,
        system_context: SystemContext,
        *args: typing.Any,
        **kwargs: typing.Any,
    ) -> None:
        """Execute command."""
        charmap = kwargs.get("charmap", "UTF-8")
        locales_dir = system_context.file_name("/usr/share/locale")
        locales = []
        for a in args:
            if not os.path.isdir(os.path.join(
                    locales_dir, a)) and not os.path.isdir(
                        os.path.join(locales_dir, a[0:2])):
                raise ParseError(
                    f'Locale "{a}" not found in /usr/share/locale.',
                    location=location,
                )
            locales.append(f"{a}.{charmap} {charmap}\n")

        self._execute(
            location,
            system_context,
            "append",
            "/etc/locale.gen",
            "".join(locales),
            force=True,
        )
        self._setup_hooks(location, system_context, locales)
示例#7
0
    def validate(self, location: Location, *args: typing.Any,
                 **kwargs: typing.Any) -> None:
        """Validate arguments."""
        self._validate_args_exact(location, 1,
                                  '{} needs a repository to export into.',
                                  *args)
        self._validate_kwargs(
            location,
            ('efi_key', 'efi_cert', 'efi_size', 'swap_size',
             'extra_partitions', 'image_format', 'repository_compression',
             'repository_compression_level', 'skip_validation', 'usr_only'),
            **kwargs)

        if 'key' in kwargs:
            if 'cert' not in kwargs:
                raise ParseError(
                    '"{}": cert keyword is required when '
                    'key keyword is given.',
                    location=location)
        else:
            if 'cert' in kwargs:
                raise ParseError(
                    '"{}": key keyword is required when '
                    'cert keyword is given.',
                    location=location)

        image_format = kwargs.get('image_format', 'raw')
        if image_format not in (
                'raw',
                'qcow2',
        ):
            raise ParseError(
                '"{}" is not a supported image format.'.format(image_format),
                location=location)

        repo_compression = kwargs.get('repository_compression', 'zstd')
        if repo_compression not in (
                'none',
                'lz4',
                'zstd',
                'zlib',
                'lzma',
        ):
            raise ParseError(
                '"{}" is not a supported '
                'repository compression format.'.format(repo_compression),
                location=location)
示例#8
0
 def validate(self, location: Location, *args: typing.Any,
              **kwargs: typing.Any) -> None:
     """Validate the arguments."""
     if not args:
         raise ParseError('"{}" does need at least one application.'.format(
             self.name),
                          location=location)
     self._validate_arguments_at_least(
         location, 1, '"{}" needs at least one application.', *args)
示例#9
0
    def validate(self, location: Location, *args: typing.Any,
                 **kwargs: typing.Any) -> None:
        """Validate the arguments."""
        if not self._binary(Binaries.SWUPD):
            raise ParseError("No swupd binary was found.")

        self._validate_arguments_at_least(
            location, 1,
            '"{}" needs at least one package or group to install.', *args)
示例#10
0
    def validate(self, location: Location, *args: typing.Any,
                 **kwargs: typing.Any) -> None:
        """Validate the arguments."""
        self._validate_arguments_exact(
            location, 2, "{} needs a name and a var directory to move.", *args,
            **kwargs)

        if not args[0]:
            raise ParseError("The name must not be empty!")
示例#11
0
 def validate(self, location: Location, *args: typing.Any,
              **kwargs: typing.Any) -> None:
     """Validate the arguments."""
     self._validate_no_args(location, *args)
     self._validate_kwargs(
         location, ('outside_match', 'cluster_match', 'cluster_name',
                    'cluster_id', 'node_id', 'gateway', 'dns', 'ntp'),
         **kwargs)
     self._require_kwargs(location,
                          ('cluster_name', 'cluster_id', 'node_id'),
                          **kwargs)
     cluster_id = int(kwargs.get('cluster_id', -1))
     if cluster_id < 1 or cluster_id > 63:
         raise ParseError('cluster_id must be between 1 and 63',
                          location=location)
     node_id = int(kwargs.get('node_id', -1))
     if node_id < 1 or node_id > 63:
         raise ParseError('node_id must be between 1 and 63',
                          location=location)
示例#12
0
    def validate(self, location: Location,
                 *args: typing.Any, **kwargs: typing.Any) -> None:
        """Validate the arguments."""
        self._validate_arguments_exact(location, 1, '"{}" needs a device.',
                                       *args, **kwargs)

        device = args[0]
        if not device.startswith('/dev/') and not device.startswith('/sys/'):
            raise ParseError('"{}": Root device "{}" does not start with /dev/ or /sys/.'
                             .format(self.name, device),
                             location=location)
示例#13
0
    def validate(self, location: Location,
                 *args: typing.Any, **kwargs: typing.Any) -> None:
        """Validate the arguments."""
        self._validate_no_args(location, *args)
        self._validate_kwargs(location,
                              ('suite', 'mirror', 'variant', 'include', 'exclude',),
                              **kwargs)
        self._require_kwargs(location, ('suite', 'mirror',), **kwargs)

        if not kwargs.get('suite', ''):
            raise ParseError('"{}" needs a suite.'
                             .format(self.name), location=location)
示例#14
0
    def validate(
        self, location: Location, *args: typing.Any, **kwargs: typing.Any
    ) -> None:
        """Validate the arguments."""
        self._validate_no_args(location, *args)
        self._validate_kwargs(
            location, ("suite", "mirror", "variant", "include", "exclude",), **kwargs
        )
        self._require_kwargs(location, ("suite", "mirror",), **kwargs)

        if not kwargs.get("suite", ""):
            raise ParseError('"{}" needs a suite.'.format(self.name), location=location)
示例#15
0
    def validate(self, location: Location, *args: typing.Any,
                 **kwargs: typing.Any) -> None:
        """Validate the arguments."""
        if not self._binary(Binaries.PACMAN) or not self._binary(
                Binaries.SYSTEMD_NSPAWN):
            raise ParseError("No pacman binary was found.")

        self._validate_args_at_least(
            location, 1, '"{}" needs at least one package '
            "or group to install.", *args)
        self._validate_kwargs(location, ("config", ), **kwargs)
        self._require_kwargs(location, ("config", ), **kwargs)
示例#16
0
    def validate(self, location: Location, *args: typing.Any,
                 **kwargs: typing.Any) -> None:
        """Validate the arguments."""
        self._validate_args_exact(location, 1, '"{}" needs a port to open.',
                                  *args)
        self._validate_kwargs(location, ("protocol", "comment"), **kwargs)

        protocol = kwargs.get("protocol", "tcp")
        if protocol != "tcp" and protocol != "udp":
            raise ParseError(
                f'"{self.name}" only supports protocols "tcp" and "udp".',
                location=location,
            )
示例#17
0
    def validate(self, location: Location, *args: typing.Any,
                 **kwargs: typing.Any) -> None:
        """Validate the arguments."""
        self._validate_arguments_exact(location, 1,
                                       '"{}" needs a system name.', *args,
                                       **kwargs)
        base = args[0]

        system_pattern = re.compile('^[A-Za-z][A-Za-z0-9_-]*$')
        if not system_pattern.match(base):
            raise ParseError('"{}" got invalid base system name "{}".'.format(
                self.name, base),
                             location=location)
示例#18
0
    def validate(self, location: Location, *args: typing.Any,
                 **kwargs: typing.Any) -> None:
        """Validate the arguments."""
        self._validate_args_exact(location, 1, '"{}" needs a port to open.',
                                  *args)
        self._validate_kwargs(location, ('protocol', 'comment'), **kwargs)

        protocol = kwargs.get('protocol', 'tcp')
        if protocol != 'tcp' and protocol != 'udp':
            raise ParseError(
                '"{}" only supports protocols "tcp" and "udp".'.format(
                    self.name),
                location=location)
示例#19
0
 def validate(
     self, location: Location, *args: typing.Any, **kwargs: typing.Any
 ) -> None:
     """Validate the arguments."""
     self._validate_args_exact(
         location, 1, '"{}" needs a name for the partition file.', *args
     )
     self._validate_kwargs(
         location,
         (
             "type",
             "device",
             "label",
             "uuid",
             "priority",
             "weight",
             "paddingWeight",
             "minSize",
             "maxSize",
             "minPadding",
             "maxPadding",
         ),
         **kwargs,
     )
     self._require_kwargs(location, ("type",), **kwargs)
     type = kwargs.get("type")
     if not type in (
         "esp",
         "xbootldr",
         "swap",
         "home",
         "srv",
         "var",
         "tmp",
         "linux-generic",
         "root",
         "root-verity",
         "root-secondary",
         "root-secondary-verity",
         "root-x86",
         "root-x86-verity",
         "root-x86-64",
         "root-x86-64-verity",
         "root-arm",
         "root-arm-verity",
         "root-arm64",
         "root-arm64-verity",
         "root-ia64",
         "root-ia64-verity",
     ):
         raise ParseError(f"Invalid type found: {type}.")
示例#20
0
    def validate(self, location: Location, *args: typing.Any,
                 **kwargs: typing.Any) -> None:
        """Validate the arguments."""
        self._validate_args_exact(location, 1, '"{}" needs a username.', *args)
        if len(kwargs) == 0:
            raise ParseError('usermod needs keyword arguments',
                             location=location)

        lock = kwargs.get('lock', None)
        if lock not in (True, None, False):
            raise ParseError('"lock" must be either True, False or None.',
                             location=location)

        append = kwargs.get('append', False)
        if append not in (True, False):
            raise ParseError(
                '"append" must have either True or False as '
                'value.',
                location=location)

        if append and kwargs.get('groups', '') == '':
            raise ParseError('"append" needs "groups" to be set, too.',
                             location=location)
示例#21
0
 def validate(self, location: Location, *args: typing.Any,
              **kwargs: typing.Any) -> None:
     """Validate the arguments."""
     self._validate_args_exact(location, 1, '"{}" needs a groupname.',
                               *args)
     self._validate_kwargs(location, (
         "gid",
         "rename",
         "password",
         "root_directory",
     ), **kwargs)
     if len(kwargs) == 0:
         raise ParseError("groupmod needs something to change.",
                          location=location)
示例#22
0
 def validate(self, location: Location, *args: typing.Any,
              **kwargs: typing.Any) -> None:
     """Validate the arguments."""
     self._validate_args_at_least(
         location, 2, '"{}" needs at least one '
         'source and a destination.', *args)
     self._validate_kwargs(
         location,
         ('from_outside', 'to_outside', 'ignore_missing_sources', 'force'),
         **kwargs)
     if kwargs.get('from_outside', False) \
        and kwargs.get('to_outside', False):
         raise ParseError(
             'You can not move a file from_outside to_outside.',
             location=location)
示例#23
0
    def validate(self, location: Location, *args: typing.Any,
                 **kwargs: typing.Any) -> None:
        """Validate the arguments."""
        self._validate_arguments_exact(location, 1,
                                       '"{}" needs the machine id.', *args,
                                       **kwargs)

        machine_id = args[0]
        assert machine_id

        id_pattern = re.compile("^[A-Fa-f0-9]{32}$")
        if not id_pattern.match(machine_id):
            raise ParseError(
                '"{}" is not a valid machine-id.'.format(machine_id),
                location=location)
示例#24
0
 def validate(self, location: Location, *args: typing.Any,
              **kwargs: typing.Any) -> None:
     """Validate the arguments."""
     self._validate_args_at_least(
         location, 2, '"{}" needs at least one '
         "source and a destination.", *args)
     self._validate_kwargs(
         location,
         ("from_outside", "to_outside", "ignore_missing_sources", "force"),
         **kwargs)
     if kwargs.get("from_outside", False) and kwargs.get(
             "to_outside", False):
         raise ParseError(
             "You can not move a file from_outside to_outside.",
             location=location)
示例#25
0
    def validate(self, location: Location, *args: typing.Any,
                 **kwargs: typing.Any) -> None:
        """Validate the arguments."""
        if not self._binary(Binaries.PACMAN) or not self._binary(
                Binaries.CHROOT_HELPER):
            raise ParseError("No pacman binary was found.")

        self._validate_args_at_least(
            location, 1, '"{}"" needs at least '
            "one package or group to install.", *args)
        self._validate_kwargs(location, (
            "remove",
            "overwrite",
            "assume_installed",
        ), **kwargs)
示例#26
0
    def validate(self, location: Location, *args: typing.Any,
                 **kwargs: typing.Any) -> None:
        """Validate the arguments."""
        self._validate_args_at_least(
            location, 2, '"{}" needs one or more sources and a '
            'destination', *args)
        self._validate_kwargs(location,
                              ('from_outside', 'to_outside', 'ignore_missing',
                               'recursive', 'force'), **kwargs)

        if kwargs.get('from_outside', False) \
           and kwargs.get('to_outside', False):
            raise ParseError(
                'You can not "{}" a file from_outside to_outside.'.format(
                    self.name),
                location=location)
示例#27
0
    def __call__(self, location: Location, system_context: SystemContext,
                 *args: typing.Any, **kwargs: typing.Any) -> None:
        """Execute command."""
        charmap = kwargs.get('charmap', 'UTF-8')
        locales_dir = system_context.file_name('/usr/share/locale')
        locales = []
        for a in args:
            if not os.path.isdir(os.path.join(locales_dir, a))\
               and not os.path.isdir(os.path.join(locales_dir, a[0:2])):
                raise ParseError('Locale "{}" not found in /usr/share/locale.'
                                 .format(a), location=location)
            locales.append('{}.{} {}\n'.format(a, charmap, charmap))

        self._execute(location, system_context,
                      'append', '/etc/locale.gen', ''.join(locales),
                      force=True)
        self._setup_hooks(location, system_context, locales)
示例#28
0
文件: copy.py 项目: phunni/cleanroom
    def validate(
        self, location: Location, *args: typing.Any, **kwargs: typing.Any
    ) -> None:
        """Validate the arguments."""
        self._validate_args_at_least(
            location, 2, '"{}" needs one or more sources and a ' "destination", *args
        )
        self._validate_kwargs(
            location,
            ("from_outside", "to_outside", "ignore_missing", "recursive", "force"),
            **kwargs
        )

        if kwargs.get("from_outside", False) and kwargs.get("to_outside", False):
            raise ParseError(
                'You can not "{}" a file from_outside to_outside.'.format(self.name),
                location=location,
            )
示例#29
0
    def validate(self, location: Location, *args: typing.Any,
                 **kwargs: typing.Any) -> None:
        """Validate arguments."""
        self._validate_args_exact(location, 1,
                                  "{} needs a repository to export into.",
                                  *args)
        self._validate_kwargs(
            location,
            (
                "efi_key",
                "efi_cert",
                "efi_emulator",
                "repository_compression",
                "repository_compression_level",
                "skip_validation",
                "usr_only",
                "debug_initrd",
            ),
            **kwargs,
        )

        if "key" in kwargs:
            if "cert" not in kwargs:
                raise ParseError(
                    '"{}": cert keyword is required when '
                    "key keyword is given.",
                    location=location,
                )
        else:
            if "cert" in kwargs:
                raise ParseError(
                    '"{}": key keyword is required when '
                    "cert keyword is given.",
                    location=location,
                )

        repo_compression = kwargs.get("repository_compression", "zstd")
        if repo_compression not in (
                "none",
                "lz4",
                "zstd",
                "zlib",
                "lzma",
        ):
            raise ParseError(
                f'"{repo_compression}" is not a supported repository compression format.',
                location=location,
            )

        efi_emulator = kwargs.get("efi_emulator", "")
        if efi_emulator:
            if not os.path.isdir(os.path.join(efi_emulator, "EFI")):
                raise ParseError(
                    f'"{efi_emulator}" is not a valid efi emulator. The folder needs to contain a "EFI" folder.',
                    location=location,
                )
            if not os.path.isdir(os.path.join(efi_emulator, "Bootloaders")):
                raise ParseError(
                    f'"{efi_emulator}" is not a valid efi emulator. The folder needs to contain a "Bootloaders" folder.',
                    location=location,
                )
            if not os.path.isdir(os.path.join(efi_emulator, "BootSectors")):
                raise ParseError(
                    f'"{efi_emulator}" is not a valid efi emulator. The folder needs to contain a "BootSectors" folder.',
                    location=location,
                )
示例#30
0
    def validate(
        self, location: Location, *args: typing.Any, **kwargs: typing.Any
    ) -> None:
        """Validate arguments."""
        self._validate_args_exact(
            location, 1, "{} needs a repository to export into.", *args
        )
        self._validate_kwargs(
            location,
            (
                "efi_key",
                "efi_cert",
                "efi_size",
                "efi_emulator",
                "swap_size",
                "extra_partitions",
                "image_format",
                "repository_compression",
                "repository_compression_level",
                "skip_validation",
                "usr_only",
            ),
            **kwargs
        )

        if "key" in kwargs:
            if "cert" not in kwargs:
                raise ParseError(
                    '"{}": cert keyword is required when ' "key keyword is given.",
                    location=location,
                )
        else:
            if "cert" in kwargs:
                raise ParseError(
                    '"{}": key keyword is required when ' "cert keyword is given.",
                    location=location,
                )

        image_format = kwargs.get("image_format", "raw")
        if image_format not in ("raw", "qcow2",):
            raise ParseError(
                '"{}" is not a supported image format.'.format(image_format),
                location=location,
            )

        repo_compression = kwargs.get("repository_compression", "zstd")
        if repo_compression not in ("none", "lz4", "zstd", "zlib", "lzma",):
            raise ParseError(
                '"{}" is not a supported '
                "repository compression format.".format(repo_compression),
                location=location,
            )

        efi_emulator = kwargs.get("efi_emulator", "")
        if efi_emulator:
            if not os.path.isdir(os.path.join(efi_emulator, "EFI")):
                raise ParseError(
                    '"{}" is not a valide efi emulator. '
                    'The folder needs to contain a "EFI" folder.'.format(efi_emulator),
                    location=location,
                )
            if not os.path.isdir(os.path.join(efi_emulator, "Bootloaders")):
                raise ParseError(
                    '"{}" is not a valide efi emulator. '
                    'The folder needs to contain a "Bootloaders" folder.'.format(
                        efi_emulator
                    ),
                    location=location,
                )
            if not os.path.isdir(os.path.join(efi_emulator, "BootSectors")):
                raise ParseError(
                    '"{}" is not a valide efi emulator. '
                    'The folder needs to contain a "BootSectors" folder.'.format(
                        efi_emulator
                    ),
                    location=location,
                )