def __init__(self, client, parent=None): ScrollArea.__init__(self) self._modified = False self.drawGUIBasic() self.loaded_done = False parent.widgets["Network"] = self parent.addToInfoArea(self.tr("Network configuration interface enabled")) self.new_vlan = QAction(QIcon(":/icons/vlan"), tr("New VLAN"), self) self.new_vlan.setToolTip(tr("Create a VLAN interface")) self.new_bonding = QAction(QIcon(":/icons/New_bonding"), tr("New Bonding"), self) self.new_bonding.setToolTip(tr("Create a Bonding interface")) self.new_network = QAction(QIcon(":/icons/addnetwork"), tr("New Network"), self) self.new_network.setToolTip(tr("Add a network definition")) self.show_all = QAction(QIcon(":/icons/show_all_interface"), tr("Text Set Below"), self) self.show_all.setToolTip(tr("Show all interfaces")) self.is_showing_all = False self.toggleShowAll() self.connect(self.show_all, SIGNAL('triggered(bool)'), self.toggleShowAll) self.contextual_toolbar = ToolBar( ( self.new_network, self.new_vlan, self.new_bonding, self.show_all ), name=tr("Interfaces")) self.contextual_toolbar.setObjectName("Network toolbar") self.parent = parent self.client = client self.routes_model = None self.q_netobject = QNetObject.getInitializedInstance(self.client) self.q_netobject.registerCallbacks( self.canHandleModification, self.handleModification ) if self.q_netobject.netcfg is None: self.parent.addToInfoArea("Could not load network configuration", COLOR_ERROR) msg_area = MessageArea() msg_area.setMessage( tr("Network configuration interface disabled"), tr("Could not fetch network configuration from the appliance"), "critical" ) self.widget().layout().addWidget(msg_area) return self.resetConf() try: Protector(self.client.host, self) except: self.parent.addToInfoArea( tr( "Problem while loading a misconfiguration preventer: " "you will not be warned if you deconfigure the IP address " "to which EdenWall Administration Suite is connected.") )
class IfacesFrontend(ScrollArea): COMPONENT = 'network' LABEL = tr('Networks') REQUIREMENTS = ('network',) ICON = ':/icons/carte_reseau.png' def __init__(self, client, parent=None): ScrollArea.__init__(self) self._modified = False self.drawGUIBasic() self.loaded_done = False parent.widgets["Network"] = self parent.addToInfoArea(self.tr("Network configuration interface enabled")) self.new_vlan = QAction(QIcon(":/icons/vlan"), tr("New VLAN"), self) self.new_vlan.setToolTip(tr("Create a VLAN interface")) self.new_bonding = QAction(QIcon(":/icons/New_bonding"), tr("New Bonding"), self) self.new_bonding.setToolTip(tr("Create a Bonding interface")) self.new_network = QAction(QIcon(":/icons/addnetwork"), tr("New Network"), self) self.new_network.setToolTip(tr("Add a network definition")) self.show_all = QAction(QIcon(":/icons/show_all_interface"), tr("Text Set Below"), self) self.show_all.setToolTip(tr("Show all interfaces")) self.is_showing_all = False self.toggleShowAll() self.connect(self.show_all, SIGNAL('triggered(bool)'), self.toggleShowAll) self.contextual_toolbar = ToolBar( ( self.new_network, self.new_vlan, self.new_bonding, self.show_all ), name=tr("Interfaces")) self.contextual_toolbar.setObjectName("Network toolbar") self.parent = parent self.client = client self.routes_model = None self.q_netobject = QNetObject.getInitializedInstance(self.client) self.q_netobject.registerCallbacks( self.canHandleModification, self.handleModification ) if self.q_netobject.netcfg is None: self.parent.addToInfoArea("Could not load network configuration", COLOR_ERROR) msg_area = MessageArea() msg_area.setMessage( tr("Network configuration interface disabled"), tr("Could not fetch network configuration from the appliance"), "critical" ) self.widget().layout().addWidget(msg_area) return self.resetConf() try: Protector(self.client.host, self) except: self.parent.addToInfoArea( tr( "Problem while loading a misconfiguration preventer: " "you will not be warned if you deconfigure the IP address " "to which EdenWall Administration Suite is connected.") ) def canHandleModification(self): return True def handleModification(self): self.updateView() def drawGUIBasic(self): base = QWidget() box = QVBoxLayout(base) #panel title title = QFrame() title_layout = QVBoxLayout(title) title_label = QLabel("<h1>%s</h1>" % tr("Network configuration")) title_layout.addWidget(title_label) box.addWidget(title) self.active_part = QScrollArea() box.addWidget(self.active_part) self.setWidgetResizable(True) self.setWidget(base) def isModified(self): return self._modified def setModified(self, message): self._modified = bool(message) if self._modified: self.parent.setModified(self, True) if isinstance(message, (str, unicode)): self.parent.addToInfoArea(message) self.emit(SIGNAL("modified")) if message and self.isLoaded(): self.q_netobject.post_modify() def updateView(self): self.ifaces_list.updateView() def resetConf(self): self.ifaces_list = IfacesWidget(self.client, self.new_network, self.new_vlan, self.new_bonding, self) self.active_part.setWidget(self.ifaces_list) self.active_part.setWidgetResizable(True) self.connect(self.new_network, SIGNAL('triggered(bool)'), self.ifaces_list.new_network) self.new_vlan.setEnabled(self.ifaces_list.canCreateNetwork()) self.connect(self.new_vlan, SIGNAL('triggered(bool)'), self.ifaces_list.new_vlan) self.new_vlan.setEnabled(self.ifaces_list.canCreateVlan()) self.connect(self.new_bonding, SIGNAL('triggered(bool)'), self.ifaces_list.new_bonding) self.new_bonding.setEnabled(self.ifaces_list.canCreateBonding()) self.parent.writeAccessNeeded(self.new_network, self.new_vlan, self.new_bonding, self.show_all) self.connect(self.ifaces_list, SIGNAL("modified"), self.updateView) self.connect(self.ifaces_list, SIGNAL("modified"), self.msgArea) self._modified = False def msgArea(self, *args): if len(args) > 0: self.parent.addToInfoArea(args[0]) def toggleShowAll(self, *args): #toggling value) self.is_showing_all ^= True text = tr("Show All Interfaces") if self.is_showing_all else tr("Show Only Configurable Interfaces") self.show_all.setText(text) self.emit(SIGNAL('show all'), not self.is_showing_all) def checkConf(self): #Done internally pass def saveConf(self, message): self.ifaces_list.save(message) self.resetConf() def get_addresses(self): return list(self.q_netobject.netcfg.iterAddresses()) def loaded(self): self.loaded_done = True def isLoaded(self): return self.loaded_done @classmethod def get_priority(cls): return NETWORK_PRIORITY