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
def set_params(self, params): (success, value) = utils.input_string_or_dict(params, allow_multiples=True) if not success: raise CX(_("invalid parameters")) else: self.params = value
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
def __getattr__(self, name): """ This returns the current value of the setting named in the args. :param name: The setting to return the value of. :return: The value of the setting "name". """ try: if name == "kernel_options": # backwards compatibility -- convert possible string value to dict (success, result) = utils.input_string_or_dict(self.__dict__[name], allow_multiples=False) self.__dict__[name] = result return result # TODO: This needs to be explicitly tested elif name == "manage_dhcp": return self.manage_dhcp_v4 return self.__dict__[name] except Exception as error: if name in DEFAULTS: lookup = DEFAULTS[name][0] self.__dict__[name] = lookup return lookup else: raise AttributeError( f"no settings attribute named '{name}' found") from error
def test_input_string_or_dict(testinput, expected_result, possible_exception): # Arrange # Act with possible_exception: result = utils.input_string_or_dict(testinput) # Assert assert expected_result == result
def set_environment(self, options): """ Yum can take options from the environment. This puts them there before each reposync. """ (success, value) = utils.input_string_or_dict(options, allow_multiples=False) if not success: raise CX(_("invalid environment options")) else: self.environment = value
def set_yumopts(self, options): """ Kernel options are a space delimited list, like 'a=b c=d e=f g h i=j' or a dictionary. """ (success, value) = utils.input_string_or_dict(options, allow_multiples=False) if not success: raise CX(_("invalid yum options")) else: self.yumopts = value
def set_template_files(self, template_files): """ A comma seperated list of source=destination templates that should be generated during a sync. """ (success, value) = utils.input_string_or_dict(template_files, allow_multiples=False) if not success: return False else: self.template_files = value
def set_kernel_options_post(self, options): """ Post kernel options are a space delimited list, like 'a=b c=d e=f g h i=j' or a dict. """ (success, value) = utils.input_string_or_dict(options, allow_multiples=True) if not success: raise CX(_("invalid post kernel options")) else: self.kernel_options_post = value
def set_boot_files(self, boot_files): """ A comma seperated list of req_name=source_file_path that should be fetchable via tftp """ (success, value) = utils.input_string_or_dict(boot_files, allow_multiples=False) if not success: return False else: self.boot_files = value
def set_fetchable_files(self, fetchable_files): """ A comma seperated list of virt_name=path_to_template that should be fetchable via tftp or a webserver """ (success, value) = utils.input_string_or_dict(fetchable_files, allow_multiples=False) if not success: return False else: self.fetchable_files = value
def fetchable_files(self, fetchable_files: Union[str, dict]): """ Setter for the fetchable files. :param fetchable_files: Files which will be made available to external users. """ (success, value) = utils.input_string_or_dict(fetchable_files, allow_multiples=False) if not success: raise TypeError("fetchable_files were handed wrong values") else: self._fetchable_files = value
def set_params(self, params): """ Setter for the params of the managementclass. :param params: The new params for the object. """ (success, value) = utils.input_string_or_dict(params, allow_multiples=True) if not success: raise CX("invalid parameters") else: self.params = value
def set_rsyncopts(self, options): """ rsync options are a space delimited list :param options: Something like '-a -S -H -v' """ (success, value) = utils.input_string_or_dict(options, allow_multiples=False) if not success: raise CX(_("invalid rsync options")) else: self.rsyncopts = value
def boot_files(self, boot_files: dict): """ A comma separated list of req_name=source_file_path that should be fetchable via tftp. :param boot_files: The new value for the boot files used by the item. """ (success, value) = utils.input_string_or_dict(boot_files, allow_multiples=False) if not success: raise TypeError("boot_files were handed wrong values") else: self._boot_files = value
def set_kernel_options(self, options): """ Kernel options are a space delimited list, like 'a=b c=d e=f g h i=j' or a dict. :param options: The new kernel options as a space delimited list. """ (success, value) = utils.input_string_or_dict(options, allow_multiples=True) if not success: raise CX("invalid kernel options") else: self.kernel_options = value
def set_fetchable_files(self, fetchable_files): """ A comma seperated list of virt_name=path_to_template that should be fetchable via tftp or a webserver :param fetchable_files: Files which will be made available to external users. :return: False if this does not succeed. """ (success, value) = utils.input_string_or_dict(fetchable_files, allow_multiples=False) if not success: return False else: self.fetchable_files = value
def kernel_options_post(self, options): """ Post kernel options are a space delimited list, like 'a=b c=d e=f g h i=j' or a dict. :param options: The new kernel options as a space delimited list. :raises CX """ (success, value) = utils.input_string_or_dict(options, allow_multiples=True) if not success: raise ValueError("invalid post kernel options") else: self._kernel_options_post = value
def template_files(self, template_files: dict): """ A comma seperated list of source=destination templates that should be generated during a sync. :param template_files: The new value for the template files which are used for the item. :raises ValueError: In case the conversion from non dict values was not successful. """ (success, value) = utils.input_string_or_dict(template_files, allow_multiples=False) if not success: raise ValueError("template_files should be of type dict") else: self._template_files = value
def yumopts(self, options: Union[str, dict]): """ Kernel options are a space delimited list. :param options: Something like ``a=b c=d e=f g h i=j`` or a dictionary. :raises ValueError: In case the presented data could not be parsed into a dictionary. """ (success, value) = utils.input_string_or_dict(options, allow_multiples=False) if not success: raise ValueError("invalid yum options") else: self._yumopts = value
def rsyncopts(self, options: Union[str, dict]): """ Setter for the ``rsyncopts`` property. :param options: Something like '-a -S -H -v' :raises ValueError: In case the options provided can't be parsed. """ (success, value) = utils.input_string_or_dict(options, allow_multiples=False) if not success: raise ValueError("invalid rsync options") else: self._rsyncopts = value
def kernel_options_post(self, options): """ Setter for ``kernel_options_post``. :param options: The new kernel options as a space delimited list. :raises ValueError: In case the options could not be split successfully. """ (success, value) = utils.input_string_or_dict(options, allow_multiples=True) if not success: raise ValueError("invalid post kernel options") else: self._kernel_options_post = value
def params(self, params: dict): """ Setter for the params of the management class. :param params: The new params for the object. :raises TypeError: Raised in case ``params`` is invalid. """ (success, value) = utils.input_string_or_dict(params, allow_multiples=True) if not success: raise TypeError("invalid parameters") self._params = value
def environment(self, options: Union[str, dict]): r""" Setter for the ``environment`` property. :param options: These are environment variables which are set before each reposync. :raises ValueError: In case the variables provided could not be parsed. """ (success, value) = utils.input_string_or_dict(options, allow_multiples=False) if not success: raise ValueError("invalid environment options") else: self._environment = value
def set_boot_files(self, boot_files): """ A comma seperated list of req_name=source_file_path that should be fetchable via tftp. :param boot_files: The new value for the boot files used by the item. :return: False if this does not succeed. """ (success, value) = utils.input_string_or_dict(boot_files, allow_multiples=False) if not success: return False else: self.boot_files = value
def autoinstall_meta(self, options: dict): """ Setter for the ``autoinstall_meta`` property. :param options: The new options for the automatic installation meta options. :raises ValueError: If splitting the value does not succeed. """ (success, value) = utils.input_string_or_dict(options, allow_multiples=True) if not success: raise ValueError("invalid options given for autoinstall meta") else: self._autoinstall_meta = value
def set_environment(self, options: Union[str, dict]): """ Yum can take options from the environment. This puts them there before each reposync. :param options: These are environment variables which are set before each reposync. """ (success, value) = utils.input_string_or_dict(options, allow_multiples=False) if not success: raise CX("invalid environment options") else: self.environment = value
def set_template_files(self, template_files): """ A comma seperated list of source=destination templates that should be generated during a sync. :param template_files: The new value for the template files which are used for the item. :return: False if this does not succeed. """ (success, value) = utils.input_string_or_dict(template_files, allow_multiples=False) if not success: return False else: self.template_files = value
def set_autoinstall_meta(self, options): """ A comma delimited list of key value pairs, like 'a=b,c=d,e=f' or a dict. The meta tags are used as input to the templating system to preprocess automatic installation template files """ (success, value) = utils.input_string_or_dict(options, allow_multiples=True) if not success: return False else: self.autoinstall_meta = value
def rsyncopts(self, options: Union[str, dict]): """ rsync options are a space delimited list :param options: Something like '-a -S -H -v' :raises CX """ (success, value) = utils.input_string_or_dict(options, allow_multiples=False) if not success: raise ValueError("invalid rsync options") else: self._rsyncopts = value