Removing GeniClient
[sfa.git] / sfa / util / geniclient.py
index cbddf91..d591dac 100644 (file)
@@ -9,6 +9,7 @@
 ### $Id$
 ### $URL$
 
+from sfa.trust.certificate import *
 from sfa.trust.gid import *
 from sfa.trust.credential import *
 from sfa.util.record import *
@@ -35,18 +36,20 @@ class GeniClient:
     # @param protocol The ORPC protocol to use. Can be "soap" or "xmlrpc"
 
     def __init__(self, url, key_file, cert_file, protocol="xmlrpc"):
-       self.url = url
-       self.key_file = key_file
-       self.cert_file = cert_file
+        self.url = url
+        self.key_file = key_file
+        self.cert_file = cert_file
+        self.key = Keypair(filename = self.key_file)
+    
 
-       if (protocol=="xmlrpc"):
-           import xmlrpcprotocol  
-           self.server = xmlrpcprotocol.get_server(self.url, self.key_file, self.cert_file)
-       elif (protocol=="soap"):
-           import soapprotocol
-           self.server = soapprotocol.get_server(self.url, self.key_file, self.cert_file)
-       else:
-           raise Exception("Attempted use of undefined protocol %s"%protocol)
+        if (protocol=="xmlrpc"):
+            import xmlrpcprotocol  
+            self.server = xmlrpcprotocol.get_server(self.url, self.key_file, self.cert_file)
+        elif (protocol=="soap"):
+            import soapprotocol
+            self.server = soapprotocol.get_server(self.url, self.key_file, self.cert_file)
+        else:
+            raise Exception("Attempted use of undefined protocol %s"%protocol)
 
 
     # -------------------------------------------------------------------------
@@ -78,13 +81,18 @@ class GeniClient:
     #
     # @return a GID object
 
-    def get_gid(self, name):
-       gid_str_list = self.server.get_gid(name)
-       gid_list = []
-       for str in gid_str_list:
-           gid_list.append(GID(string=str))
-       return gid_list
+    #def get_gid(self, name):
+    #   gid_str_list = self.server.get_gid(name)
+    #   gid_list = []
+    #   for str in gid_str_list:
+    #       gid_list.append(GID(string=str))
+    #  return gid_list
+
 
+    def get_gid(self, cert, hrn, type, request_hash):
+        cert_string = cert.save_to_string(save_parents=True)
+        gid_str = self.server.get_gid(cert_string, hrn, type, request_hash)
+        return GID(string=gid_str)
     ##
     # Get_self_credential a degenerate version of get_credential used by a
     # client to get his initial credential when he doesn't have one. This is
@@ -145,7 +153,7 @@ class GeniClient:
     #
     #
     # @param cred credential object specifying rights of the caller
-    # @return record to register
+    # @param record to register
     #
     # @return GID object for the newly-registered record
 
@@ -153,6 +161,19 @@ class GeniClient:
         gid_str = self.server.register(cred.save_to_string(save_parents=True), record.as_dict(), caller_cred)
         return GID(string = gid_str)
 
+    
+    ##
+    # Register a peer object with the registry. 
+    #
+    #
+    # @param cred credential object specifying rights of the caller
+    # @param record to register
+    #
+    # @return GID object for the newly-registered record
+
+    def register_peer_object(self, cred, record, caller_cred=None):
+        return self.server.register_peer_object(cred.save_to_string(save_parents=True), record, caller_cred)
+
     ##
     # Remove an object from the registry. If the object represents a PLC object,
     # then the PLC records will also be removed.
@@ -162,7 +183,18 @@ class GeniClient:
     # @param hrn
 
     def remove(self, cred, type, hrn, caller_cred=None):
-        result = self.server.remove(cred.save_to_string(save_parents=True), type, hrn, caller_cred)
+        return self.server.remove(cred.save_to_string(save_parents=True), type, hrn, caller_cred)
+
+    ##
+    # Remove a peer object from the registry. If the object represents a PLC object,
+    # then the PLC records will also be removed.
+    #
+    # @param cred credential object specifying rights of the caller
+    # @param type
+    # @param hrn
+
+    def remove_peer_object(self, cred, record, caller_cred=None):
+        result = self.server.remove_peer_object(cred.save_to_string(save_parents=True), record, caller_cred)
         return result
 
     ##
@@ -345,3 +377,6 @@ class GeniClient:
         return result
 
 
+    def remove_remote_object(self, cred, hrn, record):
+        result = self.server.remove_remote_object(cred.save_to_string(save_parents=True), hrn, record)
+        return result