4 from sfa.util.faults import *
5 from sfa.util.misc import *
6 from sfa.util.method import Method
7 from sfa.util.parameter import Parameter, Mixed
8 from sfa.trust.auth import Auth
9 from sfa.trust.credential import Credential
11 class delete_slice(Method):
13 Remove the slice from all nodes.
15 @param cred credential string specifying the rights of the caller
16 @param hrn human readable name specifying the slice to delete
17 @return 1 if successful, faults otherwise
20 interfaces = ['aggregate', 'slicemgr', 'component']
23 Parameter(str, "Credential string"),
24 Parameter(str, "Human readable name of slice to delete"),
25 Mixed(Parameter(str, "Request hash"),
26 Parameter(None, "Request hash not specified"))
29 returns = Parameter(int, "1 if successful")
31 def call(self, cred, hrn, request_hash=None):
32 user_cred = Credential(string=cred)
35 gid_origin_caller = user_cred.get_gid_origin_caller()
36 origin_hrn = gid_origin_caller.get_hrn()
37 self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
39 # This cred will be an slice cred, not a user, so we cant use it to
40 # authenticate the caller's request_hash. Let just get the caller's gid
41 # from the cred and authenticate using that
42 client_gid = user_cred.get_gid_caller()
43 client_gid_str = client_gid.save_to_string(save_parents=True)
44 self.api.auth.authenticateGid(client_gid_str, [cred, hrn], request_hash)
45 self.api.auth.check(cred, 'deleteslice')
48 # send the call to the right manager
49 manager_base = 'sfa.managers'
50 if self.api.interface in ['component']:
51 mgr_type = self.api.config.SFA_CM_TYPE
52 manager_module = manager_base + ".component_manager_%s" % mgr_type
53 manager = __import__(manager_module, fromlist=[manager_base])
54 manager.delete_slice(self.api, hrn)
55 elif self.api.interface in ['aggregate']:
56 mgr_type = self.api.config.SFA_AGGREGATE_TYPE
57 manager_module = manager_base + ".aggregate_manager_%s" % mgr_type
58 manager = __import__(manager_module, fromlist=[manager_base])
59 manager.delete_slice(self.api, hrn)
60 elif self.api.interface in ['slicemgr']:
61 mgr_type = self.api.config.SFA_SM_TYPE
62 manager_module = manager_base + ".slice_manager_%s" % mgr_type
63 manager = __import__(manager_module, fromlist=[manager_base])
64 manager.delete_slice(self.api, hrn, gid_origin_caller)