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