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"),
22 Parameter(str, "call_id"),
24 returns = Parameter(bool, "Success or Failure")
26 def call(self, slice_xrn, creds, expiration_time, call_id=""):
28 (hrn, type) = urn_to_hrn(slice_xrn)
30 self.api.logger.info("interface: %s\ttarget-hrn: %s\tcaller-creds: %s\tmethod-name: %s"%(self.api.interface, hrn, creds, self.name))
32 # Find the valid credentials
33 valid_creds = self.api.auth.checkCredentials(creds, 'renewsliver', hrn)
35 # Validate that the time does not go beyond the credential's expiration time
36 requested_time = utcparse(expiration_time)
37 if requested_time > Credential(string=valid_creds[0]).get_expiration():
38 raise InsufficientRights('Renewsliver: Credential expires before requested expiration time')
39 if requested_time > datetime.datetime.utcnow() + datetime.timedelta(days=60):
40 raise Exception('Cannot renew > 60 days from now')
41 manager = self.api.get_interface_manager()
42 return manager.RenewSliver(self.api, slice_xrn, valid_creds, expiration_time, call_id)