コード例 #1
0
ファイル: item.py プロジェクト: BATYD-Turksat/cobbler
 def set_mgmt_classes(self, mgmt_classes):
     """
     Assigns a list of configuration management classes that can be assigned
     to any object, such as those used by Puppet's external_nodes feature.
     """
     mgmt_classes_split = utils.input_string_or_list(mgmt_classes)
     self.mgmt_classes = utils.input_string_or_list(mgmt_classes_split)
コード例 #2
0
 def set_mgmt_classes(self, mgmt_classes):
     """
     Assigns a list of configuration management classes that can be assigned
     to any object, such as those used by Puppet's external_nodes feature.
     """
     mgmt_classes_split = utils.input_string_or_list(mgmt_classes)
     self.mgmt_classes = utils.input_string_or_list(mgmt_classes_split)
コード例 #3
0
ファイル: item.py プロジェクト: Acidburn0zzz/cobbler
 def set_owners(self, data):
     """
     The owners field is a comment unless using an authz module that pays attention to it,
     like authz_ownership, which ships with Cobbler but is off by default.
     """
     self.owners = utils.input_string_or_list(data)
     return True
コード例 #4
0
ファイル: system.py プロジェクト: bruncsak/cobbler
    def set_boot_loaders(self, boot_loaders: str):
        """
        Setter of the boot loaders.

        :param boot_loaders: The boot loaders for the system.
        """
        if boot_loaders == "<<inherit>>":
            self.boot_loaders = "<<inherit>>"
            return

        if boot_loaders:
            boot_loaders_split = utils.input_string_or_list(boot_loaders)

            if self.profile and self.profile != "":
                profile = self.collection_mgr.profiles().find(
                    name=self.profile)
                parent_boot_loaders = profile.get_boot_loaders()
            elif self.image and self.image != "":
                image = self.collection_mgr.images().find(name=self.image)
                parent_boot_loaders = image.get_boot_loaders()
            if not set(boot_loaders_split).issubset(parent_boot_loaders):
                raise CX(
                    "Error with system %s - not all boot_loaders %s are supported %s"
                    % (self.name, boot_loaders_split, parent_boot_loaders))
            self.boot_loaders = boot_loaders_split
        else:
            self.boot_loaders = []
コード例 #5
0
    def boot_loaders(self, boot_loaders: list):
        """
        Setter of the boot loaders.

        :param boot_loaders: The boot loaders for the profile.
        :raises ValueError: In case the supplied boot loaders were not a subset of the valid ones.
        """
        if boot_loaders == enums.VALUE_INHERITED:
            self._boot_loaders = enums.VALUE_INHERITED
            return

        if boot_loaders:
            boot_loaders_split = utils.input_string_or_list(boot_loaders)
            distro = self.get_conceptual_parent()

            if distro:
                distro_boot_loaders = distro.boot_loaders
            else:
                distro_boot_loaders = utils.get_supported_system_boot_loaders()
            if not set(boot_loaders_split).issubset(distro_boot_loaders):
                raise ValueError("Error with profile %s - not all boot_loaders %s are supported %s" %
                                 (self.name, boot_loaders_split, distro_boot_loaders))
            self._boot_loaders = boot_loaders_split
        else:
            self._boot_loaders = []
コード例 #6
0
    def mgmt_classes(self, mgmt_classes: list):
        """
        Setter for the ``mgmt_classes`` property.

        :param mgmt_classes: The new options for the management classes of an item.
        """
        self._mgmt_classes = utils.input_string_or_list(mgmt_classes)
コード例 #7
0
    def owners(self, owners: list):
        """
        Setter for the ``owners`` property.

        :param owners: The new list of owners. Will not be validated for existence.
        """
        self._owners = utils.input_string_or_list(owners)
コード例 #8
0
ファイル: system.py プロジェクト: nodeg/cobbler
    def boot_loaders(self, boot_loaders: str):
        """
        Setter of the boot loaders.

        :param boot_loaders: The boot loaders for the system.
        :raises CX
        """
        if boot_loaders == enums.VALUE_INHERITED:
            self._boot_loaders = enums.VALUE_INHERITED
            return

        if boot_loaders:
            boot_loaders_split = utils.input_string_or_list(boot_loaders)

            if self.profile:
                profile = self.api.profiles().find(name=self.profile)
                parent_boot_loaders = profile.boot_loaders
            elif self.image:
                image = self.api.images().find(name=self.image)
                parent_boot_loaders = image.boot_loaders
            else:
                parent_boot_loaders = []
            if not set(boot_loaders_split).issubset(parent_boot_loaders):
                raise CX(
                    "Error with system \"%s\" - not all boot_loaders are supported (given: \"%s\"; supported:"
                    "\"%s\")" % (self.name, str(boot_loaders_split),
                                 str(parent_boot_loaders)))
            self._boot_loaders = boot_loaders_split
        else:
            self._boot_loaders = []
コード例 #9
0
ファイル: system.py プロジェクト: nodeg/cobbler
    def ipv6_static_routes(self, routes: list):
        """
        TODO

        :param routes:
        """
        self._ipv6_static_routes = utils.input_string_or_list(routes)
コード例 #10
0
ファイル: mgmtclass.py プロジェクト: wssl21sjxxscpbqy/cobbler
    def set_files(self, files):
        """
        Setter for the files of the object.

        :param files: A string or list which contains the new files.
        """
        self.files = utils.input_string_or_list(files)
コード例 #11
0
    def apt_dists(self, value: Union[str, list]):
        """
        Setter for the apt dists.

        :param value: The new value for ``apt_dists``.
        """
        self._apt_dists = utils.input_string_or_list(value)
コード例 #12
0
ファイル: item.py プロジェクト: whitekid/cobbler
 def set_owners(self, data):
     """
     The owners field is a comment unless using an authz module that pays attention to it,
     like authz_ownership, which ships with Cobbler but is off by default.
     """
     self.owners = utils.input_string_or_list(data)
     return True
コード例 #13
0
ファイル: system.py プロジェクト: nodeg/cobbler
    def cnames(self, cnames: list):
        """
        TODO

        :param cnames:
        """
        self._cnames = utils.input_string_or_list(cnames)
コード例 #14
0
ファイル: settings.py プロジェクト: vzhestkov/cobbler
    def __setattr__(self, name, value):
        """
        This sets the value of the settings named in the args.

        :param name: The setting to set its value.
        :param value: The value of the setting "name". Must be the correct the type.
        :return: 0 if the action was completed successfully. No return if there is an error.
        :raises AttributeError: Raised if the setting with "name" has the wrong type.
        """
        if name in DEFAULTS:
            try:
                if DEFAULTS[name][1] == "str":
                    value = str(value)
                elif DEFAULTS[name][1] == "int":
                    value = int(value)
                elif DEFAULTS[name][1] == "bool":
                    value = utils.input_boolean(value)
                elif DEFAULTS[name][1] == "float":
                    value = float(value)
                elif DEFAULTS[name][1] == "list":
                    value = utils.input_string_or_list(value)
                elif DEFAULTS[name][1] == "dict":
                    value = utils.input_string_or_dict(value)[1]
            except Exception as error:
                raise AttributeError from error

            self.__dict__[name] = value
            update_settings_file(self.to_dict())

            return 0
        else:
            pass
コード例 #15
0
 def set_rpm_list(self, rpms):
     """
     Rather than mirroring the entire contents of a repository (Fedora Extras, for instance,
     contains games, and we probably don't want those), make it possible to list the packages
     one wants out of those repos, so only those packages + deps can be mirrored.
     """
     self.rpm_list = utils.input_string_or_list(rpms)
コード例 #16
0
    def boot_loaders(self, boot_loaders: list):
        """
        Setter of the boot loaders.

        :param boot_loaders: The boot loaders for the image.
        :raises TypeError: In case this was of a not allowed type.
        :raises ValueError: In case the str which contained the list could not be successfully split.
        """
        # allow the magic inherit string to persist
        if boot_loaders == enums.VALUE_INHERITED:
            self._boot_loaders = enums.VALUE_INHERITED
            return

        if boot_loaders:
            boot_loaders_split = utils.input_string_or_list(boot_loaders)

            if not isinstance(boot_loaders_split, list):
                raise TypeError("boot_loaders needs to be of type list!")

            if not set(boot_loaders_split).issubset(
                    self.supported_boot_loaders):
                raise ValueError(
                    "Error with image %s - not all boot_loaders %s are supported %s"
                    % (self.name, boot_loaders_split,
                       self.supported_boot_loaders))
            self._boot_loaders = boot_loaders_split
        else:
            self._boot_loaders = []
コード例 #17
0
ファイル: mgmtclass.py プロジェクト: wssl21sjxxscpbqy/cobbler
    def set_packages(self, packages):
        """
        Setter for the packages of the managementclass.

        :param packages: A string or list which contains the new packages.
        """
        self.packages = utils.input_string_or_list(packages)
コード例 #18
0
 def set_rpm_list(self, rpms):
     """
     Rather than mirroring the entire contents of a repository (Fedora Extras, for instance,
     contains games, and we probably don't want those), make it possible to list the packages
     one wants out of those repos, so only those packages + deps can be mirrored.
     """
     self.rpm_list = utils.input_string_or_list(rpms)
コード例 #19
0
    def set_boot_loaders(self, boot_loaders):
        """
        Setter of the boot loaders.

        :param boot_loaders: The boot loaders for the profile.
        """
        if boot_loaders == "<<inherit>>":
            self.boot_loaders = "<<inherit>>"
            return

        if boot_loaders:
            boot_loaders_split = utils.input_string_or_list(boot_loaders)
            distro = self.get_conceptual_parent()

            if distro:
                distro_boot_loaders = distro.get_boot_loaders()
            else:
                distro_boot_loaders = utils.get_supported_system_boot_loaders()
            if not set(boot_loaders_split).issubset(distro_boot_loaders):
                raise CX(
                    "Error with profile %s - not all boot_loaders %s are supported %s"
                    % (self.name, boot_loaders_split, distro_boot_loaders))
            self.boot_loaders = boot_loaders_split
        else:
            self.boot_loaders = []
コード例 #20
0
    def rpm_list(self, rpms: Union[str, list]):
        """
        Setter for the ``rpm_list`` property.

        :param rpms: The rpm to mirror. This may be a string or list.
        """
        self._rpm_list = utils.input_string_or_list(rpms)
コード例 #21
0
    def apt_components(self, value: Union[str, list]):
        """
        Setter for the apt command property.

        :param value: The new value for ``apt_components``.
        """
        self._apt_components = utils.input_string_or_list(value)
コード例 #22
0
    def filter_systems_or_profiles(self, selected_items, list_type):
        """
        Return a list of valid profile or system objects selected from all profiles
        or systems by name, or everything if selected_items is empty
        """
        if list_type == 'profile':
            all_objs = [profile for profile in self.api.profiles()]
        elif list_type == 'system':
            all_objs = [system for system in self.api.systems()]
        else:
            utils.die(self.logger, "Invalid list_type argument: " + list_type)

        all_objs.sort(key=lambda profile: profile.name)

        # no profiles/systems selection is made, let's process everything
        if not selected_items:
            return all_objs

        which_objs = []
        selected_list = utils.input_string_or_list(selected_items)
        for obj in all_objs:
            if obj.name in selected_list:
                which_objs.append(obj)
                selected_list.remove(obj.name)

        for bad_name in selected_list:
            self.logger.warning("WARNING: %s is not a valid %s" %
                                (bad_name, list_type))

        if not which_objs:
            utils.die(self.logger,
                      "No valid systems or profiles were specified.")

        return which_objs
コード例 #23
0
    def __setattr__(self, name, value):
        if name in DEFAULTS:
            try:
                if DEFAULTS[name][1] == "str":
                    value = str(value)
                elif DEFAULTS[name][1] == "int":
                    value = int(value)
                elif DEFAULTS[name][1] == "bool":
                    if utils.input_boolean(value):
                        value = 1
                    else:
                        value = 0
                elif DEFAULTS[name][1] == "float":
                    value = float(value)
                elif DEFAULTS[name][1] == "list":
                    value = utils.input_string_or_list(value)
                elif DEFAULTS[name][1] == "dict":
                    value = utils.input_string_or_dict(value)[1]
            except:
                raise AttributeError

            self.__dict__[name] = value
            if not utils.update_settings_file(self.to_dict()):
                raise AttributeError

            return 0
        else:
            # FIXME. Not sure why __dict__ is part of name
            # workaround applied, ignore exception
            # raise AttributeError
            pass
コード例 #24
0
    def boot_loaders(self, boot_loaders: list):
        """
        Setter of the boot loaders.

        :param boot_loaders: The boot loaders for the profile.
        :raises ValueError: In case the supplied boot loaders were not a subset of the valid ones.
        """
        if boot_loaders == enums.VALUE_INHERITED:
            self._boot_loaders = enums.VALUE_INHERITED
            return

        if boot_loaders:
            boot_loaders_split = utils.input_string_or_list(boot_loaders)

            parent = self.parent
            if parent is not None:
                parent_boot_loaders = parent.boot_loaders
            else:
                self.logger.warning(
                    "Parent of profile \"%s\" could not be found for resolving the parent bootloaders.",
                    self.name)
                parent_boot_loaders = []
            if not set(boot_loaders_split).issubset(parent_boot_loaders):
                raise CX(
                    "Error with profile \"%s\" - not all boot_loaders are supported (given: \"%s\"; supported:"
                    "\"%s\")" % (self.name, str(boot_loaders_split),
                                 str(parent_boot_loaders)))
            self._boot_loaders = boot_loaders_split
        else:
            self._boot_loaders = []
コード例 #25
0
ファイル: utils_test.py プロジェクト: openSUSE/cobbler
def test_input_string_or_list(test_input, expected_result):
    # Arrange

    # Act
    result = utils.input_string_or_list(test_input)

    # Assert
    assert expected_result == result
コード例 #26
0
ファイル: item.py プロジェクト: openSUSE/cobbler
    def owners(self, owners: list):
        """
        TODO

        :param owners:
        :return:
        """
        self._owners = utils.input_string_or_list(owners)
コード例 #27
0
ファイル: item.py プロジェクト: openSUSE/cobbler
    def mgmt_classes(self, mgmt_classes: list):
        """
        Assigns a list of configuration management classes that can be assigned to any object, such as those used by
        Puppet's external_nodes feature.

        :param mgmt_classes: The new options for the management classes of an item.
        """
        self._mgmt_classes = utils.input_string_or_list(mgmt_classes)
コード例 #28
0
ファイル: item.py プロジェクト: y2kenny/cobbler
    def set_owners(self, data):
        """
        The owners field is a comment unless using an authz module that pays attention to it,
        like authz_ownership, which ships with Cobbler but is off by default.

        :param data: This can be a string or a list which contains all owners.
        """
        self.owners = utils.input_string_or_list(data)
コード例 #29
0
ファイル: repo.py プロジェクト: openSUSE/cobbler
    def rpm_list(self, rpms: Union[str, list]):
        """
        Rather than mirroring the entire contents of a repository (Fedora Extras, for instance, contains games, and we
        probably don't want those), make it possible to list the packages one wants out of those repos, so only those
        packages and deps can be mirrored.

        :param rpms: The rpm to mirror. This may be a string or list.
        """
        self._rpm_list = utils.input_string_or_list(rpms)
コード例 #30
0
    def set_apt_dists(self, value):
        """
        Setter for the apt dists.

        :param value: The new value for ``apt_dists``.
        :return: ``True`` if everything went correctly.
        """
        self.apt_dists = utils.input_string_or_list(value)
        return True
コード例 #31
0
ファイル: system.py プロジェクト: LeoDemoniac/cobbler
    def set_ipv6_secondaries(self, addresses, interface):
        intf = self.__get_interface(interface)
        data = utils.input_string_or_list(addresses)
        secondaries = []
        for address in data:
            if address == "" or utils.is_ip(address):
                secondaries.append(address)
            else:
                raise CX("invalid format for IPv6 IP address (%s)" % address)

        intf["ipv6_secondaries"] = secondaries
コード例 #32
0
ファイル: item_system.py プロジェクト: inthecloud247/cobbler
    def set_ipv6_secondaries(self, addresses, interface):
        intf = self.__get_interface(interface)
        data = utils.input_string_or_list(addresses)
        secondaries = []
        for address in data:
            if address == "" or utils.is_ip(address):
                secondaries.append(address)
            else:
                raise CX(_("invalid format for IPv6 IP address (%s)") % address)

        intf["ipv6_secondaries"] = secondaries
コード例 #33
0
ファイル: system.py プロジェクト: nodeg/cobbler
    def ipv6_secondaries(self, addresses: list):
        """
        TODO

        :param addresses:
        """
        data = utils.input_string_or_list(addresses)
        secondaries = []
        for address in data:
            if address == "" or utils.is_ip(address):
                secondaries.append(address)
            else:
                raise AddressValueError(
                    "invalid format for IPv6 IP address (%s)" % address)
        self._ipv6_secondaries = secondaries
コード例 #34
0
ファイル: item.py プロジェクト: openSUSE/cobbler
    def __find_compare(cls, from_search, from_obj):
        """
        Only one of the two parameters shall be given in this method. If you give both ``from_obj`` will be preferred.

        :param from_search: Tries to parse this str in the format as a search result string.
        :param from_obj: Tries to parse this str in the format of an obj str.
        :return: True if the comparison succeeded, False otherwise.
        :raises CX
        """
        if isinstance(from_obj, str):
            # FIXME: fnmatch is only used for string to string comparisions which should cover most major usage, if
            #        not, this deserves fixing
            from_obj_lower = from_obj.lower()
            from_search_lower = from_search.lower()
            # It's much faster to not use fnmatch if it's not needed
            if '?' not in from_search_lower and '*' not in from_search_lower and '[' not in from_search_lower:
                match = from_obj_lower == from_search_lower
            else:
                match = fnmatch.fnmatch(from_obj_lower, from_search_lower)
            return match
        else:
            if isinstance(from_search, str):
                if isinstance(from_obj, list):
                    from_search = utils.input_string_or_list(from_search)
                    for x in from_search:
                        if x not in from_obj:
                            return False
                    return True
                if isinstance(from_obj, dict):
                    (junk, from_search) = utils.input_string_or_dict(
                        from_search, allow_multiples=True)
                    for x in list(from_search.keys()):
                        y = from_search[x]
                        if x not in from_obj:
                            return False
                        if not (y == from_obj[x]):
                            return False
                    return True
                if isinstance(from_obj, bool):
                    if from_search.lower() in ["true", "1", "y", "yes"]:
                        inp = True
                    else:
                        inp = False
                    if inp == from_obj:
                        return True
                    return False

            raise TypeError("find cannot compare type: %s" % type(from_obj))
コード例 #35
0
ファイル: item.py プロジェクト: andrewwyatt/cobbler
    def __find_compare(self, from_search, from_obj):

        if isinstance(from_obj, str):
            # FIXME: fnmatch is only used for string to string comparisions
            # which should cover most major usage, if not, this deserves fixing
            from_obj_lower = from_obj.lower()
            from_search_lower = from_search.lower()
            # it's much faster to not use fnmatch if it's not needed
            if '?' not in from_search_lower and '*' not in from_search_lower and '[' not in from_search_lower:
                match = from_obj_lower == from_search_lower
            else:
                match = fnmatch.fnmatch(from_obj_lower, from_search_lower)
            return match
        else:
            if isinstance(from_search, str):
                if isinstance(from_obj, list):
                    from_search = utils.input_string_or_list(from_search)
                    for x in from_search:
                        if x not in from_obj:
                            return False
                    return True
                if isinstance(from_obj, dict):
                    (junk, from_search) = utils.input_string_or_dict(from_search, allow_multiples=True)
                    for x in list(from_search.keys()):
                        y = from_search[x]
                        if x not in from_obj:
                            return False
                        if not (y == from_obj[x]):
                            return False
                    return True
                if isinstance(from_obj, bool):
                    if from_search.lower() in ["true", "1", "y", "yes"]:
                        inp = True
                    else:
                        inp = False
                    if inp == from_obj:
                        return True
                    return False

            raise CX(_("find cannot compare type: %s") % type(from_obj))
コード例 #36
0
ファイル: item.py プロジェクト: BATYD-Turksat/cobbler
    def __find_compare(self, from_search, from_obj):

        if isinstance(from_obj, basestring):
            # FIXME: fnmatch is only used for string to string comparisions
            # which should cover most major usage, if not, this deserves fixing
            if fnmatch.fnmatch(from_obj.lower(), from_search.lower()):
                return True
            else:
                return False
        else:
            if isinstance(from_search, basestring):
                if isinstance(from_obj, list):
                    from_search = utils.input_string_or_list(from_search)
                    for x in from_search:
                        if x not in from_obj:
                            return False
                    return True
                if isinstance(from_obj, dict):
                    (junk, from_search) = utils.input_string_or_dict(from_search, allow_multiples=True)
                    for x in from_search.keys():
                        y = from_search[x]
                        if x not in from_obj:
                            return False
                        if not (y == from_obj[x]):
                            return False
                    return True
                if isinstance(from_obj, bool):
                    if from_search.lower() in ["true", "1", "y", "yes"]:
                        inp = True
                    else:
                        inp = False
                    if inp == from_obj:
                        return True
                    return False

            raise CX(_("find cannot compare type: %s") % type(from_obj))
コード例 #37
0
 def set_apt_dists(self, value):
     self.apt_dists = utils.input_string_or_list(value)
     return True
コード例 #38
0
 def set_apt_components(self, value):
     self.apt_components = utils.input_string_or_list(value)
コード例 #39
0
ファイル: item_mgmtclass.py プロジェクト: andrewwyatt/cobbler
 def set_packages(self, packages):
     self.packages = utils.input_string_or_list(packages)
コード例 #40
0
ファイル: item_system.py プロジェクト: langimike/cobbler
 def set_ipv6_static_routes(self, routes, interface):
     intf = self.__get_interface(interface)
     data = utils.input_string_or_list(routes)
     intf["ipv6_static_routes"] = data
     return True
コード例 #41
0
ファイル: item_system.py プロジェクト: langimike/cobbler
 def set_cnames(self, cnames, interface):
     intf = self.__get_interface(interface)
     data = utils.input_string_or_list(cnames)
     intf["cnames"] = data
     return True
コード例 #42
0
ファイル: item_mgmtclass.py プロジェクト: andrewwyatt/cobbler
 def set_files(self, files):
     self.files = utils.input_string_or_list(files)