merging with geni-api branch
[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 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 = ['geni_am']
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         ValidCreds = 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=ValidCreds[0]).get_lifetime():
35             raise InsufficientRights('SliverStatus: Credential expires before requested expiration time')
36         
37         manager_base = 'sfa.managers'
38
39         if self.api.interface in ['geni_am']:
40             mgr_type = self.api.config.SFA_GENI_AGGREGATE_TYPE
41             manager_module = manager_base + ".geni_am_%s" % mgr_type
42             manager = __import__(manager_module, fromlist=[manager_base])
43             return manager.RenewSliver(self.api, slice_xrn, ValidCreds, expiration_time)
44
45         return ''
46