handle clicking in the main window when no rspec downloaded
[sface.git] / sface / screens / mainscreen.py
index b2b8cc8..df110c6 100644 (file)
@@ -75,6 +75,11 @@ class NodeView(QTreeView):
     def toggleSelection(self):
         index = self.currentIndex()
         model = index.model()
+
+        if (model == None):
+            # probably no rspec downloaded yet
+            return
+
         status_index = model.index(index.row(), MEMBERSHIP_STATUS_COLUMN, index.parent())
         status_data = status_index.data().toString()
         node_index = model.index(index.row(), NAME_COLUMN, index.parent())
@@ -125,6 +130,11 @@ class NodeView(QTreeView):
         # Right click
         index = self.currentIndex()
         model = index.model()
+
+        if (model == None):
+            # probably no rspec downloaded yet
+            return
+
         status_index = model.index(index.row(), 1, index.parent())
         status_data = status_index.data().toString()
         node_index = model.index(index.row(), 0, index.parent())
@@ -287,6 +297,20 @@ class NodeFilterProxyModel(QSortFilterProxyModel):
                     return False
         return True
 
+    def lessThan(self, left, right):
+        l_str = str(left.data().toString())
+        r_str = str(right.data().toString())
+
+        # make sure default_tags appears before everything else
+        if l_str.startswith(default_tags):
+            return True
+
+        if r_str.startswith(default_tags):
+            return False
+
+        return (l_str < r_str)
+
+
 class SliceWidget(QWidget):
     def __init__(self, parent):
         QWidget.__init__(self, parent)
@@ -575,11 +599,11 @@ class SliceWidget(QWidget):
         rootItem = self.nodeModel.invisibleRootItem()
 
         networks = []
-        for network in rspec.get_networks():
+        for network in rspec.version.get_networks():
             network_name = network.get("name", None)
             if (network_name != None) and (not network_name in networks):
                 networks.append(network_name)
-        for network in resources.get_networks():
+        for network in resources.version.get_networks():
             network_name = network.get("name", None)
             if (network_name != None) and (not network_name in networks):
                 networks.append(network_name)
@@ -604,7 +628,7 @@ class SliceWidget(QWidget):
 
             # Add default slice tags
             nodeItem = self.nodeView.appendRow(networkItem, "%s for %s" % (default_tags, network), kind="defaults")
-            attrs = rspec.get_default_sliver_attributes(network)
+            attrs = rspec.version.get_default_sliver_attributes(network)
             for attr in attrs:
                     name = attr.get("name", None)
                     value = attr.get("value", None)
@@ -612,14 +636,21 @@ class SliceWidget(QWidget):
                     self.nodeView.appendRow(nodeItem, tagstring, membership=tag_status['in'], kind = "attribute")
 
             for node in sliver_nodes:
+                nodeType = None
+                if ("hardware_types" in node):
+                    hardware_types = [x["name"] for x in node["hardware_types"]]
+                    nodeType = ",".join(hardware_types)
+                nodeStatus = node.get("boot_state", "")
+                if nodeStatus == None:
+                    nodeStatus=""
                 nodeItem = self.nodeView.appendRow(networkItem,
                                node["component_name"],
-                               nodeStatus=node.get("boot_state", ""),
-                               #nodeType=node.get("rspec.get_node_sliver_type(node, network),
+                               nodeStatus=nodeStatus,
+                               nodeType=nodeType,
                                membership=node_status['in'],
                                kind="node")
 
-                attrs = rspec.get_sliver_attributes(node['component_id'], network)
+                attrs = rspec.version.get_sliver_attributes(node['component_id'], network)
                 for attr in attrs:
                     name = attr.get("name", None)
                     value = attr.get("value", None)
@@ -629,10 +660,17 @@ class SliceWidget(QWidget):
                                             kind="attribute")
 
             for node in available_nodes:
+                nodeType = None
+                if ("hardware_types" in node):
+                    hardware_types = [x["name"] for x in node["hardware_types"]]
+                    nodeType = ",".join(hardware_types)
+                nodeStatus = node.get("boot_state", "")
+                if nodeStatus == None:
+                    nodeStatus=""
                 self.nodeView.appendRow(networkItem,
                                node["component_name"],
-                               nodeStatus = node.get("boot_state", ""),
-                               #nodeType= resources.get_node_sliver_type(node, network),
+                               nodeStatus=nodeStatus,
+                               nodeType=nodeType,
                                membership=node_status['out'],
                                kind="node")