fix headnode not at top of list, fix get_master_node returning wrong result
smbaker [Wed, 16 Jan 2013 00:43:51 +0000 (16:43 -0800)]
apps/gacks/bridgeconfig.py

index d9b3c43..db883cf 100644 (file)
@@ -63,17 +63,15 @@ class WizardHelper:
             self.plc.DeleteSliceTag(tag["slice_tag_id"])
 
     def get_wizard_config(self, name=None, default=None):
-        if self.wizard_config is not None:
-            return self.wizard_config
-
-        self.wizard_config = {}
+        if self.wizard_config is None:
+            self.wizard_config = {}
 
-        tag = self.get_tag("slice_wizardconfig", None)
-        if tag is not None:
-            try:
-                self.wizard_config = literal_eval(tag["value"])
-            except:
-                self.wizard_config = {}
+            tag = self.get_tag("slice_wizardconfig", None)
+            if tag is not None:
+                try:
+                    self.wizard_config = literal_eval(tag["value"])
+                except:
+                    self.wizard_config = {}
 
         if name:
             return self.wizard_config.get(name, default)
@@ -120,13 +118,15 @@ class WizardHelper:
                 headnode = node
 
         if headnode:
-            # move headnode up to the front
-            nodes = [headnode] + [x for x in nodes if x!=headnode]
+            # XXX we don't need to do this anymore, since updating add_host
+            # to automatically move the headnode to the front
+            #nodes = [headnode] + [x for x in nodes if x!=headnode]
+            pass
         else:
             headnode = nodes[0]
             self.set_master_node(headnode["hostname"])
 
-        return (nodes, headnode)
+        return headnode
 
 class NetworkBuilder(WizardHelper):
     def __init__(self, plc, slice):
@@ -134,7 +134,13 @@ class NetworkBuilder(WizardHelper):
         self.want_default_interface = True
 
     def add_host(self, hostmap, node, address):
-        hostmap.append("%s %s" % (address, node["hostname"]))
+        line = "%s %s" % (address, node["hostname"])
+        if node["hostname"] == self.get_master_node():
+            # Make sure the head node goes to the top of the list
+            # as the hostmap uses this assumption to identify the headnode
+            hostmap.insert(0, line)
+        else:
+            hostmap.append(line)
 
     def configure_slice(self):
         raise "Not Implemented"
@@ -201,7 +207,7 @@ class NetworkBuilder_gre(NetworkBuilder):
         self.set_network_method("gre")
 
     def generate_star_topology(self, nodes):
-        (nodes, headnode) = self.pick_headnode(nodes)
+        headnode = self.pick_headnode(nodes)
         if not headnode:
             # if there are no nodes, then there is no topology
             return {}
@@ -234,7 +240,7 @@ class NetworkBuilder_IPv4_shared(NetworkBuilder):
         slice_id = slice["slice_id"]
 
         nodes = self.plc.GetNodes(slice["node_ids"], ["node_id", "hostname", "site_id"])
-        (nodes, headnode) = self.pick_headnode(nodes)
+        headnode = self.pick_headnode(nodes)
 
         site_ids = []
         for node in nodes:
@@ -285,7 +291,7 @@ class NetworkBuilder_IPv6_shared(NetworkBuilder):
         slice_id = slice["slice_id"]
 
         nodes = self.plc.GetNodes(slice["node_ids"], ["node_id", "hostname", "site_id"])
-        (nodes, headnode) = self.pick_headnode(nodes)
+        headnode = self.pick_headnode(nodes)
 
         hostmap = []
         for node in nodes: