X-Git-Url: http://git.onelab.eu/?p=sface.git;a=blobdiff_plain;f=sface%2Fscreens%2Fmainscreen.py;h=3c1be13c6ea06a89d488ec2e363b073647dcf10b;hp=c2a2118c2a4dacc701596089eb2d0f6570310fa7;hb=b4479edcd8022bc11805758a575f7ca96dcdfc04;hpb=dc5a4a16b0819bc27efd1f77d632a76463db82c0 diff --git a/sface/screens/mainscreen.py b/sface/screens/mainscreen.py index c2a2118..3c1be13 100644 --- a/sface/screens/mainscreen.py +++ b/sface/screens/mainscreen.py @@ -1,11 +1,11 @@ import datetime import os +import urlparse from PyQt4.QtCore import * from PyQt4.QtGui import * #from sfa.util.rspecHelper import RSpec -from sfa.rspecs.rspec_parser import parse_rspec from sface.config import config from sface.sfirenew import RenewWindow from sface.sfiprocess import SfiProcess @@ -24,6 +24,10 @@ tag_status = { "in": "Already Set", "add": "To be Added", "remove": "To be Removed"} +color_status = { "in": QColor.fromRgb(0, 250, 250), + "add": QColor.fromRgb(0, 250, 0), + "remove": QColor.fromRgb(250, 0, 0) } + default_tags = "Default tags" settable_tags = ['delegations', 'initscript'] @@ -189,44 +193,20 @@ class NodeNameDelegate(QStyledItemDelegate): painter.fillRect(option.rect, option.palette.color(QPalette.Active, QPalette.Highlight)) if itemType(index) == "node": - if status_data == node_status['in']: # already in the slice - painter.fillPath(path, QColor.fromRgb(0, 250, 250)) - painter.setPen(QColor.fromRgb(0, 0, 0)) - painter.drawText(rect, 0, QString(data)) - - elif status_data == node_status['add']: # newly added to the slice - painter.fillPath(path, QColor.fromRgb(0, 250, 0)) - painter.setPen(QColor.fromRgb(0, 0, 0)) - painter.drawText(rect, 0, QString(data)) - - elif status_data == node_status['remove']: # removed from the slice - painter.fillPath(path, QColor.fromRgb(250, 0, 0)) - painter.setPen(QColor.fromRgb(0, 0, 0)) - painter.drawText(rect, 0, QString(data)) + for x in node_status.keys(): + if (node_status[x] == status_data) and (x in color_status): + painter.fillPath(path, color_status[x]) - else: - painter.setPen(QColor.fromRgb(0, 0, 0)) - painter.drawText(rect, 0, QString(data)) + painter.setPen(QColor.fromRgb(0, 0, 0)) + painter.drawText(rect, 0, QString(data)) else: - if status_data == tag_status['in']: # already in the slice - painter.fillPath(path, QColor.fromRgb(0, 250, 250)) - painter.setPen(QColor.fromRgb(0, 0, 0)) - painter.drawText(rect, 0, QString(data)) + for x in tag_status.keys(): + if (tag_status[x] == status_data) and (x in color_status): + painter.fillPath(path, color_status[x]) - elif status_data == tag_status['add']: # newly added to the slice - painter.fillPath(path, QColor.fromRgb(0, 250, 0)) - painter.setPen(QColor.fromRgb(0, 0, 0)) - painter.drawText(rect, 0, QString(data)) - - elif status_data == tag_status['remove']: # removed from the slice - painter.fillPath(path, QColor.fromRgb(250, 0, 0)) - painter.setPen(QColor.fromRgb(0, 0, 0)) - painter.drawText(rect, 0, QString(data)) - - else: - painter.setPen(QColor.fromRgb(0, 0, 0)) - painter.drawText(rect, 0, QString(data)) + painter.setPen(QColor.fromRgb(0, 0, 0)) + painter.drawText(rect, 0, QString(data)) painter.restore() @@ -358,7 +338,7 @@ class SliceWidget(QWidget): self.connect(refresh, SIGNAL('clicked()'), self.refresh) self.connect(renew, SIGNAL('clicked()'), self.renew) - self.connect(submit, SIGNAL('clicked()'), self.submit) + self.connect(submit, SIGNAL('clicked()'), self.submit_pg_compat) self.connect(searchbox, SIGNAL('textChanged(QString)'), self.search) self.connect(filterbox, SIGNAL('currentIndexChanged(QString)'), self.filter) self.connect(self.nodeView, SIGNAL('hostnameClicked(QString)'), @@ -375,21 +355,29 @@ class SliceWidget(QWidget): else: self.setStatus("Slice submit failed: %s" % (faultString)) - # no need to do that anymore - # QTimer.singleShot(1000, self.refresh) self.updateView() self.parent().signalAll("rspecUpdated") def refreshResourcesFinished(self): self.disconnect(self.process, SIGNAL('finished()'), self.refreshResourcesFinished) - self.setStatus("Refreshing slice RSpec.") - self.connect(self.process, SIGNAL('finished()'), self.refreshRSpecFinished) - self.process.retrieveRspec() + faultString = self.process.getFaultString() + if not faultString: + self.setStatus("Refreshing slice RSpec.") + self.connect(self.process, SIGNAL('finished()'), self.refreshRSpecFinished) + self.process.retrieveRspec() + else: + self.setStatus("Resources refresh failed: %s" % (faultString)) def refreshRSpecFinished(self): self.disconnect(self.process, SIGNAL('finished()'), self.refreshRSpecFinished) - self.setStatus("Slice data refreshed.", timeout=5000) + + faultString = self.process.getFaultString() + if not faultString: + self.setStatus("Slice data refreshed.", timeout=5000) + else: + self.setStatus("Slice refresh failed: %s" % (faultString)) + self.updateView() self.parent().signalAll("rspecUpdated") @@ -410,10 +398,10 @@ class SliceWidget(QWidget): def itemStatus(self, item): statusItem = item.parent().child(item.row(), MEMBERSHIP_STATUS_COLUMN) - return statusItem.data(Qt.DisplayRole).toString() + return str(statusItem.data(Qt.DisplayRole).toString()) def itemText(self, item): - return item.data(Qt.DisplayRole).toString() + return str(item.data(Qt.DisplayRole).toString()) # Recursively walk the tree, making changes to the RSpec def process_subtree(self, rspec, resources, item, depth = 0): @@ -435,11 +423,11 @@ class SliceWidget(QWidget): print "Error: Failed to find %s in resources rspec" % hostname else: rspec.merge_node(resource_node, testbed) - rspec.add_slivers(str(hostname), testbed) + rspec.add_slivers([{"hostname": str(hostname)}], testbed) change = True elif status == node_status['remove']: print "Remove hostname: %s" % hostname - rspec.remove_slivers(str(hostname), testbed) + rspec.remove_slivers([{"hostname": str(hostname)}], testbed) change = True elif depth == 3: # Tag tag, value = self.itemText(item).split(": ") @@ -450,14 +438,14 @@ class SliceWidget(QWidget): testbed = self.itemText(item.parent().parent()) if status == tag_status['add']: print "Add tag to (%s, %s): %s/%s " % (testbed, node, tag, value) - if node.startsWith(default_tags): + if node.startswith(default_tags): rspec.add_default_sliver_attribute(tag, value, testbed) else: rspec.add_sliver_attribute(node, tag, value, testbed) change = True elif status == tag_status['remove']: print "Remove tag from (%s, %s): %s/%s " % (testbed, node, tag, value) - if node.startsWith(default_tags): + if node.startswith(default_tags): rspec.remove_default_sliver_attribute(tag, value, testbed) else: rspec.remove_sliver_attribute(node, tag, value, testbed) @@ -482,11 +470,120 @@ class SliceWidget(QWidget): self.setStatus("No change in slice data. Not submitting!", timeout=3000) return - self.connect(self.process, SIGNAL('finished()'), self.submitFinished) + # Several aggregates have issues with the section in the + # rspec, so make sure it's not there. + stats_elems = rspec.xml.xpath("//statistics") + if len(stats_elems)>0: + stats_elem = stats_elems[0] + parent = stats_elem.xpath("..")[0] + parent.remove(stats_elem) + self.connect(self.process, SIGNAL('finished()'), self.submitFinished) self.process.applyRSpec(rspec) self.setStatus("Sending slice data (RSpec). This will take some time...") + # ProtoGENI-compatible submit. Contact each aggregate individually rather + # than using the slice manager. + # This code will be removed when ProtoGENI slicemanager is patched. + def submit_pg_compat(self): + if self.checkRunningProcess(): + return + + rspec = SfiData().getSliceRSpec() + resources = SfiData().getResourcesRSpec() + change = self.process_subtree(rspec, resources, self.nodeModel.invisibleRootItem()) + + if not change: + self.setStatus("No change in slice data. Not submitting!", timeout=3000) + return + + # Several aggregates have issues with the section in the + # rspec, so make sure it's not there. + stats_elems = rspec.xml.xpath("//statistics") + if len(stats_elems)>0: + stats_elem = stats_elems[0] + parent = stats_elem.xpath("..")[0] + parent.remove(stats_elem) + + self.submit_aggSuccessCount = 0 + self.submit_aggFailCount = 0 + self.submit_rspec = rspec + self.connect(self.process, SIGNAL('finished()'), self.getVersionFinished) + self.process.getSliceMgrVersion() + self.setStatus("Getting aggregate directory...") + + def getVersionFinished(self): + self.disconnect(self.process, SIGNAL('finished()'), self.getVersionFinished) + + faultString = self.process.getFaultString() + if not faultString: + peers = SfiData().getSliceMgrVersion()["peers"] + self.submit_aggs = [(key, peers[key]) for key in peers.keys()] + self.delete_aggs = [(key, peers[key]) for key in peers.keys() if key.startswith("emulab")] + str = "Successfully retrieved agg list. " + #self.submitNextAgg(str) + self.deleteNextAgg(str) + else: + self.setStatus("getSliceMgrVersion failed: %s" % (faultString)) + + def deleteNextAgg(self, statusStr=""): + if (self.delete_aggs == []): + self.submitNextAgg(statusStr) + return + + self.delete_agg = self.delete_aggs.pop() + + urlParts = urlparse.urlsplit(self.delete_agg[1]) + amPort = urlParts.port + amAddr = urlParts.hostname+urlParts.path + + self.setStatus(statusStr + "Deleting slivers on %s..." % (self.delete_agg[0])) + + self.connect(self.process, SIGNAL('finished()'), self.deleteNextAggFinished) + self.process.deleteSlivers(aggAddr = amAddr, aggPort = amPort) + + def submitNextAgg(self, statusStr=""): + if (self.submit_aggs == []): + self.setStatus(statusStr + "Finished submitting. %d/%d aggs succeeded." % + (self.submit_aggSuccessCount,self.submit_aggSuccessCount+self.submit_aggFailCount)) + QTimer.singleShot(2500, self.refresh) + return + + self.submit_agg = self.submit_aggs.pop() + + urlParts = urlparse.urlsplit(self.submit_agg[1]) + amPort = urlParts.port + amAddr = urlParts.hostname+urlParts.path + + self.setStatus(statusStr + "Submitting to %s..." % (self.submit_agg[0])) + + self.connect(self.process, SIGNAL('finished()'), self.submitNextAggFinished) + self.process.applyRSpec(self.submit_rspec, aggAddr = amAddr, aggPort = amPort, saveObtained=False) + + def submitNextAggFinished(self): + self.disconnect(self.process, SIGNAL('finished()'), self.submitNextAggFinished) + + faultString = self.process.getFaultString() + if not faultString: + self.submit_aggSuccessCount+=1 + str = "Succeeded on %s. " % (self.submit_agg[0]) + else: + self.submit_aggFailCount+=1 + str = "Failed on %s. " % (self.submit_agg[0]) # , faultString) + + self.submitNextAgg(str) + + def deleteNextAggFinished(self): + self.disconnect(self.process, SIGNAL('finished()'), self.deleteNextAggFinished) + + faultString = self.process.getFaultString() + if not faultString: + str = "Succeeded deleteslivers on %s. " % (self.delete_agg[0]) + else: + str = "Failed deleteslivers on %s. " % (self.delete_agg[0]) # , faultString) + + self.deleteNextAgg(str) + def renew(self): dlg = RenewWindow(parent=self) dlg.exec_()