+ if node_ids:
+ slice['node_ids'] = node_ids
+ tags_dict = self.get_slice_tags(slice)
+ nodes_dict = self.get_slice_nodes(slice, options)
+ slivers = []
+ for node in nodes_dict.values():
+ node.update(slices[0])
+ node['tags'] = tags_dict[node['node_id']]
+ sliver_hrn = '%s.%s-%s' % (self.driver.hrn, slice['slice_id'], node['node_id'])
+ node['sliver_id'] = Xrn(sliver_hrn, type='sliver').urn
+ node['urn'] = node['sliver_id']
+ slivers.append(node)
+ return slivers
+
+ def node_to_rspec_node(self, node, sites, interfaces, node_tags, pl_initscripts=[], grain=None, options={}):
+ rspec_node = Node()
+ # xxx how to retrieve site['login_base']
+ site=sites[node['site_id']]
+ rspec_node['component_id'] = hostname_to_urn(self.driver.hrn, site['login_base'], node['hostname'])
+ rspec_node['component_name'] = node['hostname']
+ rspec_node['component_manager_id'] = Xrn(self.driver.hrn, 'authority+cm').get_urn()
+ rspec_node['authority_id'] = hrn_to_urn(PlXrn.site_hrn(self.driver.hrn, site['login_base']), 'authority+sa')
+ # do not include boot state (<available> element) in the manifest rspec
+ rspec_node['boot_state'] = node['boot_state']
+ rspec_node['exclusive'] = 'false'
+ rspec_node['hardware_types'] = [HardwareType({'name': 'plab-pc'}),
+ HardwareType({'name': 'pc'})]
+ # only doing this because protogeni rspec needs
+ # to advertise available initscripts
+ rspec_node['pl_initscripts'] = pl_initscripts.values()
+ # add site/interface info to nodes.
+ # assumes that sites, interfaces and tags have already been prepared.
+ if site['longitude'] and site['latitude']:
+ location = Location({'longitude': site['longitude'], 'latitude': site['latitude'], 'country': 'unknown'})
+ rspec_node['location'] = location
+ # Granularity
+ granularity = Granularity({'grain': grain})
+ rspec_node['granularity'] = granularity
+ rspec_node['interfaces'] = []
+ if_count=0
+ for if_id in node['interface_ids']:
+ interface = Interface(interfaces[if_id])
+ interface['ipv4'] = interface['ip']
+ interface['component_id'] = PlXrn(auth=self.driver.hrn,
+ interface='node%s:eth%s' % (node['node_id'], if_count)).get_urn()
+ # interfaces in the manifest need a client id
+ if slice:
+ interface['client_id'] = "%s:%s" % (node['node_id'], if_id)
+ rspec_node['interfaces'].append(interface)
+ if_count+=1
+ tags = [PLTag(node_tags[tag_id]) for tag_id in node['node_tag_ids']]
+ rspec_node['tags'] = tags
+ return rspec_node
+
+ def sliver_to_rspec_node(self, sliver, sites, interfaces, node_tags, pl_initscripts):
+ # get the granularity in second for the reservation system
+ grain = self.driver.shell.GetLeaseGranularity()
+ rspec_node = self.node_to_rspec_node(sliver, sites, interfaces, node_tags, pl_initscripts, grain)
+ # xxx how to retrieve site['login_base']
+ rspec_node['expires'] = datetime_to_string(utcparse(sliver['expires']))
+ # remove interfaces from manifest
+ rspec_node['interfaces'] = []
+ # add sliver info
+ rspec_sliver = Sliver({'sliver_id': sliver['urn'],
+ 'name': sliver['name'],
+ 'type': 'plab-vserver',
+ 'tags': []})
+ rspec_node['sliver_id'] = rspec_sliver['sliver_id']
+ rspec_node['client_id'] = sliver['hostname']
+ rspec_node['slivers'] = [rspec_sliver]
+
+ # slivers always provide the ssh service
+ login = Login({'authentication': 'ssh-keys', 'hostname': sliver['hostname'], 'port':'22', 'username': sliver['name']})
+ service = Services({'login': login})
+ rspec_node['services'] = [service]
+ return rspec_node
+
+ def get_slice_tags(self, slice):
+ slice_tag_ids = []
+ slice_tag_ids.extend(slice['slice_tag_ids'])
+ tags = self.driver.shell.GetSliceTags({'slice_tag_id': slice_tag_ids})
+ # sorted by node_id
+ tags_dict = defaultdict(list)