+ YEAR = 365*24*3600
+ @staticmethod
+ def translate_timestamp (start,timestamp):
+ if timestamp < TestPlc.YEAR: return start+timestamp
+ else: return timestamp
+
+ @staticmethod
+ def timestamp_printable (timestamp):
+ return time.strftime('%m-%d %H:%M UTC',time.gmtime(timestamp))
+
+ def leases(self):
+ now=time.time()
+ grain=self.apiserver.GetLeaseGranularity(self.auth_root())
+ round=(int(now)/grain)*grain
+ start=round+grain
+ # find out all nodes that are reservable
+ nodes=self.all_reservable_nodenames()
+ if not nodes:
+ utils.header ("No reservable node found - proceeding without leases")
+ return True
+ ok=True
+ # attach them to the leases as specified in plc_specs
+ # this is where the 'leases' field gets interpreted as relative of absolute
+ for lease_spec in self.plc_spec['leases']:
+ lease_spec['t_from']=TestPlc.translate_timestamp(start,lease_spec['t_from'])
+ lease_spec['t_until']=TestPlc.translate_timestamp(start,lease_spec['t_until'])
+ if self.apiserver.AddLeases(self.auth_root(),nodes,
+ lease_spec['slice'],lease_spec['t_from'],lease_spec['t_until']):
+ utils.header('Leases on nodes %r from %s until %s'%(nodes,lease_spec['t_from'],lease_spec['t_until']))
+ else:
+ ok=False
+ return ok
+