+ 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
+ # this is what describes a particular node
+ node_level_tags = [PLTag(node_tags[tag_id]) for tag_id in node['node_tag_ids'] if tag_id in node_tags]
+ rspec_node['tags'] = node_level_tags
+ return rspec_node
+
+ def sliver_to_rspec_node(self, sliver, sites, interfaces, node_tags, sliver_pltags, \
+ pl_initscripts, sliver_allocations):
+ # 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)
+ for pltag in sliver_pltags:
+ logger.debug("Need to expose {}".format(pltag))
+ # 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': sliver_pltags,
+ })
+ rspec_node['sliver_id'] = rspec_sliver['sliver_id']
+ if sliver['urn'] in sliver_allocations:
+ rspec_node['client_id'] = sliver_allocations[sliver['urn']].client_id
+ if sliver_allocations[sliver['urn']].component_id:
+ rspec_node['component_id'] = sliver_allocations[sliver['urn']].component_id
+ rspec_node['slivers'] = [rspec_sliver]
+
+ # slivers always provide the ssh service
+ login = Login({'authentication': 'ssh-keys',
+ 'hostname': sliver['hostname'],
+ 'port':'22',
+ 'username': sliver['name'],
+ 'login': sliver['name']
+ })
+ service = ServicesElement({'login': login,
+ 'services_user': sliver['services_user']})
+ rspec_node['services'] = [service]
+ return rspec_node
+
+ def get_pltags_by_node_id(self, slice):
+ slice_tag_ids = []
+ slice_tag_ids.extend(slice['slice_tag_ids'])
+ tags = self.driver.shell.GetSliceTags({'slice_tag_id': slice_tag_ids},
+ ['tagname', 'value', 'node_id', 'nodegroup_id'])
+ # sorted by node_id
+ pltags_dict = defaultdict(list)
+ for tag in tags:
+ # specific to a node
+ if tag['node_id']:
+ tag['scope'] = 'sliver'
+ pltags_dict[tag['node_id']].append(PLTag(tag))
+ # restricted to a nodegroup
+ # for now such tags are not exposed to describe
+ # xxx we should also expose the nodegroup name in this case to be complete..
+ elif tag['nodegroup_id']:
+ tag['scope'] = 'nodegroup'
+ pltags_dict['nodegroup'].append(PLTag(tag))
+ # this tag is global to the slice
+ else:
+ tag['scope'] = 'slice'
+ pltags_dict['slice-global'].append(PLTag(tag))
+ return pltags_dict
+
+ def get_slice_nodes(self, slice, options=None):
+ if options is None: options={}
+ nodes_dict = {}
+ filter = {'peer_id': None}