X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sface%2Fscreens%2Fmainscreen.py;h=0452161a5ba1ff2e34834835f2a286f5a3e62ad8;hb=83a8227f531598385af1b6b9e3fa8ef56904b32b;hp=b20ae516c414e0e70d5fe25d226e503c4662f617;hpb=9be93c1e7a8a2a4e0cd1c890e9ebe2acf6030787;p=sface.git
diff --git a/sface/screens/mainscreen.py b/sface/screens/mainscreen.py
index b20ae51..0452161 100644
--- a/sface/screens/mainscreen.py
+++ b/sface/screens/mainscreen.py
@@ -7,9 +7,10 @@ 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 SfiRenewer
+from sface.sfirenew import RenewWindow
from sface.sfiprocess import SfiProcess
from sface.screens.sfascreen import SfaScreen
+from sface.sfidata import SfiData
already_in_nodes = []
@@ -23,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']
@@ -31,6 +36,9 @@ NODE_STATUS_COLUMN = 1
MEMBERSHIP_STATUS_COLUMN = 2
KIND_COLUMN = 3
+# maximum length of a name to display before clipping
+NAME_MAX_LEN = 48
+
def itemType(index):
if index.parent().parent().isValid():
return "tag"
@@ -51,7 +59,16 @@ class NodeView(QTreeView):
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.setToolTip("Double click on a row to change its status. Right click on a host to add a tag.")
+ def keyPressEvent(self, event):
+ if (event.key() == Qt.Key_Space):
+ self.toggleSelection()
+ else:
+ QTreeView.keyPressEvent(self, event)
+
def mouseDoubleClickEvent(self, event):
+ self.toggleSelection()
+
+ def toggleSelection(self):
index = self.currentIndex()
model = index.model()
status_index = model.index(index.row(), MEMBERSHIP_STATUS_COLUMN, index.parent())
@@ -124,7 +141,7 @@ class NodeView(QTreeView):
tagstring = QString("%s: %s" % (tagname, value))
tagItem = QStandardItem(tagstring)
status = QStandardItem(QString(tag_status['add']))
- nodeItem.appendRow([tagItem, status])
+ nodeItem.appendRow([tagItem, QStandardItem(QString("")), status])
elif status_data in (node_status['out'], node_status['remove']):
QMessageBox.warning(self, "Not selected", "Can only add tags to selected nodes")
@@ -144,15 +161,21 @@ class NodeNameDelegate(QStyledItemDelegate):
def __init__(self, parent):
QStyledItemDelegate.__init__(self, parent)
+ def displayText(self, value, locale):
+ data = str(QStyledItemDelegate.displayText(self, value, locale))
+ if (len(data)>NAME_MAX_LEN):
+ data = data[:(NAME_MAX_LEN-3)] + "..."
+ return QString(data)
+
def paint(self, painter, option, index):
model = index.model()
+ data = str(self.displayText(index.data(), QLocale()))
status_index = model.index(index.row(), MEMBERSHIP_STATUS_COLUMN, index.parent())
status_data = status_index.data().toString()
fm = QFontMetrics(option.font)
rect = QRect(option.rect)
- data = index.data().toString()
rect.setHeight(rect.height() - 2)
rect.setWidth(fm.width(QString(data)) + 6)
rect.setX(rect.x() + 5)
@@ -170,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))
+ for x in node_status.keys():
+ if (node_status[x] == status_data) and (x in color_status):
+ painter.fillPath(path, color_status[x])
- 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))
-
- 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()
@@ -348,20 +347,39 @@ class SliceWidget(QWidget):
self.updateView()
def submitFinished(self):
- self.setStatus("Slice data submitted.")
- QTimer.singleShot(1000, self.refresh)
+ self.disconnect(self.process, SIGNAL('finished()'), self.submitFinished)
+
+ faultString = self.process.getFaultString()
+ if not faultString:
+ self.setStatus("Slice data submitted.")
+ else:
+ self.setStatus("Slice submit failed: %s" % (faultString))
- def refreshFinished(self):
- self.setStatus("Slice data refreshed.", timeout=5000)
self.updateView()
self.parent().signalAll("rspecUpdated")
- def readSliceRSpec(self):
- rspec_file = config.getSliceRSpecFile()
- if os.path.exists(rspec_file):
- xml = open(rspec_file).read()
- return parse_rspec(xml)
- return None
+ def refreshResourcesFinished(self):
+ self.disconnect(self.process, SIGNAL('finished()'), self.refreshResourcesFinished)
+
+ 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)
+
+ 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")
def setStatus(self, msg, timeout=None):
self.parent().setStatus(msg, timeout)
@@ -380,13 +398,13 @@ 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, item, depth = 0):
+ def process_subtree(self, rspec, resources, item, depth = 0):
change = False
model = self.nodeModel
@@ -398,8 +416,15 @@ class SliceWidget(QWidget):
status = self.itemStatus(item)
if status == node_status['add']:
print "Add hostname: %s" % hostname
- rspec.add_slivers(str(hostname), testbed)
- change = True
+
+ resource_node = resources.get_node_element(hostname)
+
+ if resource_node==None:
+ print "Error: Failed to find %s in resources rspec" % hostname
+ else:
+ rspec.merge_node(resource_node, testbed)
+ rspec.add_slivers(str(hostname), testbed)
+ change = True
elif status == node_status['remove']:
print "Remove hostname: %s" % hostname
rspec.remove_slivers(str(hostname), testbed)
@@ -428,7 +453,7 @@ class SliceWidget(QWidget):
children = item.rowCount()
for row in range(0, children):
- status = self.process_subtree(rspec, item.child(row), depth + 1)
+ status = self.process_subtree(rspec, resources, item.child(row), depth + 1)
change = change or status
return change
@@ -437,14 +462,14 @@ class SliceWidget(QWidget):
if self.checkRunningProcess():
return
- rspec = self.readSliceRSpec()
- change = self.process_subtree(rspec, self.nodeModel.invisibleRootItem())
+ 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
- self.disconnect(self.process, SIGNAL('finished()'), self.refreshFinished)
self.connect(self.process, SIGNAL('finished()'), self.submitFinished)
self.process.applyRSpec(rspec)
@@ -452,19 +477,7 @@ class SliceWidget(QWidget):
def renew(self):
dlg = RenewWindow(parent=self)
- if (dlg.exec_() == QDialog.Accepted):
- self.setStatus("Renewing Slice.")
-
- self.renewProcess = SfiRenewer(config.getSlice(), dlg.get_new_expiration(), self)
- self.connect(self.renewProcess, SIGNAL('finished()'), self.renewFinished)
-
- def renewFinished(self):
- if self.renewProcess.statusMsg:
- self.setStatus("Renew " + self.renewProcess.status + ": " + self.renewProcess.statusMsg)
- else:
- self.setStatus("Renew " + self.renewProcess.status)
- self.disconnect(self.renewProcess, SIGNAL('finished()'), self.renewFinished)
- self.renewProcess = None
+ dlg.exec_()
def refresh(self):
if not config.getSlice():
@@ -475,11 +488,10 @@ class SliceWidget(QWidget):
self.setStatus("There is already a process running. Please wait.")
return
- self.disconnect(self.process, SIGNAL('finished()'), self.submitFinished)
- self.connect(self.process, SIGNAL('finished()'), self.refreshFinished)
+ self.connect(self.process, SIGNAL('finished()'), self.refreshResourcesFinished)
- self.process.getRSpecFromSM()
- self.setStatus("Refreshing slice data. This will take some time...")
+ self.process.retrieveResources()
+ self.setStatus("Refreshing resources. This will take some time...")
def updateView(self):
global already_in_nodes
@@ -487,20 +499,27 @@ class SliceWidget(QWidget):
self.network_names = []
self.nodeModel.clear()
- rspec = self.readSliceRSpec()
+ rspec = SfiData().getSliceRSpec()
if not rspec:
return None
+ resources = SfiData().getResourcesRSpec()
+ if not resources:
+ return None
+
rootItem = self.nodeModel.invisibleRootItem()
- #networks = sorted(rspec.get_network_list())
networks = rspec.get_networks()
+
+ for network in resources.get_networks():
+ if not network in networks:
+ networks.append(network)
+
for network in networks:
self.network_names.append(network)
- #all_nodes = rspec.get_node_list(network)
- #sliver_nodes = rspec.get_sliver_list(network)
- all_nodes = rspec.get_nodes(network)
+ all_nodes = resources.get_nodes(network)
sliver_nodes = rspec.get_nodes_with_slivers(network)
+
available_nodes = [ node for node in all_nodes if node not in sliver_nodes ]
networkItem = QStandardItem(QString(network))
@@ -539,7 +558,7 @@ class SliceWidget(QWidget):
for node in available_nodes:
nodeItem = QStandardItem(QString(node))
statusItem = QStandardItem(QString(node_status['out']))
- nodeStatus = QStandardItem(QString(rspec.get_node_element(node, network).attrib.get("boot_state","")))
+ nodeStatus = QStandardItem(QString(resources.get_node_element(node, network).attrib.get("boot_state","")))
networkItem.appendRow([nodeItem, nodeStatus, statusItem, QStandardItem(QString("node"))])
self.filterModel.setSourceModel(self.nodeModel)
@@ -562,44 +581,6 @@ class SliceWidget(QWidget):
def nodeSelectionChanged(self, hostname):
self.parent().nodeSelectionChanged(hostname)
-class RenewWindow(QDialog):
- def __init__(self, parent=None):
- super(RenewWindow, self).__init__(parent)
- self.setWindowTitle("Renew Slivers")
-
- self.duration = QComboBox()
-
- self.expirations = []
-
- durations = ( (1, "One Week"), (2, "Two Weeks"), (3, "Three Weeks"), (4, "One Month") )
-
- now = datetime.datetime.utcnow()
- for (weeks, desc) in durations:
- exp = now + datetime.timedelta(days = weeks * 7)
- desc = desc + " " + exp.strftime("%Y-%m-%d %H:%M:%S")
- self.expirations.append(exp)
- self.duration.addItem(desc)
-
- self.duration.setCurrentIndex(0)
-
- buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
- buttonBox.button(QDialogButtonBox.Ok).setDefault(True)
-
- layout = QVBoxLayout()
- layout.addWidget(self.duration)
- layout.addWidget(buttonBox)
- self.setLayout(layout)
-
- self.connect(buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
- self.connect(buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
-
- def accept(self):
- QDialog.accept(self)
-
- def get_new_expiration(self):
- index = self.duration.currentIndex()
- return self.expirations[index]
-
class MainScreen(SfaScreen):
def __init__(self, parent):
SfaScreen.__init__(self, parent)