slice_hrn, _ = urn_to_hrn(slice_xrn)
# GetSlices always returns a list, even if there is only one element
- slices = self.driver.GetSlices(
- slice_filter=str(slice_hrn),
+ slices = self.driver.GetSlices(slice_filter=str(slice_hrn),
slice_filter_type='slice_hrn',
login=login)
:param sliver_allocations: dictionary of slivers
:type sliver_allocations: dict
- :returns: Node dictionary with all necessary data. .
+ :returns: Node dictionary with all necessary data.
+
.. seealso:: node_to_rspec_node
"""
rspec_node = self.node_to_rspec_node(sliver)
return rspec_node
+ def get_leases(self, slice=None, options={}):
+ filter={}
+ if slice:
+ filter.update({'name':slice['slice_name']})
+ #return_fields = ['lease_id', 'hostname', 'site_id', 'name', 't_from', 't_until']
+ leases = self.driver.GetLeases(lease_filter_dict=filter)
+ grain = self.driver.testbed_shell.GetLeaseGranularity()
+
+ rspec_leases = []
+ for lease in leases:
+ #as many leases as there are nodes in the job
+ for node in lease['reserved_nodes']:
+ rspec_lease = Lease()
+ rspec_lease['lease_id'] = lease['lease_id']
+ #site = node['site_id']
+ iotlab_xrn = xrn_object(self.driver.testbed_shell.root_auth,
+ node)
+ rspec_lease['component_id'] = iotlab_xrn.urn
+ #rspec_lease['component_id'] = hostname_to_urn(self.driver.hrn,\
+ #site, node['hostname'])
+ try:
+ rspec_lease['slice_id'] = lease['slice_id']
+ except KeyError:
+ #No info on the slice used in testbed_xp table
+ pass
+ rspec_lease['start_time'] = lease['t_from']
+ rspec_lease['duration'] = (lease['t_until'] - lease['t_from']) \
+ / grain
+ rspec_leases.append(rspec_lease)
+ return rspec_leases
+
+
def get_all_leases(self, ldap_username):
"""
Get list of lease dictionaries which all have the mandatory keys
# lookup the sliver allocations
geni_urn = urns[0]
sliver_ids = [sliver['sliver_id'] for sliver in slivers]
- logger.debug(" IOTLAB_API.PY \tDescribe sliver_ids %s "
- % (sliver_ids))
constraint = SliverAllocation.sliver_id.in_(sliver_ids)
query = self.driver.api.dbsession().query(SliverAllocation)
sliver_allocations = query.filter((constraint)).all()
- logger.debug(" IOTLAB_API.PY \tDescribe sliver_allocations %s "
- % (sliver_allocations))
sliver_allocation_dict = {}
for sliver_allocation in sliver_allocations:
geni_urn = sliver_allocation.slice_urn
sliver_allocation_dict[sliver_allocation.sliver_id] = \
sliver_allocation
+ if not options.get('list_leases') or options['list_leases'] != 'leases':
+ # add slivers
+ nodes_dict = {}
+ for sliver in slivers:
+ nodes_dict[sliver['node_id']] = sliver
+ rspec_nodes = []
+ for sliver in slivers:
+ rspec_node = self.sliver_to_rspec_node(sliver,
+ sliver_allocation_dict)
+ rspec_nodes.append(rspec_node)
+ geni_sliver = self.rspec_node_to_geni_sliver(rspec_node,
+ sliver_allocation_dict)
+ geni_slivers.append(geni_sliver)
+ rspec.version.add_nodes(rspec_nodes)
- # add slivers
- nodes_dict = {}
- for sliver in slivers:
- nodes_dict[sliver['node_id']] = sliver
- rspec_nodes = []
- for sliver in slivers:
- rspec_node = self.sliver_to_rspec_node(sliver,
- sliver_allocation_dict)
- rspec_nodes.append(rspec_node)
- logger.debug(" IOTLAB_API.PY \tDescribe sliver_allocation_dict %s "
- % (sliver_allocation_dict))
- geni_sliver = self.rspec_node_to_geni_sliver(rspec_node,
- sliver_allocation_dict)
- geni_slivers.append(geni_sliver)
-
- logger.debug(" IOTLAB_API.PY \tDescribe rspec_nodes %s\
- rspec %s "
- % (rspec_nodes, rspec))
- rspec.version.add_nodes(rspec_nodes)
+ if not options.get('list_leases') or options['list_leases'] == 'resources':
+ if slivers:
+ leases = self.get_leases(slivers[0])
+ rspec.version.add_leases(leases)
return {'geni_urn': geni_urn,
'geni_rspec': rspec.toxml(),
- 'geni_slivers': geni_slivers}
\ No newline at end of file
+ 'geni_slivers': geni_slivers}