예제 #1
0
    def on_change(self, changes):
        self.logger.debug("Boot device changes: %s" % changes)
        devices = self.storage_discovery.all_devices_for_ui_table()
        if devices:
            if changes.contains_any(["boot.device"]):
                device = changes["boot.device"]
                if device == "other":
                    self.widgets["label.details"].text("")
                else:
                    changes["boot.device.current"] = device
                    self._model.update(changes)
                    self.widgets["label.details"].set_device(device)
        else:
            # Disable the continue button
            buttons = plugins.UIElements(self.widgets["boot"].buttons)
            buttons["button.next"].enabled(False)

        if changes.contains_any(["boot.device.custom"]):
            if self.storage_discovery.devices.live_disk_name() == \
                    self.storage_discovery.devices.translate_device_name(
                        changes["boot.device.custom"]):
                raise exceptions.InvalidData("Can't be the same as "
                                             "the live device")
            else:
                self._model.update(changes)
예제 #2
0
파일: defaults.py 프로젝트: oVirt/Node
 def update(self, bootproto, ipaddr, netmask, gateway):
     if bootproto not in ["auto", "static", "none", "dhcp", None]:
         raise exceptions.InvalidData("Unknown bootprotocol: %s" %
                                      bootproto)
     (valid.IPv6Address() | valid.Empty(or_none=True))(ipaddr)
     (valid.IPv6Address() | valid.Empty(or_none=True))(netmask)
     (valid.IPv6Address() | valid.Empty(or_none=True))(gateway)
예제 #3
0
 def update(self, iface, bootproto, ipaddr=None, netmask=None, gateway=None,
            vlanid=None):
     if bootproto not in ["static", "none", "dhcp", None]:
         raise exceptions.InvalidData("Unknown bootprotocol: %s" %
                                      bootproto)
     (valid.IPv4Address() | valid.Empty(or_none=True))(ipaddr)
     (valid.IPv4Address() | valid.Empty(or_none=True))(netmask)
     (valid.IPv4Address() | valid.Empty(or_none=True))(gateway)
예제 #4
0
    def __validate(self, changes):
        """Test changes against the validators

        Args:
            changes: A dict of (path, value) to be checked

        Returns:
            True on a valid value or if there is no validator for a path
        Raises:
            InvalidData on any invalid data
        """
        validators = self.validators()
        widgets = self.widgets

        for change in changes.items():
            path, value = change

            problems = []

            # We assume that the change is invalid, as long as it
            # isn't validated
            self.__invalid_changes.update({path: value})

            self.logger.debug("Validation of path %s" % str(change))

            try:
                if path in validators:
                    problems.append(validators[path](value))
            except exceptions.InvalidData as e:
                msg = e.message or str(e)
                self.logger.debug("Validation failed on validator with: %s"
                                  % msg)
                problems.append(msg)

            try:
                if path in widgets:
                    problems.append(widgets[path]._validates())
            except exceptions.InvalidData as e:
                msg = e.message or str(e)
                self.logger.debug("Validation failed on widget with: %s"
                                  % msg)
                problems.append(msg)

            problems = [p for p in problems if p not in [True, None]]

            if problems:
                txt = "\n".join(problems)
                self.logger.debug("Validation failed with: %s" % problems)
                raise exceptions.InvalidData(txt)

            # If we reach this line, then it's valid data
            self.__invalid_changes.drop([path])

        validates = self.__invalid_changes.is_empty()
        self.logger.debug("Validates? %s (%s)" % (validates,
                                                  self.__invalid_changes))

        return validates
예제 #5
0
    def on_change(self, changes):
        if changes.contains_any(
            ["snmp.password", "snmp.password_confirmation"]):

            snmp_pw = self._model.get("snmp.password", "")
            snmp_pw_conf = self._model.get("snmp.password_confirmation", "")
            if snmp_pw != snmp_pw_conf:
                raise exceptions.InvalidData("Passwords must be the same.")
            else:
                self.widgets["snmp.password"].valid(True)
                self.widgets["snmp.password_confirmation"].valid(True)
예제 #6
0
파일: cim_page.py 프로젝트: oVirt/Node
    def on_change(self, changes):
        if changes.contains_any(["cim.password", "cim.password_confirmation"]):
            self._model.update(changes)
            root_pw, root_pw_conf = self._model.get("cim.password", ""), \
                self._model.get("cim.password_confirmation", "")

            if root_pw != root_pw_conf:
                raise exceptions.InvalidData("Passwords must be the same.")
            else:
                self.widgets["cim.password"].valid(True)
                self.widgets["cim.password_confirmation"].valid(True)
예제 #7
0
    def on_change(self, changes):
        if changes.contains_any(
            ["passwd.admin.password", "passwd.admin.password_confirmation"]):
            self._model.update(changes)
            model = self._model
            admin_pw = model.get("passwd.admin.password", "")
            admin_pw_conf = model.get("passwd.admin.password_confirmation", "")

            if admin_pw != admin_pw_conf:
                raise exceptions.InvalidData("Passwords must be the same.")
            else:
                self.widgets["passwd.admin.password"].valid(True)
                self.widgets["passwd.admin.password_confirmation"].valid(True)
 def on_change(self, changes):
     self.logger.debug("Installation device changes: %s" % changes)
     if changes.contains_any(["installation.device.current"]):
         changed_device = changes["installation.device.current"]
         if changed_device:
             selected_devices = \
                 self.widgets["installation.device.current"].selection()
             self.logger.debug("selected devices: %s" % selected_devices)
             changes["installation.devices"] = selected_devices
             self._model.update(changes)
     if changes.contains_any(["installation.device.custom"]):
         if self.storage_discovery.devices.live_disk_name() == \
                 self.storage_discovery.devices.translate_device_name(
                     changes["installation.device.custom"]):
             raise exceptions.InvalidData("Can't be the same as " +
                                          "the live device")
         elif self.storage_discovery.devices.translate_device_name(
                 changes["installation.device.custom"]) in \
                 self.widgets["installation.device.current"].selection():
             raise exceptions.InvalidData(
                 "%s is already selected" %
                 changes["installation.device.custom"])
         else:
             self._model.update(changes)
    def on_change(self, changes):
        self.logger.debug("Boot device changes: %s" % changes)
        if changes.contains_any(["boot.device"]):
            device = changes["boot.device"]
            if device == "other":
                self.widgets["label.details"].text("")
            else:
                changes["boot.device.current"] = device
                self._model.update(changes)
                self.widgets["label.details"].set_device(device)

        if changes.contains_any(["boot.device.custom"]):
            if self.storage_discovery.devices.live_disk_name() == \
                    self.storage_discovery.devices.translate_device_name(
                        changes["boot.device.custom"]):
                raise exceptions.InvalidData("Can't be the same as "
                                             "the live device")
            else:
                self._model.update(changes)
예제 #10
0
    def on_change(self, changes):
        if changes.contains_any(["admin.password",
                                 "admin.password_confirmation"]):
            self._model.update(changes)
            admin_pw, admin_pw_conf = self._model.get("admin.password", ""), \
                self._model.get("admin.password_confirmation", "")

            try:
                min_pw_length = 1
                msg = password_check(admin_pw, admin_pw_conf, min_pw_length)
                self.widgets["admin.password"].valid(True)
                self.widgets["admin.password_confirmation"].valid(True)
                if msg:
                    self.widgets["password.info"].text(msg)
                else:
                    self.widgets["password.info"].text("")
            except ValueError as e:
                self.widgets["password.info"].text("")
                raise exceptions.InvalidData(e.message)
예제 #11
0
    def on_merge(self, effective_changes):
        self.logger.debug("Saving security page")
        changes = Changeset(self.pending_changes(False))
        effective_model = Changeset(self.model())
        effective_model.update(effective_changes)

        self.logger.debug("Changes: %s" % changes)
        self.logger.debug("Effective Model: %s" % effective_model)

        ssh_keys = [
            "ssh.pwauth", "strongrng.num_bytes", "strongrng.disable_aesni"
        ]
        passwd_keys = [
            "passwd.admin.password", "passwd.admin.password_confirmation"
        ]

        txs = utils.Transaction("Updating security configuration")

        if changes.contains_any(ssh_keys):
            model = defaults.SSH()
            model.update(*effective_model.values_for(ssh_keys))
            txs += model.transaction()

        if changes.contains_any(passwd_keys):
            pw, pwc = effective_model.values_for(passwd_keys)
            if pw != pwc:
                raise exceptions.InvalidData("Passwords do not match")
            passwd = utils.security.Passwd()

            # Create a custom transaction element, because the password
            # is not handled/saved in the defaults file
            class SetAdminPasswd(utils.Transaction.Element):
                title = "Setting admin password"

                def commit(self):
                    self.logger.debug("Setting admin password.")
                    passwd.set_password("admin", pw)

            txs += [SetAdminPasswd()]

        progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self)
        progress_dialog.run()
예제 #12
0
    def on_change(self, changes):
        if changes.contains_any(
            ["upgrade.password", "upgrade.password_confirmation"]):
            self._model.update(changes)
            up_pw, up_pw_conf = self._model.get("upgrade.password", ""), \
                self._model.get("upgrade.password_confirmation", "")

            if up_pw != up_pw_conf:
                self.widgets["password.info"].text("")
                raise exceptions.InvalidData("Passwords must be the same.")
            else:
                self.widgets["upgrade.password"].valid(True)
                self.widgets["upgrade.password_confirmation"].valid(True)
                self.widgets["password.info"].text("")

                if not up_pw and not up_pw_conf:
                    msg = self.__no_new_password_msg
                    self.widgets["password.info"].text(msg)

        if changes.contains_any(["upgrade.current_password"]):
            # Hide any message which was shown
            self.widgets["current_password.info"].text("")
예제 #13
0
    def validate(self, changes):
        """Test changes against the validators

        Args:
            changes: A dict of (path, value) to be checked

        Returns:
            True on a valid value or if there is no validator for a path
        Raises:
            InvalidData on any invalid data
        """
        validators = self.validators()
        for path, value in changes.items():
            if path in validators:
                msg = None
                try:
                    msg = validators[path](value)
                except exceptions.InvalidData as e:
                    msg = e.message
                    self.logger.debug("Failed to validate %s: %s" % (path, e))

                # True and None are allowed values
                if msg in [True, None]:
                    self.__invalid_changes.drop([path])
                else:
                    self.logger.debug("Failed to validate " +
                                      "'%s' with '%s'" % (path, value))
                    self.__invalid_changes.update({path: value})
                    raise exceptions.InvalidData(msg)

        # Is valid if no invalid_changes
        is_valid = self.__invalid_changes.is_empty()
        self.logger.debug("Valid yet? %s (%s)" %
                          (is_valid, self.__invalid_changes))
        self.on_valid(is_valid)

        return True
예제 #14
0
 def on_change(self, changes):
     if "console.path" in changes:
         if changes["console.path"] != '' and not os.path.exists(
                 changes["console.path"].split(',')[0]):
             raise exceptions.InvalidData("Console path must be a valid"
                                          "device or empty")