one more fix to renewsliver
[sfa.git] / sfa / methods / RenewSliver.py
1 from sfa.util.faults import *
2 from sfa.util.namespace import *
3 from sfa.util.method import Method
4 from sfa.util.parameter import Parameter
5 from sfa.trust.credential import Credential
6
7 class RenewSliver(Method):
8     """
9     Renews the resources in a sliver, extending the lifetime of the slice.    
10     @param slice_urn (string) URN of slice to renew
11     @param credentials ([string]) of credentials
12     @param expiration_time (string) requested time of expiration
13     
14     """
15     interfaces = ['aggregate', 'slicemgr']
16     accepts = [
17         Parameter(str, "Slice URN"),
18         Parameter(type([str]), "List of credentials"),
19         Parameter(str, "Expiration time in RFC 3339 format")
20         ]
21     returns = Parameter(bool, "Success or Failure")
22
23     def call(self, slice_xrn, creds, expiration_time):
24         hrn, type = urn_to_hrn(slice_xrn)
25
26         self.api.logger.info("interface: %s\ttarget-hrn: %s\tcaller-creds: %s\tmethod-name: %s"%(self.api.interface, hrn, creds, self.name))
27
28         # Find the valid credentials
29         valid_creds = self.api.auth.checkCredentials(creds, 'renewsliver', hrn)
30
31         # Validate that the time does not go beyond the credential's expiration time
32         requested_time = parse(expiration_time)
33         if requested_time > Credential(string=valid_creds[0]).get_expiration():
34             raise InsufficientRights('SliverStatus: Credential expires before requested expiration time')
35        
36         manager = self.api.get_interface_manager()
37         manager.renew_slice(self.api, slice_xrn, valid_creds, expiration_time)    
38  
39         return 1
40