3 from sfa.util.faults import InsufficientRights
4 from sfa.util.xrn import urn_to_hrn
5 from sfa.util.method import Method
6 from sfa.util.sfatime import utcparse
8 from sfa.trust.credential import Credential
10 from sfa.storage.parameter import Parameter
12 class RenewSliver(Method):
14 Renews the resources in a sliver, extending the lifetime of the slice.
15 @param slice_urn (string) URN of slice to renew
16 @param credentials ([string]) of credentials
17 @param expiration_time (string) requested time of expiration
20 interfaces = ['aggregate', 'slicemgr']
22 Parameter(str, "Slice URN"),
23 Parameter(type([str]), "List of credentials"),
24 Parameter(str, "Expiration time in RFC 3339 format"),
25 Parameter(dict, "Options"),
27 returns = Parameter(bool, "Success or Failure")
29 def call(self, slice_xrn, creds, expiration_time, options={}):
31 (hrn, type) = urn_to_hrn(slice_xrn)
33 self.api.logger.info("interface: %s\ttarget-hrn: %s\tcaller-creds: %s\tmethod-name: %s"%(self.api.interface, hrn, creds, self.name))
35 # Find the valid credentials
36 valid_creds = self.api.auth.checkCredentials(creds, 'renewsliver', hrn)
38 # Validate that the time does not go beyond the credential's expiration time
39 requested_time = utcparse(expiration_time)
40 max_renew_days = int(self.api.config.SFA_MAX_SLICE_RENEW)
41 if requested_time > Credential(string=valid_creds[0]).get_expiration():
42 raise InsufficientRights('Renewsliver: Credential expires before requested expiration time')
43 if requested_time > datetime.datetime.utcnow() + datetime.timedelta(days=max_renew_days):
44 raise Exception('Cannot renew > %s days from now' % max_renew_days)
45 return self.api.manager.RenewSliver(self.api, slice_xrn, valid_creds, expiration_time, options)