def __init__(self, edenwall_ip, parent_widget): QObject.__init__(self) if isinstance(edenwall_ip, (str, unicode, int)): try: edenwall_ip = IP(edenwall_ip) except ValueError: edenwall_ip = gethostbyname(edenwall_ip) #not checking for error because we have been to resolve the #hostname a minute ago when we started EAS edenwall_ip = IP(edenwall_ip) if not isinstance(edenwall_ip, IP): raise TypeError("Need an IP descriptor or an IPy.IP") self.__edenwall_ip = edenwall_ip self.__parent_widget = parent_widget self.__qnetobject = QNetObject.getInstance() self.__qnetobject.registerCallbacks( self.acceptNetworkChange, self.handleNetworkChange ) self.connect( self.__qnetobject, SIGNAL('reset'), self.reset ) self.__danger_state_known = False self.reset()
def getInterface(self): """ return current selected interface """ index = self.currentIndex() items = self.itemData(index).toInt() # net_id, ok return QNetObject.getInstance().netcfg.getInterfaceByUniqueID(items[0])
def __init__(self, modelname=MODEL_NETWORKS_EXCL_HA, parent=None): QComboBox.__init__(self, parent) self.qnetobject = QNetObject.getInstance() self.__modelname = modelname self.setModel( self.qnetobject.models[self.__modelname] )
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 __init__(self, chooseInterface, parent): QComboBox.__init__(self, parent) selectable = list() for interface in QNetObject.getInstance().netcfg.iterInterfaces(): if not callable(chooseInterface) or chooseInterface(interface): selectable.append(("%s" % interface.fullName(), QVariant(interface.unique_id))) selectable.sort() for item in selectable: self.addItem(*item)
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
def isValid(self): global_ok = True messages = [] validators = ( self._validNet, self._validNetIp, self._validIpAddrs, self._validCoherence ) for validate in validators: ok, message = validate() global_ok &= ok if message is not None: messages.append(unicode(message)) if not global_ok: break if global_ok: title = self.tr("Information") message = tr("Valid settings") status = MessageArea.INFO else: title = self.tr("Input error") message = '<ul>%s</ul>' % "".join('<li>%s</li>' % message for message in messages) status = MessageArea.WARNING if global_ok: # search if another interface have a net which overlaps netcfg = QNetObject.getInstance().netcfg current_net = self.net_ip.value() for iface in netcfg.iterInterfaces(): if iface.unique_id != self.interface.unique_id: ret, net = self.isNetInInterface(iface, current_net) if ret: global_ok = False message = tr("Interface '%s' has a '%s' network which overlaps '%s'") % (iface.fullName(), net.strNormal(), current_net.strNormal()) status = MessageArea.WARNING self.message_area.message.setWordWrap(True) break self.message_area.setMessage( title, message, status=status ) return global_ok
def __init__(self, iface, parent=None): QWizardPage.__init__(self, parent) self.setTitle(tr("Edit interface parameters")) self.setSubTitle(tr("Interface name")) self.q_netobject = QNetObject.getInstance() layout = QVBoxLayout(self) if isinstance(iface, Vlan): self.editor = VlanEditor(vlan=iface) self.setPixmap(QWizard.LogoPixmap, QPixmap(":/icons/vlan")) elif isinstance(iface, Bonding): self.editor = BondingEditor(bonding=iface) elif isinstance(iface, Ethernet): self.editor = EthernetEditor(iface) self.validatePage = self.editor.accept layout.addWidget(self.editor) self.connect(self.editor, SIGNAL("modified"), self.resendModified)
def __candidates(self): candidates = list( QNetObject.getInstance().netcfg.iterNetworkables() ) candidates.sort() return candidates
def _done(self, *args): self.emit(SIGNAL('done'), self) QNetObject.getInstance().post_modify()
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)