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)
class ConfigPage(QWizardPage): 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) def selectInterface(self, interface): return interface.canReserve() or interface.hasHA() def toggleType(self, index): selected_type = self.ha_type.itemData(index) self.interface.setVisible(selected_type.toString() != ENOHA) self.label_interface.setVisible(selected_type.toString() != ENOHA) 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 def getData(self): return self.config