1 from sfa.util.faults import *
2 from sfa.util.xrn 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 sfa.util.sfatime import utcparse
9 class RenewSliver(Method):
11 Renews the resources in a sliver, extending the lifetime of the slice.
12 @param slice_urn (string) URN of slice to renew
13 @param credentials ([string]) of credentials
14 @param expiration_time (string) requested time of expiration
17 interfaces = ['aggregate', 'slicemgr']
19 Parameter(str, "Slice URN"),
20 Parameter(type([str]), "List of credentials"),
21 Parameter(str, "Expiration time in RFC 3339 format")
23 returns = Parameter(bool, "Success or Failure")
25 def call(self, slice_xrn, creds, expiration_time):
26 hrn, type = urn_to_hrn(slice_xrn)
28 self.api.logger.info("interface: %s\ttarget-hrn: %s\tcaller-creds: %s\tmethod-name: %s"%(self.api.interface, hrn, creds, self.name))
30 # Find the valid credentials
31 valid_creds = self.api.auth.checkCredentials(creds, 'renewsliver', hrn)
33 # Validate that the time does not go beyond the credential's expiration time
34 requested_time = utcparse(expiration_time)
35 if requested_time > Credential(string=valid_creds[0]).get_expiration():
36 raise InsufficientRights('SliverStatus: Credential expires before requested expiration time')
37 if requested_time > datetime.datetime.utcnow() + datetime.timedelta(days=60):
38 raise Exception('Cannot renew > 60 days from now')
39 manager = self.api.get_interface_manager()
40 manager.renew_slice(self.api, slice_xrn, valid_creds, expiration_time)