Whamcloud - gitweb
- landing b_fid.
[fs/lustre-release.git] / lustre / utils / Lustre / lustredb.py
index 35bca56..12656b5 100644 (file)
@@ -27,6 +27,13 @@ class LustreDB:
             return default
         return None
 
+    def get_hostaddr(self):
+       ret = []
+       list = self.dom_node.getElementsByTagName('hostaddr')
+       for node in list:
+           ret.append(node.firstChild.data)
+       return ret
+                
     def get_class(self):
         return self._get_class()
 
@@ -37,7 +44,7 @@ class LustreDB:
                 return int(str)
             return default
         except ValueError:
-            raise LconfError("text value is not integer:", str)
+            raise Lustre.LconfError("text value is not integer: " + str)
             
     def get_first_ref(self, tag):
         """ Get the first uuidref of the type TAG. Only
@@ -57,10 +64,17 @@ class LustreDB:
         uuids = self._get_all_refs()
         return uuids
 
-    def nid2server(self, nid, net_type):
+    def get_lov_tgts(self, tag):
+        """ Returns list of lovtgts. """
+        tgts = self._get_lov_tgts(tag)
+        return tgts
+
+    def nid2server(self, nid, net_type, cluster_id):
         netlist = self.lookup_class('network')
         for net_db in netlist:
-            if net_db.get_val('nid') == nid and net_db.get_val('nettype') == net_type: 
+            if (net_db.get_val('nid') == nid and
+                net_db.get_val('nettype') == net_type and
+                net_db.get_val('clusterid') == cluster_id):
                 return net_db
         return None
     
@@ -70,7 +84,7 @@ class LustreDB:
         node_db = self.lookup_name(node_name)
         if not node_db:
             return None
-        return self.get_tgt_dev(target_uuid)
+        return node_db.get_tgt_dev(target_uuid)
 
     # get all network uuids for this node
     def get_networks(self):
@@ -127,6 +141,10 @@ class LustreDB_XML(LustreDB):
         self.dom_node = dom
         self.root_node = root_node
 
+    def close(self):
+        # do nothing
+        return None
+
     def xmltext(self, dom_node, tag):
         list = dom_node.getElementsByTagName(tag)
         if len(list) > 0:
@@ -177,6 +195,18 @@ class LustreDB_XML(LustreDB):
             uuids.append(self.xml_get_ref(r))
         return uuids
 
+    def _get_lov_tgts(self, tag):
+        """ Get all the refs of type TAG.  Returns list of lov_tgts. """
+        tgts = []
+        tgtlist = self.dom_node.getElementsByTagName(tag)
+        for tgt in tgtlist:
+            uuidref = tgt.getAttribute('uuidref')
+            index = tgt.getAttribute('index')
+            generation = tgt.getAttribute('generation')
+            active = int(tgt.getAttribute('active'))
+            tgts.append((uuidref, index, generation, active))
+        return tgts
+
     def xmllookup_by_uuid(self, dom_node, uuid):
         for n in dom_node.childNodes:
             if n.nodeType == n.ELEMENT_NODE:
@@ -264,7 +294,7 @@ class LustreDB_XML(LustreDB):
         return ret
 
     def _update_active(self, tgt, new):
-        raise LconfError("updates not implemented for XML")
+        raise Lustre.LconfError("updates not implemented for XML")
 
 # ================================================================    
 # LDAP Support
@@ -274,7 +304,7 @@ class LustreDB_LDAP(LustreDB):
                  parent = None,
                  url  = "ldap://localhost",
                  user = "cn=Manager, fs=lustre",
-                 pw   = "secret"
+                 pw   = ""
                  ):
         self._name = name
         self._attrs = attrs
@@ -298,7 +328,7 @@ class LustreDB_LDAP(LustreDB):
             # user and pw only needed if modifying db
             self.l.bind_s(self._user, self._pw, ldap.AUTH_SIMPLE);
         except ldap.LDAPError, e:
-            raise Lustre.LconfError('Unable to connection to ldap server')
+            raise Lustre.LconfError('Unable to connect to ldap server:' + self._url)
 
         try:
             self._name, self._attrs = self.l.search_s(self._base,