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