X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Fgeniclient.py;h=d591daca26221ff7db90470fb7abed941ef42532;hb=169d8662600848b74afea4bde96a4107e0067db1;hp=54ded71e6ead05a4ac1e4200112e3fc879e0a7e8;hpb=dffd7fa770d4cc6b80bda25c0296c7c029f37b18;p=sfa.git diff --git a/sfa/util/geniclient.py b/sfa/util/geniclient.py index 54ded71e..d591daca 100644 --- a/sfa/util/geniclient.py +++ b/sfa/util/geniclient.py @@ -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 @@ -130,8 +138,8 @@ class GeniClient: # # @return list of record objects - def list(self, cred, auth_hrn): - result_dict_list = self.server.list(cred.save_to_string(save_parents=True), auth_hrn) + def list(self, cred, auth_hrn, caller_cred=None): + result_dict_list = self.server.list(cred.save_to_string(save_parents=True), auth_hrn, caller_cred) result_rec_list = [] for dict in result_dict_list: result_rec_list.append(GeniRecord(dict=dict)) @@ -145,14 +153,27 @@ 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 - def register(self, cred, record): - gid_str = self.server.register(cred.save_to_string(save_parents=True), record.as_dict()) + def register(self, cred, record, caller_cred=None): + 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. @@ -161,8 +182,19 @@ class GeniClient: # @param type # @param hrn - def remove(self, cred, type, hrn): - result = self.server.remove(cred.save_to_string(save_parents=True), type, hrn) + def remove(self, cred, type, hrn, caller_cred=None): + 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 ## @@ -174,8 +206,8 @@ class GeniClient: # @param cred credential object specifying rights of the caller # @param name human readable name of object - def resolve(self, cred, name): - result_dict_list = self.server.resolve(cred.save_to_string(save_parents=True), name) + def resolve(self, cred, name, caller_cred=None): + result_dict_list = self.server.resolve(cred.save_to_string(save_parents=True), name, caller_cred) result_rec_list = [] for dict in result_dict_list: if dict['type'] in ['authority']: @@ -200,8 +232,8 @@ class GeniClient: # @param cred credential object specifying rights of the caller # @param record a record object to be updated - def update(self, cred, record): - result = self.server.update(cred.save_to_string(save_parents=True), record.as_dict()) + def update(self, cred, record, caller_cred=None): + result = self.server.update(cred.save_to_string(save_parents=True), record.as_dict(), caller_cred) return result @@ -214,14 +246,18 @@ class GeniClient: # @param cred a credential # @param hrn slice hrn - def get_resources(self, cred, hrn=None): - result = self.server.get_resources(cred.save_to_string(save_parents=True), hrn) + def get_resources(self, cred, hrn=None, caller_cred=None): + result = self.server.get_resources(cred.save_to_string(save_parents=True), hrn, caller_cred) return result def get_aggregates(self, cred, hrn=None): - result = self.server.get_resources(cred.save_to_string(save_parents=True), hrn) + result = self.server.get_aggregates(cred.save_to_string(save_parents=True), hrn) return result + def get_registries(self, cred, hrn=None): + result = self.server.get_registries(cred.save_to_string(save_parents=True), hrn) + return result + ## get policy # # @param cred a credential @@ -235,8 +271,8 @@ class GeniClient: # @param cred a credential # @param rspec resource specification defining how to instantiate the slice - def create_slice(self, cred, hrn, rspec): - result = self.server.create_slice(cred.save_to_string(save_parents=True), hrn, rspec) + def create_slice(self, cred, hrn, rspec, caller_cred=None): + result = self.server.create_slice(cred.save_to_string(save_parents=True), hrn, rspec, caller_cred) return result @@ -244,8 +280,8 @@ class GeniClient: # # @param cred a credential # @param hrn slice to delete - def delete_slice(self, cred, hrn): - result = self.server.delete_slice(cred.save_to_string(save_parents=True), hrn) + def delete_slice(self, cred, hrn, caller_cred=None): + result = self.server.delete_slice(cred.save_to_string(save_parents=True), hrn, caller_cred) return result # ------------------------------------------------------------------------ @@ -288,8 +324,8 @@ class GeniClient: # @param cred a credential identifying the caller (callerGID) and the slice # (objectGID) - def delete_slice(self, cred, hrn): - result = self.server.delete_slice(cred.save_to_string(save_parents=True), hrn) + def delete_slice(self, cred, hrn, caller_cred=None): + result = self.server.delete_slice(cred.save_to_string(save_parents=True), hrn, caller_cred) return result ## @@ -341,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