[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] conga/luci/site/luci/Extensions cluster_adapte ...



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	jparsons sourceware org	2006-11-08 15:52:41

Modified files:
	luci/site/luci/Extensions: cluster_adapters.py 

Log message:
	Finish task of separating fence info methods so that conditional arg need not be passed. Also some fixes

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.153&r2=1.154

--- conga/luci/site/luci/Extensions/cluster_adapters.py	2006/11/07 21:33:52	1.153
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2006/11/08 15:52:41	1.154
@@ -2867,7 +2867,7 @@
 
 def getFence(self, model, request):
   map = {}
-  fencename = request['fencedevicename']
+  fencename = request['fencename']
   fencedevs = model.getFenceDevices()
   for fencedev in fencedevs:
     if fencedev.getName().strip() == fencename:
@@ -2877,9 +2877,37 @@
       except:
         map['pretty_name'] = fencedev.getAgentType()
 
+      nodes_used = list()
+      nodes = model.getNodes()
+      for node in nodes:
+        flevels = node.getFenceLevels()
+        for flevel in flevels: #These are the method blocks...
+          kids = flevel.getChildren()
+          for kid in kids: #These are actual devices in each level
+            if kid.getName().strip() == fencedev.getName().strip():
+              #See if this fd already has an entry for this node
+              found_duplicate = False
+              for item in nodes_used:
+                if item['nodename'] == node.getName().strip():
+                  found_duplicate = True
+              if found_duplicate == True:
+                continue
+              node_hash = {}
+              node_hash['nodename'] = node.getName().strip()
+              node_hash['nodeurl'] = baseurl + "?clustername=" + clustername + "&nodename=" + node.getName() + "&pagetype=" + NODE 
+              nodes_used.append(node_hash)
+
+      map['nodesused'] = nodes_used
       return map
 
   return map
+
+def getFDForInstance(fds, name):
+  for fd in fds:
+    if fd.getName().strip() == name:
+      return fd
+
+  raise
   
 def getFenceInfo(self, model, request):
   clustername = request['clustername']
@@ -2894,7 +2922,8 @@
   map['shared1'] = shared1
   map['shared2'] = shared2
 
-  pass
+  major_num = 1
+  minor_num = 100
 
   try:
     nodename = request['nodename']
@@ -2911,70 +2940,200 @@
   except GeneralError, e:
     raise GeneralError('FATAL', "Couldn't find node name in current node list")
 
+  fds = model.getFenceDevices()
+
   levels = node.getFenceLevels()
   len_levels = len(levels)
 
   if len_levels == 0:
     return map
 
-  for i in xrange(2):
-    if not i in levels:
-      continue
-    fence_struct = {}
-    if levels[i] != None:
-      level = levels[i]
-    else:
-      #No more levels...
-      continue
-    kids = level.getChildren()
-    if len(kids) == 0:
-      continue
-    else:
-      #for each kid, 
-      ### resolve name, find fence device
-      ### Add fd to list, if it is not there yet 
-      ### determine if it is a shared fence type
-      ### if it is a shared device, add instance entry
-      fds = model.getFenceDevices()
-      fence_struct = None
-      for kid in kids:
-        name = kid.getName()
-        found_fd = False
-        if not i in map:
-          continue
-        for entry in map[i]:
-          if entry['name'] == name:
-            fence_struct = entry
-            found_fd = True
-            break
-        if found_fd == False:
-          for fd in fds:
-            if fd.getName() == name:  #Found the fence device
-              fence_struct = {}
-              fence_struct['isShareable'] = fd.isShared()
-              fd_attrs = fd.getAttributes()
-              kees = fd_attrs.keys()
-              for kee in kees:
-                fence_struct[kee] = fd_attrs[kee]
-        fi_attrs = kid.getAttributes()
-        kees = fi_attrs.keys()
-        if fence_struct['isShareable'] == True:
-          instance_struct = {}
+  if len_levels >= 1:
+    first_level = levels[0]
+    kids = first_level.getChildren()
+    last_kid_fd = None  #This is a marker for allowing multi instances
+                        #beneath a fencedev
+    for kid in kids:
+      instance_name = kid.getName().strip()
+      try:
+        fd = getFDForInstance(fds, instance_name)
+      except:
+        fd = None #Set to None in case last time thru loop
+        continue
+      if fd != None:
+        if fd.isShared() == False:  #Not a shared dev...build struct and add
+          fencedev = {}
+          fencedev['prettyname'] = FenceHandler.FENCE_OPTS[fd.getAgentType()]
+          fencedev['isShared'] = False
+          fencedev['id'] = str(major_num)
+          major_num = major_num + 1
+          devattrs = fd.getAttributes()
+          kees = devattrs.keys()
           for kee in kees:
-            instance_struct[kee] = fi_attrs[kee]
-            try:
-                check = fence_struct['instances']
-                check.append(instance_struct)
-            except KeyError, e:
-                fence_struct['instances'] = list()
-                fence_struct['instances'].append(instance_struct) 
-        else:  #Not a shareable fence device type
+            fencedev[kee] = devattrs[kee]
+          kidattrs = kid.getAttributes()
+          kees = kidattrs.keys()
           for kee in kees:
-            fence_struct[kee] = fi_attrs[kee]
-      if i == 0:
-        level1.append(fence_struct)      
-      else:
-        level2.append(fence_struct)      
+            if kee == "name":
+              continue #Don't duplicate name attr
+            fencedev[kee] = kidattrs[kee]
+          #This fencedev struct is complete, and needs to be placed on the 
+          #level1 Q. Because it is non-shared, we should set last_kid_fd
+          #to none.
+          last_kid_fd = None
+          level1.append(fencedev)
+        else:  #This dev is shared
+          if (last_kid_fd != None) and (fd.getName().strip() == last_kid_fd.getName().strip()):  #just append a new instance struct to last_kid_fd
+            instance_struct = {}
+            instance_struct['id'] = str(minor_num)
+            minor_num = minor_num + 1
+            kidattrs = kid.getAttributes()
+            kees = kidattrs.keys()
+            for kee in kees:
+              if kee == "name":
+                continue
+              instance_struct[kee] = kidattrs[kee]
+            #Now just add this struct to last_kid_fd and reset last_kid_fd
+            ilist = last_kid_fd['instance_list']
+            ilist.append(instance_struct)
+            last_kid_fd = fd
+            continue
+          else: #Shared, but not used above...so we need a new fencedev struct
+            fencedev = {}
+            fencedev['prettyname'] = FenceHandler.FENCE_OPTS[fd.getAgentType()]
+            fencedev['isShared'] = True
+            fencedev['cfgurl'] = baseurl + "?clustername=" + clustername + "&fencename=" + fd.getName().strip() + "&pagetype=" + FENCEDEV 
+            fencedev['id'] = str(major_num)
+            major_num = major_num + 1
+            inlist = list()
+            fencedev['instance_list'] = inlist
+            devattrs = fd.getAttributes()
+            kees = devattrs.keys()
+            for kee in kees:
+              fencedev[kee] = devattrs[kee]
+            instance_struct = {}
+            kidattrs = kid.getAttributes()
+            kees = kidattrs.keys()
+            for kee in kees:
+              if kee == "name":
+                continue
+              instance_struct[kee] = kidattrs[kee]
+            inlist.append(instance_struct) 
+            level1.append(fencedev)
+            last_kid_fd = fd
+            continue
+
+    #level1 list is complete now, but it is still necessary to build shared1
+    sharednames = list()
+    for fd in fds:
+      isUnique = True
+      if fd.isShared() == False:
+        continue
+      for fdev in level1
+        if fd.getName.strip() == fdev['name']:
+          isUnique = False
+          break
+      if isUnique == True:
+        shared_struct = {}
+        shared_struct['name'] = fd.getName().strip()
+        agentname = fd.getAgentType()
+        shared_struct['agent'] = agentname
+        shared_struct['prettyname'] = FenceHandler.FENCE_OPTS[agentname]
+        shared1.append(shared_struct)
+
+  #YUK: This next section violates the DRY rule, :-(
+  if len_levels >= 2:
+    second_level = levels[1]
+    kids = second_level.getChildren()
+    last_kid_fd = None  #This is a marker for allowing multi instances
+                        #beneath a fencedev
+    for kid in kids:
+      instance_name = kid.getName().strip()
+      try:
+        fd = getFDForInstance(fds, instance_name)
+      except:
+        fd = None #Set to None in case last time thru loop
+        continue
+      if fd != None:
+        if fd.isShared() == False:  #Not a shared dev...build struct and add
+          fencedev = {}
+          fencedev['prettyname'] = FenceHandler.FENCE_OPTS[fd.getAgentType()]
+          fencedev['isShared'] = False
+          fencedev['id'] = str(major_num)
+          major_num = major_num + 1
+          devattrs = fd.getAttributes()
+          kees = devattrs.keys()
+          for kee in kees:
+            fencedev[kee] = devattrs[kee]
+          kidattrs = kid.getAttributes()
+          kees = kidattrs.keys()
+          for kee in kees:
+            if kee == "name":
+              continue #Don't duplicate name attr
+            fencedev[kee] = kidattrs[kee]
+          #This fencedev struct is complete, and needs to be placed on the 
+          #level2 Q. Because it is non-shared, we should set last_kid_fd
+          #to none.
+          last_kid_fd = None
+          level2.append(fencedev)
+        else:  #This dev is shared
+          if (last_kid_fd != None) and (fd.getName().strip() == last_kid_fd.getName().strip()):  #just append a new instance struct to last_kid_fd
+            instance_struct = {}
+            instance_struct['id'] = str(minor_num)
+            minor_num = minor_num + 1
+            kidattrs = kid.getAttributes()
+            kees = kidattrs.keys()
+            for kee in kees:
+              if kee == "name":
+                continue
+              instance_struct[kee] = kidattrs[kee]
+            #Now just add this struct to last_kid_fd and reset last_kid_fd
+            ilist = last_kid_fd['instance_list']
+            ilist.append(instance_struct)
+            last_kid_fd = fd
+            continue
+          else: #Shared, but not used above...so we need a new fencedev struct
+            fencedev = {}
+            fencedev['prettyname'] = FenceHandler.FENCE_OPTS[fd.getAgentType()]
+            fencedev['isShared'] = True
+            fencedev['cfgurl'] = baseurl + "?clustername=" + clustername + "&fencename=" + fd.getName().strip() + "&pagetype=" + FENCEDEV 
+            fencedev['id'] = str(major_num)
+            major_num = major_num + 1
+            inlist = list()
+            fencedev['instance_list'] = inlist
+            devattrs = fd.getAttributes()
+            kees = devattrs.keys()
+            for kee in kees:
+              fencedev[kee] = devattrs[kee]
+            instance_struct = {}
+            kidattrs = kid.getAttributes()
+            kees = kidattrs.keys()
+            for kee in kees:
+              if kee == "name":
+                continue
+              instance_struct[kee] = kidattrs[kee]
+            inlist.append(instance_struct) 
+            level2.append(fencedev)
+            last_kid_fd = fd
+            continue
+
+    #level2 list is complete but like above, we need to build shared2
+    sharednames = list()
+    for fd in fds:
+      isUnique = True
+      if fd.isShared() == False:
+        continue
+      for fdev in level2
+        if fd.getName.strip() == fdev['name']:
+          isUnique = False
+          break
+      if isUnique == True:
+        shared_struct = {}
+        shared_struct['name'] = fd.getName().strip()
+        agentname = fd.getAgentType()
+        shared_struct['agent'] = agentname
+        shared_struct['prettyname'] = FenceHandler.FENCE_OPTS[agentname]
+        shared2.append(shared_struct)
 
   return map    
       
@@ -2999,6 +3158,8 @@
         fencedev['pretty_name'] = FENCE_OPTS[fd.getAgentType()]
       except:
         fencedev['pretty_name'] = fd.getAgentType()
+      #Add config url for this fencedev
+      fencedev['cfgurl'] = baseurl + "?clustername=" + clustername + "&fencename=" + fd.getName().strip() + "&pagetype=" + FENCEDEV
 
       nodes = model.getNodes()
       for node in nodes:
@@ -3016,7 +3177,7 @@
                 continue
               node_hash = {}
               node_hash['nodename'] = node.getName().strip()
-              node_hash['nodeurl'] = baseurl + "#fence" + "?clustername=" + clustername + "&nodename=" + node.getName() + "&pagetype=" + NODE 
+              node_hash['nodeurl'] = baseurl + "?clustername=" + clustername + "&nodename=" + node.getName() + "&pagetype=" + NODE 
               nodes_used.append(node_hash)
 
       fencedev['nodesused'] = nodes_used


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]