Esempio n. 1
0
    def displayConfig(self):
        config = QHAObject.getInstance().hacfg
        if config.ha_type == PRIMARY:
            QMessageBox.warning(
                self,
                tr('High availability already configured'),
                tr('High availability status disallows editing the configuration'))
            return

        ha_wizard = ConfigWizard(self)
        ret = ha_wizard.exec_()
        if ret != QDialog.Accepted:
            return False

        qhaobject = QHAObject.getInstance()
        qhaobject.pre_modify()

        config = qhaobject.hacfg

        qnetobject = QNetObject.getInstance()
        qnetobject.pre_modify()
        net_cfg = qnetobject.netcfg

        old_type = config.ha_type
        new_config = ha_wizard.getData()
        config.ha_type = new_config.ha_type
        config.interface_id = new_config.interface_id
        config.interface_name = new_config.interface_name
        if config.ha_type in (PENDING_PRIMARY, PENDING_SECONDARY):
            iface = net_cfg.getIfaceByHardLabel(config.interface_id)
            configureHA(net_cfg, iface)
            network_modified = True
        elif config.ha_type != old_type:
            deconfigureHA(net_cfg)
            network_modified = True
            # XXX should not reconfigure now ?
        else:
            network_modified = False

        valid = qnetobject.post_modify()
        if not valid:
            qhaobject.revert()
        else:
            # FIXME: use post_modify() result?
            qhaobject.post_modify()
            self.setModified(True)
            if network_modified:
                network = self.mainwindow.getPage('network')
                network.setModified(True)
                dhcp = self.mainwindow.getPage('dhcp')
                dhcp.dhcp_widget.setModified(True)
                dhcp.dhcp_widget.fillView()

        self.setViewData()
        return True
Esempio n. 2
0
    def isValid(self):
        msg = QHAObject.getInstance().hacfg.isValidWithMsg()

        if msg is not None:
            self.error_message = msg[0] % msg[1:] # used by main_window
            return False
        else:
            return True
Esempio n. 3
0
    def validatePage(self):
        type_index, is_ok = self.field('type').toInt()
        ha_type = unicode(self.ha_type.itemData(type_index).toString())

        if QHAObject.getInstance().cfg.ha_type == SECONDARY and ha_type == ENOHA:
            #SECONDARY -> ENOHA is forbidden
            #when PRIMARY, this wizard is not even displayed
            QMessageBox.warning(self,
                tr('Invalid configuration'),
                tr(
                    "In order to fully deconfigure high availability, you "
                    "need to restore this appliance to factory defaults."
                )
                )
            return False

        if ha_type != ENOHA:
            net_cfg = QNetObject.getInstance().netcfg
            iface = self.interface.getInterface()
            iface_id = net_cfg.getHardLabel(iface)
            iface_name = iface.system_name
        else:
            iface_id = None
            iface_name = None
        config = HAConf(ha_type=ha_type, interface_id=iface_id, interface_name=iface_name)
        msg = config.isValidWithMsg()
        if msg is None:
            self.config = config
        else:
            QMessageBox.warning(self, tr('Invalid configuration'), msg[0] % msg[1:])
        if msg is not None:
            return False

        if ha_type != PENDING_PRIMARY:
            return True

        user_valid = QMessageBox.question(
                self,
                tr("Configuring primary appliance. Are you sure?"),
                "<div>%s<br/>%s<br/>%s<br/>%s</div>" % (
                    tr(
                        "After this configuration step, <b>you will not be able to "
                        "change the hostname anymore.</b>"
                      ),
                    tr(
                        "Abort now, or reject the saved configuration if you "
                        "need to change the hostname."
                      ),
                    tr("The hostname is currently <i><b>'%(HOSTNAME)s'</b></i>"
                      ) % {'HOSTNAME': QHostnameObject.getInstance().cfg.hostname},
                    tr("Do you want to continue?"),
                    ),
                QMessageBox.Yes | QMessageBox.Abort
                )

        return user_valid == QMessageBox.Yes
Esempio n. 4
0
    def __init__(self, parent):
        QWizardPage.__init__(self, parent)
        layout = QFormLayout(self)

        config = QHAObject.getInstance().hacfg

        self.setTitle(tr("High Availability Configuration"))

        self.ha_type = QComboBox() # primary / secondary
        self.ha_type.addItem(tr('Disabled'), QVariant(ENOHA))
        self.ha_type.addItem(tr('Primary'), QVariant(PENDING_PRIMARY))
        self.ha_type.addItem(tr('Secondary'), QVariant(PENDING_SECONDARY))
        index = self.ha_type.findData(QVariant(config.ha_type))
        self.ha_type.setCurrentIndex(index)

        layout.addRow(tr('Status of this cluster member:'), self.ha_type)
        self.registerField('type', self.ha_type)

        self.interface = InterfaceChoice(self.selectInterface, self)
        self.label_interface = QLabel(tr('Interface'))
        layout.addRow(self.label_interface, self.interface)
        self.registerField('interface', self.interface)

        self.connect(self.ha_type, SIGNAL('currentIndexChanged(int)'), self.toggleType)
        self.toggleType(index)

        if config.ha_type != ENOHA:
            message = tr("'%s' already configured as '%s'.") % (config.interface_id,
                config.ha_type)
            message += '<br />'
            message += tr("The configuration for this interface will be cleared.")

            warning_message = MessageArea()
            warning_message.setMessage(tr("Warning"), message,
                status=MessageArea.WARNING)
            layout.addRow(warning_message)
Esempio n. 5
0
 def setModified(self, is_modified):
     FullFeaturedScrollArea.setModified(self, is_modified)
     if is_modified:
         QHAObject.getInstance().post_modify()
Esempio n. 6
0
 def sendConfig(self, message):
     """
     Save HA config
     """
     serialized =  QHAObject.getInstance().hacfg.serialize()
     self.client.call('ha', 'configureHA', serialized, message)
Esempio n. 7
0
    def setViewData(self):
        config = QHAObject.getInstance().hacfg

        if "1.0" == self.version:
            raw_state = self.mainwindow.init_call('ha', 'getState')
            if raw_state is None:
                self.__disable()
                return
            self.link_state, self.ha_last_date, last_error = raw_state
            self.link_status_label.setText(self.LINK_STATE.get(self.link_state,
                tr('(unknown)')))
        else:
            raw_state = self.mainwindow.init_call('ha', 'getFullState')
            if raw_state is None:
                self.__disable()
                return
            node_state = raw_state['node_state']
            self.link_state = raw_state['link_state']
            self.ha_last_date = raw_state['seen_other']
            last_error = raw_state['last_error']

            self.link_status_label.setText(self.LINK_STATE.get(self.link_state,
                tr('(unknown)')))
            self.node_status_label.setText(self.NODE_STATE.get(node_state,
                tr('(unknown)')))

        # TEMP : use compatibility instead
        try:
            try:
                if raw_state.get('link_state', None) == CONNECTED:
                    self.join.setEnabled(False)
            except Exception:
                if isinstance(raw_state, list) and len(raw_state) > 0:
                    if raw_state[0] == CONNECTED:
                        self.join.setEnabled(False)
        except TypeError:
            pass

        ha_type = self.__ha_type()

        self.type_label.setText(
            HAConfigFrontend.STATE_DESCRIPTIONS[ha_type]
            )

        if ha_type != ENOHA:
            if self.ha_last_date not in (0, None):
                fmt = '%Y-%m-%d %H:%M:%S'
                seen = time.strftime(fmt, time.localtime(self.ha_last_date))
                self.activity_label.setText(unicode(seen))
            if config.interface_id is not None:
                qnetobject = QNetObject.getInstance()
                iface = qnetobject.netcfg.getIfaceByHardLabel(config.interface_id)
                self.interface_label.setText(iface.fullName())
            try:
                last_error = self.client.call('ha', 'getLastError')
                self.show_last_error(last_error)
            except Exception:
                self.hide_last_error()
        else:
            self.interface_label.clear()
            self.activity_label.clear()
            self.hide_last_error()
        if ha_type == PRIMARY:
            async = self.client.async()
            async.call('ha', 'getMissingUpgradeNums',
                       callback=self._get_missing_upgrade_nums,
                       errback=self.writeError)
        self.mainwindow.writeAccessNeeded(self.join)
        if self.join.isEnabled():
            self.join.setEnabled(PENDING_PRIMARY == ha_type)
Esempio n. 8
0
 def __ha_type(self):
     config = QHAObject.getInstance().cfg
     if config is None:
         return ENOHA
     return config.ha_type