+ def get_slivers(self, urns, options={}):
+ """Get slivers of the given slice urns. Slivers contains slice, node and
+ user information.
+
+ For Iotlab, returns the leases with sliver ids and their allocation
+ status.
+
+ :param urns: list of slice urns.
+ :type urns: list of strings
+ :param options: unused
+ :type options: unused
+
+ .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#urns
+ """
+
+
+ slice_ids = set()
+ node_ids = []
+ for urn in urns:
+ xrn = IotlabXrn(xrn=urn)
+ if xrn.type == 'sliver':
+ # id: slice_id-node_id
+ try:
+ sliver_id_parts = xrn.get_sliver_id_parts()
+ slice_id = int(sliver_id_parts[0])
+ node_id = int(sliver_id_parts[1])
+ slice_ids.add(slice_id)
+ node_ids.append(node_id)
+ except ValueError:
+ pass
+ else:
+ slice_names = set()
+ slice_names.add(xrn.hrn)
+
+
+ logger.debug("IotlabAggregate \t get_slivers urns %s slice_ids %s \
+ node_ids %s\r\n" % (urns, slice_ids, node_ids))
+ logger.debug("IotlabAggregate \t get_slivers xrn %s slice_names %s \
+ \r\n" % (xrn, slice_names))
+ filter_sliver = {}
+ if slice_names:
+ filter_sliver['slice_hrn'] = list(slice_names)
+ slice_hrn = filter_sliver['slice_hrn'][0]
+
+ slice_filter_type = 'slice_hrn'
+
+ # if slice_ids:
+ # filter['slice_id'] = list(slice_ids)
+ # # get slices
+ if slice_hrn:
+ slices = self.driver.GetSlices(slice_hrn,
+ slice_filter_type)
+ leases = self.driver.GetLeases({'slice_hrn':slice_hrn})
+ logger.debug("IotlabAggregate \t get_slivers \
+ slices %s leases %s\r\n" % (slices, leases ))
+ if not slices:
+ return []
+
+ single_slice = slices[0]
+ # get sliver users
+ user = single_slice['reg_researchers'][0].__dict__
+ logger.debug("IotlabAggregate \t get_slivers user %s \
+ \r\n" % (user))
+
+ # construct user key info
+ person = self.driver.testbed_shell.ldap.LdapFindUser(record=user)
+ logger.debug("IotlabAggregate \t get_slivers person %s \
+ \r\n" % (person))
+ # name = person['last_name']
+ user['login'] = person['uid']
+ user['user_urn'] = hrn_to_urn(user['hrn'], 'user')
+ user['keys'] = person['pkey']
+
+
+ try:
+ node_ids = single_slice['node_ids']
+ node_list = self.driver.testbed_shell.GetNodes(
+ {'hostname':single_slice['node_ids']})
+ node_by_hostname = dict([(node['hostname'], node)
+ for node in node_list])
+ except KeyError:
+ logger.warning("\t get_slivers No slivers in slice")
+ # slice['node_ids'] = node_ids
+ # nodes_dict = self.get_slice_nodes(slice, options)
+
+ slivers = []
+ for current_lease in leases:
+ for hostname in current_lease['reserved_nodes']:
+ node = {}
+ node['slice_id'] = current_lease['slice_id']
+ node['slice_hrn'] = current_lease['slice_hrn']
+ slice_name = current_lease['slice_hrn'].split(".")[1]
+ node['slice_name'] = slice_name
+ index = current_lease['reserved_nodes'].index(hostname)
+ node_id = current_lease['resource_ids'][index]
+ # node['slice_name'] = user['login']
+ # node.update(single_slice)
+ more_info = node_by_hostname[hostname]
+ node.update(more_info)
+ # oar_job_id is the slice_id (lease_id)
+ sliver_hrn = '%s.%s-%s' % (self.driver.hrn,
+ current_lease['lease_id'], node_id)
+ node['node_id'] = node_id
+ node['expires'] = current_lease['t_until']
+ node['sliver_id'] = Xrn(sliver_hrn, type='sliver').urn
+ node['urn'] = node['sliver_id']
+ node['services_user'] = [user]
+
+ slivers.append(node)
+ return slivers