def IOS_images(self): """ Load IOS images settings from config file """ # Loading IOS images conf basegroup = "IOS.images" c = ConfDB() c.beginGroup(basegroup) childGroups = c.childGroups() c.endGroup() for img_num in childGroups: cgroup = basegroup + '/' + img_num img_filename = c.get(cgroup + "/filename", unicode('')) img_hypervisors = c.get(cgroup + "/hypervisors", unicode('')).split() if img_filename == '': continue if len(img_hypervisors) == 0: #if globals.GApp.systconf['dynamips'].HypervisorManager_binding == '0.0.0.0': # img_ref = "127.0.0.1:" + img_filename #else: img_ref = globals.GApp.systconf[ 'dynamips'].HypervisorManager_binding + ":" + img_filename else: if len(img_hypervisors) > 1: img_ref = 'load-balanced-on-external-hypervisors:' + img_filename else: (host, port) = img_hypervisors[0].rsplit(':', 1) img_ref = host + ":" + img_filename conf = iosImageConf() conf.id = int(img_num) conf.filename = img_filename conf.baseconfig = unicode( c.get(cgroup + "/baseconfig", 'baseconfig.txt')) conf.platform = str(c.get(cgroup + "/platform", '')) conf.chassis = str(c.get(cgroup + "/chassis", '')) conf.idlepc = str(c.get(cgroup + "/idlepc", '')) conf.idlemax = int(c.get(cgroup + "/idlemax", 1500)) conf.idlesleep = int(c.get(cgroup + "/idlesleep", 30)) conf.default_ram = int(c.get(cgroup + "/default_ram", 0)) conf.default = c.value(cgroup + "/default", QtCore.QVariant(False)).toBool() conf.hypervisors = img_hypervisors globals.GApp.iosimages[img_ref] = conf if conf.id >= globals.GApp.iosimages_ids: globals.GApp.iosimages_ids = conf.id + 1
def IOS_images(self): """ Load IOS images settings from config file """ # Loading IOS images conf basegroup = "IOS.images" c = ConfDB() c.beginGroup(basegroup) childGroups = c.childGroups() c.endGroup() for img_num in childGroups: cgroup = basegroup + '/' + img_num img_filename = c.get(cgroup + "/filename", unicode('')) #установка IP адреса гипервизора dynamips из myfile.py img_hypervisors = unicode(dynamips_server).split(",") if img_filename == '': continue if len(img_hypervisors) == 0: img_ref = globals.GApp.systconf['dynamips'].HypervisorManager_binding + ":" + img_filename else: if len(img_hypervisors) > 1: img_ref = 'load-balanced-on-external-hypervisors:' + img_filename else: (host, port) = img_hypervisors[0].rsplit(':', 1) img_ref = host + ":" + img_filename conf = iosImageConf() conf.id = int(img_num) conf.filename = img_filename conf.baseconfig = unicode(c.get(cgroup + "/baseconfig", 'baseconfig.txt')) conf.platform = str(c.get(cgroup + "/platform", '')) conf.chassis = str(c.get(cgroup + "/chassis", '')) conf.idlepc = str(c.get(cgroup + "/idlepc", '')) conf.default_ram = int(c.get(cgroup + "/default_ram", 0)) conf.default = c.value(cgroup + "/default", QtCore.QVariant(False)).toBool() conf.hypervisors = img_hypervisors globals.GApp.iosimages[img_ref] = conf if conf.id >= globals.GApp.iosimages_ids: globals.GApp.iosimages_ids = conf.id + 1
def slotSaveIOS(self): """ Save an IOS image and all his settings """ imagename = unicode(self.lineEditIOSImage.text(), 'utf-8', errors='replace') if not imagename: return idlepc = str(self.lineEditIdlePC.text()).strip() if idlepc and not re.search(r"""^0x[0-9a-fA-F]{8}$""", idlepc): QtGui.QMessageBox.critical(self, translate("IOSDialog", "IOS Configuration"), translate("IOSDialog", "IDLE PC not valid (format required: 0xhhhhhhhh)")) return if not idlepc: self.label_IdlePCWarning.setText('<font color="red">' + translate("IOSDialog", "Warning: IDLE PC will have to be configured! <a href='http://www.gns3.net/gns3-simplest-topology' >Find out why and how</a>") + '</font>') else: self.label_IdlePCWarning.setText('') hypervisors = [] if self.checkBoxIntegratedHypervisor.checkState() == QtCore.Qt.Checked: # external hypervisor, don't use the hypervisor manager items = self.listWidgetHypervisors.selectedItems() if len(items) == 0: QtGui.QMessageBox.warning(self, translate("IOSDialog", "IOS Configuration"), translate("IOSDialog", "No hypervisor selected, use the local hypervisor")) self.checkBoxIntegratedHypervisor.setCheckState(QtCore.Qt.Unchecked) imagekey = globals.GApp.systconf['dynamips'].HypervisorManager_binding + ':' + imagename else: # get the selected hypervisor if len(items) > 1: for item in items: selected_hypervisor = unicode(item.text(), 'utf-8', errors='replace') hypervisor = globals.GApp.hypervisors[selected_hypervisor] hypervisors.append(hypervisor.host + ':' + str(hypervisor.port)) imagekey = 'load-balanced-on-external-hypervisors:' + imagename if globals.GApp.iosimages.has_key(globals.GApp.systconf['dynamips'].HypervisorManager_binding + ':' + imagename): del globals.GApp.iosimages[globals.GApp.systconf['dynamips'].HypervisorManager_binding + ':' + imagename] else: selected_hypervisor = unicode(items[0].text(), 'utf-8', errors='replace') hypervisor = globals.GApp.hypervisors[selected_hypervisor] hypervisors.append(hypervisor.host + ':' + str(hypervisor.port)) imagekey = hypervisor.host + ':' + imagename if globals.GApp.iosimages.has_key('load-balanced-on-external-hypervisors:' + imagename): del globals.GApp.iosimages['load-balanced-on-external-hypervisors:' + imagename] else: imagekey = globals.GApp.systconf['dynamips'].HypervisorManager_binding + ':' + imagename if globals.GApp.iosimages.has_key('load-balanced-on-external-hypervisors:' + imagename): del globals.GApp.iosimages['load-balanced-on-external-hypervisors:' + imagename] if globals.GApp.iosimages.has_key(imagekey): # update an already existing IOS image item_to_update = self.treeWidgetIOSimages.findItems(imagekey, QtCore.Qt.MatchFixedString)[0] item_to_update.setText(1, self.comboBoxChassis.currentText()) else: # else create a new entry item = QtGui.QTreeWidgetItem(self.treeWidgetIOSimages) # image name column item.setText(0, imagekey) # chassis column item.setText(1, self.comboBoxChassis.currentText()) self.treeWidgetIOSimages.setCurrentItem(item) # save settings if globals.GApp.iosimages.has_key(imagekey): conf = globals.GApp.iosimages[imagekey] else: conf = iosImageConf() conf.id = globals.GApp.iosimages_ids globals.GApp.iosimages_ids += 1 conf.filename = imagename conf.baseconfig = unicode(self.lineEditBaseConfig.text(), 'utf-8', errors='replace') conf.platform = str(self.comboBoxPlatform.currentText()) conf.chassis = str(self.comboBoxChassis.currentText()) conf.idlepc = idlepc conf.idlemax = self.spinBoxIdlemax.value() conf.idlesleep = self.spinBoxIdlesleep.value() conf.hypervisors = hypervisors default_ram = self.spinBoxDefaultRAM.value() if default_ram == 0 and DEFAULT_RAM.has_key(conf.platform): conf.default_ram = DEFAULT_RAM[conf.platform] else: conf.default_ram = default_ram default_platform = True if self.checkBoxDefaultImage.checkState() == QtCore.Qt.Checked: for image in globals.GApp.iosimages: image_conf = globals.GApp.iosimages[image] if imagekey != image and image_conf.platform == conf.platform and image_conf.default: QtGui.QMessageBox.warning(self, translate("IOSDialog", "IOS Configuration"), translate("IOSDialog", "There is already a default image for this platform")) self.checkBoxDefaultImage.setCheckState(QtCore.Qt.Unchecked) default_platform = False else: default_platform = False if default_platform: conf.default = True else: conf.default = False globals.GApp.iosimages[imagekey] = conf self.treeWidgetIOSimages.update() self.treeWidgetIOSimages.resizeColumnToContents(0) self.treeWidgetIOSimages.clear() # reload IOS for name in globals.GApp.iosimages.keys(): image = globals.GApp.iosimages[name] item = QtGui.QTreeWidgetItem(self.treeWidgetIOSimages) # image name column item.setText(0, name) # chassis column item.setText(1, image.chassis)