def on_change(self, changes):
        self._model.update(changes)

        if "storage.fill_data" in changes:
            if self._fill is not changes["storage.fill_data"]:
                self._fill = changes["storage.fill_data"]
                self.application.show(self.ui_content())
        size_keys = [
            "storage.efi_size", "storage.root_size", "storage.swap_size",
            "storage.config_size", "storage.logging_size"
        ]
        if not self._fill:
            size_keys.append("storage.data_size")
        if changes.contains_any(size_keys):
            self._free_space = self.__calculate_free_space()
            if "storage.free_space" in self.widgets:
                self.widgets["storage.free_space"].text("%s MB" %
                                                        self._free_space)
            if self._fill:
                self.widgets["storage.data_size"].text("%s" % self._free_space)
            if self._free_space < 0:
                if self._fill:
                    raise InvalidData("Data partition must be at least 0 MB")
                else:
                    raise InvalidData("Free space must not be negative")
            else:
                for w in self.widgets:
                    if hasattr(self.widgets[w], "notice"):
                        self.widgets[w].notice("")
                self._on_ui_change(self._NodePlugin__invalid_changes)
Example #2
0
 def update(self, name, slaves, options):
     if name is not None and not name.startswith("bond"):
         raise InvalidData("Bond ifname must start with 'bond'")
     if slaves is not None and type(slaves) is not list:
         raise InvalidData("Slaves must be a list")
     options = options or ""
     return {"OVIRT_BOND_SLAVES": ",".join(slaves) if slaves else None,
             "OVIRT_BOND_OPTIONS": options if name else None}
Example #3
0
 def _validates(self):
     if self.is_password:
         self.logger.debug("Doing security check")
         msg = ""
         pw, pwc = self._values()
         try:
             msg = security.password_check(pw, pwc,
                                           min_length=self.min_length)
         except ValueError as e:
             msg = e.message
             if msg:
                 raise InvalidData(msg)
         self._additional_notice = msg
Example #4
0
    def _on_ui_change(self, change):
        """Called when some widget was changed
        change is expected to be a dict.
        """
        if type(change) not in [dict, Changeset]:
            self.logger.warning("Change is not a dict: %s (%s)" %
                                (repr(change), type(change)))

        change = Changeset(change)

        self.logger.debug("Passing UI change to callback on_change: %s" %
                          change)

        msg = None
        self.__changes.drop(change.keys())

        try:
            # Run validators
            self.__validate(change)

            try:
                # Run custom validation
                self.on_change(change)

            except exceptions.InvalidData:
                # If caught here, it's from custom validation, and we
                # don't know for sure what failed, so flag everything
                self.__invalid_changes.update(dict((k, v) for (k, v) in
                                              change.iteritems()))
                raise

            self.__changes.update(change)

        except exceptions.InvalidData as e:
            msg = e.message

        except Exception as e:
            self.on_valid(False)
            self.application.show_exception(e)

        all_changes_are_valid = self.is_only_valid_changes()

        for path in change.keys():
            if path in self.widgets:
                self.logger.debug("Updating %s widgets validity: %s (%s)"
                                  % (path, all_changes_are_valid, msg))
                self.widgets[path].valid(all_changes_are_valid)
                try:
                    self.widgets[path].notice(msg)
                except NotImplementedError:
                    self.logger.debug("Widget doesn't support notices.")
                    notice = ("The following requirements need to " +
                              "be met: \n%s" % msg)
                    self.application.show_exception(InvalidData(notice))
            else:
                self.logger.warning("No widget for path %s" % path)

        self.logger.debug("All valid changes: %s" %
                          self.__changes)
        self.logger.debug("All invalid changes: %s" %
                          self.__invalid_changes)

        self.on_valid(all_changes_are_valid)

        return all_changes_are_valid
 def update(self, profile):
     all_profiles = tuned.get_available_profiles()
     if profile not in all_profiles:
         raise InvalidData("Unknown tuned profile: %s" % profile)
     return {"OVIRT_TUNED_PROFILE": profile}