Exemple #1
0
def __migrate_settingsfile_int_bools(settings_dict: dict) -> dict:
    for key in settings_dict:
        if DEFAULTS[key][1] == "bool":
            settings_dict[key] = utils.input_boolean(settings_dict[key])
    mgmt_parameters = "mgmt_parameters"
    if mgmt_parameters in settings_dict and "from_cobbler" in settings_dict[
            mgmt_parameters]:
        settings_dict[mgmt_parameters]["from_cobbler"] = utils.input_boolean(
            settings_dict[mgmt_parameters]["from_cobbler"])
    return settings_dict
Exemple #2
0
    def set_mirror_locally(self, value):
        """
        Setter for the local mirror property.

        :param value: The new value for ``mirror_locally``.
        """
        self.mirror_locally = utils.input_boolean(value)
Exemple #3
0
    def set_is_dir(self, is_dir):
        """
        If true, treat file resource as a directory. Templates are ignored.

        :param is_dir: This is the path to check if it is a directory.
        """
        self.is_dir = utils.input_boolean(is_dir)
Exemple #4
0
 def set_enable_menu(self, enable_menu):
     """
     Sets whether or not the profile will be listed in the default
     PXE boot menu.  This is pretty forgiving for YAML's sake.
     """
     self.enable_menu = utils.input_boolean(enable_menu)
     return True
    def set_is_definition(self, isdef):
        """
        Setter for property ``is_defintion``.

        :param isdef: The new value for the property.
        """
        self.is_definition = utils.input_boolean(isdef)
Exemple #6
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
Exemple #7
0
    def set_keep_updated(self, keep_updated):
        """
        This allows the user to disable updates to a particular repo for whatever reason.

        :param keep_updated: This may be a bool-like value if the repository shall be keept up to date or not.
        """
        self.keep_updated = utils.input_boolean(keep_updated)
Exemple #8
0
 def set_enable_menu(self, enable_menu):
     """
     Sets whether or not the profile will be listed in the default
     PXE boot menu.  This is pretty forgiving for YAML's sake.
     """
     self.enable_menu = utils.input_boolean(enable_menu)
     return True
Exemple #9
0
    def set_enable_gpxe(self, enable_gpxe: bool):
        """
        Sets whether or not the profile will use gPXE for booting.

        :param enable_gpxe: New boolean value for enabling gPXE.
        """
        self.enable_gpxe = utils.input_boolean(enable_gpxe)
Exemple #10
0
    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
Exemple #11
0
    def set_enable_menu(self, enable_menu: bool):
        """
        Sets whether or not the profile will be listed in the default PXE boot menu. This is pretty forgiving for
        YAML's sake.

        :param enable_menu: New boolean value for enabling the menu.
        """
        self.enable_menu = utils.input_boolean(enable_menu)
Exemple #12
0
def test_input_boolean(testinput, expected_result):
    # Arrange

    # Act
    result = utils.input_boolean(testinput)

    # Assert
    assert expected_result == result
Exemple #13
0
 def enable_ipxe(self, enable_ipxe: bool):
     """
     Sets whether or not the system will use iPXE for booting.
     """
     enable_ipxe = utils.input_boolean(enable_ipxe)
     if not isinstance(enable_ipxe, bool):
         raise TypeError("enable_ipxe needs to be of type bool")
     self._enable_ipxe = enable_ipxe
Exemple #14
0
def test_input_boolean(testinput, expected_exception, expected_result):
    # Arrange

    # Act
    with expected_exception:
        result = utils.input_boolean(testinput)

        # Assert
        assert expected_result == result
Exemple #15
0
    def is_definition(self, isdef: bool):
        """
        Setter for property ``is_defintion``.

        :param isdef: The new value for the property.
        """
        isdef = utils.input_boolean(isdef)
        if not isinstance(isdef, bool):
            raise TypeError("Field is_defintion from mgmtclass must be of type bool.")
        self._is_definition = isdef
Exemple #16
0
    def enable_ipxe(self, enable_ipxe: bool):
        """
        Sets whether or not the profile will use iPXE for booting.

        :param enable_ipxe: New boolean value for enabling iPXE.
        """
        enable_ipxe = utils.input_boolean(enable_ipxe)
        if not isinstance(enable_ipxe, bool):
            raise TypeError("enable_ipxe needs to be of type bool")
        self._enable_ipxe = enable_ipxe
Exemple #17
0
def migrate(settings: dict) -> dict:
    """
    Migration of the settings ``settings`` to the V3.2.1 settings

    :param settings: The settings dict to migrate
    :return: The migrated dict
    """
    # int bool to real bool conversion
    bool_values = [
        "allow_duplicate_hostnames", "allow_duplicate_ips",
        "allow_duplicate_macs", "allow_duplicate_macs",
        "allow_dynamic_settings", "always_write_dhcp_entries",
        "anamon_enabled", "bind_manage_ipmi", "build_reporting_enabled",
        "cache_enabled", "client_use_https", "client_use_localhost",
        "convert_server_to_ip", "enable_gpxe", "enable_menu",
        "ldap_anonymous_bind", "ldap_tls", "manage_dhcp", "manage_dns",
        "manage_genders", "manage_rsync", "manage_tftp", "manage_tftpd",
        "nopxe_with_triggers", "nsupdate_enabled", "puppet_auto_setup",
        "puppet_parameterized_classes", "pxe_just_once",
        "redhat_management_permissive", "register_new_installs",
        "remove_old_puppet_certs_automatically", "restart_dhcp", "restart_dns",
        "run_install_triggers", "scm_track_enabled", "serializer_pretty_json",
        "sign_puppet_certs_automatically", "virt_auto_boot",
        "yum_post_install_mirror"
    ]
    for key in bool_values:
        if key in settings:
            settings[key] = utils.input_boolean(settings[key])
    mgmt_parameters = "mgmt_parameters"
    if mgmt_parameters in settings and "from_cobbler" in settings[
            mgmt_parameters]:
        settings[mgmt_parameters]["from_cobbler"] = utils.input_boolean(
            settings[mgmt_parameters]["from_cobbler"])

    # rename old settings filename
    filename = "/etc/cobbler/settings"
    if os.path.exists(filename):
        os.rename(filename, filename + ".yaml")
        filename += ".yaml"

    if not validate(settings):
        raise SchemaError("V3.2.1: Schema error while validating")
    return normalize(settings)
Exemple #18
0
    def ipv6_autoconfiguration(self, value: bool):
        """
        TODO

        :param value:
        """
        value = utils.input_boolean(value)
        if not isinstance(value, bool):
            raise TypeError("ipv6_autoconfiguration needs to be of type bool")
        self._ipv6_autoconfiguration = value
Exemple #19
0
    def mirror_locally(self, value: bool):
        """
        Setter for the local mirror property.

        :param value: The new value for ``mirror_locally``.
        """
        value = utils.input_boolean(value)
        if not isinstance(value, bool):
            raise TypeError("mirror_locally needs to be of type bool")
        self._mirror_locally = value
Exemple #20
0
    def set_monit_enabled(self, monit_enabled):
        """
        If true, allows per-system to start Monit to monitor system services such as apache.
        If monit is not running it will start the service.

        If false, no management of monit will take place. If monit is not running it will not
        be started. If monit is running it will not be stopped or restarted.
        """
        self.monit_enabled = utils.input_boolean(monit_enabled)
        return True
Exemple #21
0
    def is_dir(self, is_dir: bool):
        """
        If true, treat file resource as a directory. Templates are ignored.

        :param is_dir: This is the path to check if it is a directory.
        """
        is_dir = utils.input_boolean(is_dir)
        if not isinstance(is_dir, bool):
            raise TypeError(
                "Field is_dir in object file needs to be of type bool!")
        self._is_dir = is_dir
Exemple #22
0
def validate_virt_auto_boot(value: bool) -> bool:
    """
    For Virt only.
    Specifies whether the VM should automatically boot upon host reboot 0 tells Koan not to auto_boot virtuals.

    :param value: May be True or False.
    """
    value = utils.input_boolean(value)
    if not isinstance(value, bool):
        raise TypeError("virt_auto_boot needs to be of type bool.")
    return value
Exemple #23
0
    def enable_menu(self, enable_menu: bool):
        """
        Setter for the ``enable_menu`` property.

        :param enable_menu: New boolean value for enabling the menu.
        :raises TypeError: In case the boolean could not be converted successfully.
        """
        enable_menu = utils.input_boolean(enable_menu)
        if not isinstance(enable_menu, bool):
            raise TypeError("enable_menu needs to be of type bool")
        self._enable_menu = enable_menu
Exemple #24
0
    def static(self, truthiness: bool):
        """
        TODO

        :param truthiness:
        """
        truthiness = utils.input_boolean(truthiness)
        if not isinstance(truthiness, bool):
            raise TypeError(
                "Field static of NetworkInterface needs to be of Type bool!")
        self._static = truthiness
Exemple #25
0
    def keep_updated(self, keep_updated: bool):
        """
        This allows the user to disable updates to a particular repo for whatever reason.

        :param keep_updated: This may be a bool-like value if the repository shall be keept up to date or not.
        """
        keep_updated = utils.input_boolean(keep_updated)
        if not isinstance(keep_updated, bool):
            raise TypeError(
                "Field keep_updated of object repo needs to be of type bool!")
        self._keep_updated = keep_updated
Exemple #26
0
    def enable_menu(self, enable_menu: bool):
        """
        Sets whether or not the profile will be listed in the default PXE boot menu. This is pretty forgiving for
        YAML's sake.

        :param enable_menu: New boolean value for enabling the menu.
        """
        enable_menu = utils.input_boolean(enable_menu)
        if not isinstance(enable_menu, bool):
            raise TypeError("enable_menu needs to be of type bool")
        self._enable_menu = enable_menu
Exemple #27
0
    def keep_updated(self, keep_updated: bool):
        """
        Setter for the keep_updated property.

        :param keep_updated: This may be a bool-like value if the repository shall be kept up to date or not.
        :raises TypeError: In case the conversion to a bool was unsuccessful.
        """
        keep_updated = utils.input_boolean(keep_updated)
        if not isinstance(keep_updated, bool):
            raise TypeError("Field keep_updated of object repo needs to be of type bool!")
        self._keep_updated = keep_updated
Exemple #28
0
    def enable_ipxe(self, enable_ipxe: bool):
        r"""
        Setter for the ``enable_ipxe`` property.

        :param enable_ipxe: New boolean value for enabling iPXE.
        :raises TypeError: In case after the conversion, the new value is not of type ``bool``.
        """
        enable_ipxe = utils.input_boolean(enable_ipxe)
        if not isinstance(enable_ipxe, bool):
            raise TypeError("enable_ipxe needs to be of type bool")
        self._enable_ipxe = enable_ipxe
Exemple #29
0
    def management(self, truthiness: bool):
        """
        TODO

        :param truthiness:
        """
        truthiness = utils.input_boolean(truthiness)
        if not isinstance(truthiness, bool):
            raise TypeError(
                "Field management of object NetworkInterface needs to be of type bool!"
            )
        self._management = truthiness
Exemple #30
0
    def connected_mode(self, truthiness: bool):
        """
        TODO

        :param truthiness:
        """
        truthiness = utils.input_boolean(truthiness)
        if not isinstance(truthiness, bool):
            raise TypeError(
                "Field connected_mode of object NetworkInterface needs to be of type bool!"
            )
        self._connected_mode = truthiness
Exemple #31
0
def validate_virt_pxe_boot(value: bool) -> bool:
    """
    For Virt only.
    Specifies whether the VM should use PXE for booting 0 tells Koan not to PXE boot virtuals

    :param value: May be True or False.
    :return: True or False
    """
    value = utils.input_boolean(value)
    if not isinstance(value, bool):
        raise TypeError("virt_pxe_boot needs to be of type bool.")
    return value
Exemple #32
0
    def set_netboot_enabled(self, netboot_enabled):
        """
        If true, allows per-system PXE files to be generated on sync (or add).  If false,
        these files are not generated, thus eliminating the potential for an infinite install
        loop when systems are set to PXE boot first in the boot order.  In general, users
        who are PXE booting first in the boot order won't create system definitions, so this
        feature primarily comes into play for programmatic users of the API, who want to
        initially create a system with netboot enabled and then disable it after the system installs,
        as triggered by some action in kickstart %post.   For this reason, this option is not
        surfaced in the CLI, output, or documentation (yet).

        Use of this option does not affect the ability to use PXE menus.  If an admin has machines
        set up to PXE only after local boot fails, this option isn't even relevant.
        """
        self.netboot_enabled = utils.input_boolean(netboot_enabled)
Exemple #33
0
    def set_dns_name(self, dns_name, interface):
        """
        Set DNS name for interface.

        @param: str dns_name (dns name)
        @param: str interface (interface name)
        @returns: True or CX
        """
        dns_name = validate.hostname(dns_name)
        if dns_name != "" and utils.input_boolean(self.collection_mgr._settings.allow_duplicate_hostnames) is False:
            matched = self.collection_mgr.api.find_items("system", {"dns_name": dns_name})
            for x in matched:
                if x.name != self.name:
                    raise CX("DNS name duplicated: %s" % dns_name)

        intf = self.__get_interface(interface)
        intf["dns_name"] = dns_name
Exemple #34
0
    def set_ipv6_address(self, address, interface):
        """
        Set IPv6 address on interface.

        @param: str address (ip address)
        @param: str interface (interface name)
        @returns: True or CX
        """
        address = validate.ipv6_address(address)
        if address != "" and utils.input_boolean(self.collection_mgr._settings.allow_duplicate_ips) is False:
            matched = self.collection_mgr.api.find_items("system", {"ipv6_address": address})
            for x in matched:
                if x.name != self.name:
                    raise CX("IP address duplicated: %s" % address)

        intf = self.__get_interface(interface)
        intf["ipv6_address"] = address
Exemple #35
0
    def set_mac_address(self, address, interface):
        """
        Set mac address on interface.

        @param: str address (mac address)
        @param: str interface (interface name)
        @returns: True or CX
        """
        address = validate.mac_address(address)
        if address == "random":
            address = utils.get_random_mac(self.collection_mgr.api)
        if address != "" and utils.input_boolean(self.collection_mgr._settings.allow_duplicate_macs) is False:
            matched = self.collection_mgr.api.find_items("system", {"mac_address": address})
            for x in matched:
                if x.name != self.name:
                    raise CX("MAC address duplicated: %s" % address)

        intf = self.__get_interface(interface)
        intf["mac_address"] = address
Exemple #36
0
 def set_is_definition(self, isdef):
     self.is_definition = utils.input_boolean(isdef)
Exemple #37
0
 def set_is_dir(self, is_dir):
     """
     If true, treat file resource as a directory. Templates are ignored.
     """
     self.is_dir = utils.input_boolean(is_dir)
 def set_keep_updated(self, keep_updated):
     """
     This allows the user to disable updates to a particular repo for whatever reason.
     """
     self.keep_updated = utils.input_boolean(keep_updated)
Exemple #39
0
 def set_repos_enabled(self, repos_enabled):
     self.repos_enabled = utils.input_boolean(repos_enabled)
     return True
Exemple #40
0
 def set_connected_mode(self, truthiness, interface):
     intf = self.__get_interface(interface)
     intf["connected_mode"] = utils.input_boolean(truthiness)
Exemple #41
0
 def set_ldap_enabled(self, ldap_enabled):
     self.ldap_enabled = utils.input_boolean(ldap_enabled)
     return True
Exemple #42
0
 def set_static(self, truthiness, interface):
     intf = self.__get_interface(interface)
     intf["static"] = utils.input_boolean(truthiness)
     return True
Exemple #43
0
 def set_enable_gpxe(self, enable_gpxe):
     """
     Sets whether or not the system will use gPXE for booting.
     """
     self.enable_gpxe = utils.input_boolean(enable_gpxe)
     return True
Exemple #44
0
 def set_ipv6_autoconfiguration(self, truthiness):
     self.ipv6_autoconfiguration = utils.input_boolean(truthiness)
     return True
Exemple #45
0
 def set_management(self, truthiness, interface):
     intf = self.__get_interface(interface)
     intf["management"] = utils.input_boolean(truthiness)
     return True
 def set_mirror_locally(self, value):
     self.mirror_locally = utils.input_boolean(value)
Exemple #47
0
 def set_enable_gpxe(self, enable_gpxe):
     """
     Sets whether or not the profile will use gPXE for booting.
     """
     self.enable_gpxe = utils.input_boolean(enable_gpxe)