def verify_slice(self, slice_hrn, slice_record, sfa_peer, expiration, options={}): #top_auth_hrn = top_auth(slice_hrn) #site_hrn = '.'.join(slice_hrn.split('.')[:-1]) #slice_part = slice_hrn.split('.')[-1] #if top_auth_hrn == self.driver.hrn: # login_base = slice_hrn.split('.')[-2][:12] #else: # login_base = hash_loginbase(site_hrn) #slice_name = '_'.join([login_base, slice_part]) plxrn = PlXrn(xrn=slice_hrn) slice_hrn = plxrn.get_hrn() type = plxrn.get_type() site_hrn = plxrn.get_authority_hrn() authority_name = plxrn.pl_authname() slicename = plxrn.pl_slicename() login_base = plxrn.pl_login_base() slices = self.driver.shell.GetSlices({'peer_id': None}, ['slice_id', 'name', 'hrn']) # Filter slices by HRN slice_exists = [slice for slice in slices if slice['hrn'] == slice_hrn] expires = int(datetime_to_epoch(utcparse(expiration))) if not slice_exists: if slice_record: url = slice_record.get('url', slice_hrn) description = slice_record.get('description', slice_hrn) else: url = slice_hrn description = slice_hrn slice = { 'name': slice_name, 'url': url, 'description': description } # add the slice slice['slice_id'] = self.driver.shell.AddSlice(slice) # set the slice HRN self.driver.shell.SetSliceHrn(int(slice['slice_id']), slice_hrn) # Tag this as created through SFA self.driver.shell.SetSliceSfaCreated(int(slice['slice_id']), 'True') # set the expiration self.driver.shell.UpdateSlice(int(slice['slice_id']), {'expires': expires}) else: slice = slice_exists[0] #Update expiration if necessary if slice.get('expires', None) != expires: self.driver.shell.UpdateSlice(int(slice['slice_id']), {'expires': expires}) return self.driver.shell.GetSlices(int(slice['slice_id']))[0]
def verify_site(self, slice_xrn, slice_record={}, sfa_peer=None, options={}): #(slice_hrn, type) = urn_to_hrn(slice_xrn) #top_auth_hrn = top_auth(slice_hrn) #site_hrn = '.'.join(slice_hrn.split('.')[:-1]) #if top_auth_hrn == self.driver.hrn: # login_base = slice_hrn.split('.')[-2][:12] #else: # login_base = hash_loginbase(site_hrn) plxrn = PlXrn(xrn=slice_xrn) slice_hrn = plxrn.get_hrn() type = plxrn.get_type() site_hrn = plxrn.get_authority_hrn() authority_name = plxrn.pl_authname() slicename = plxrn.pl_slicename() login_base = plxrn.pl_login_base() sites = self.driver.shell.GetSites( {'peer_id': None}, ['site_id', 'name', 'abbreviated_name', 'login_base', 'hrn']) # filter sites by hrn site_exists = [site for site in sites if site['hrn'] == site_hrn] if not site_exists: # create new site record site = { 'name': 'sfa:%s' % site_hrn, 'abbreviated_name': site_hrn, 'login_base': login_base, 'max_slices': 100, 'max_slivers': 1000, 'enabled': True, 'peer_site_id': None } site['site_id'] = self.driver.shell.AddSite(site) # Set site HRN self.driver.shell.SetSiteHrn(int(site['site_id']), site_hrn) # Tag this as created through SFA self.driver.shell.SetSiteSfaCreated(int(site['site_id']), 'True') # exempt federated sites from monitor policies self.driver.shell.AddSiteTag(int(site['site_id']), 'exempt_site_until', "20200101") else: site = site_exists[0] return site
def redeem_ticket(api, ticket_string): ticket = SfaTicket(string=ticket_string) ticket.decode() hrn = ticket.attributes['slivers'][0]['hrn'] slicename = PlXrn (hrn).pl_slicename() if not api.sliver_exists(slicename): raise SliverDoesNotExist(slicename) # convert ticket to format nm is used to nm_ticket = xmlrpclib.dumps((ticket.attributes,), methodresponse=True) api.driver.nodemanager.AdminTicket(nm_ticket)
def node_to_rspec_node(self, node, sites, interfaces, node_tags, pl_initscripts=None, grain=None, options=None): if pl_initscripts is None: pl_initscripts=[] if options is None: options={} rspec_node = NodeElement() # 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'] if node['boot_state'] == 'boot': rspec_node['available'] = 'true' else: rspec_node['available'] = 'false' #distinguish between Shared and Reservable nodes if node['node_type'] == 'reservable': rspec_node['exclusive'] = 'true' else: 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'] if tag_id in node_tags] rspec_node['tags'] = tags return rspec_node
def add_slivers(xml, slivers): if not slivers: return if not isinstance(slivers, list): slivers = [slivers] for sliver in slivers: sliver_elem = xml.add_instance('sliver', sliver, ['name']) tags = sliver.get('tags', []) if tags: for tag in tags: NITOSv1Sliver.add_sliver_attribute(sliver_elem, tag['tagname'], tag['value']) if sliver.get('sliver_id'): name = PlXrn(xrn=sliver.get('sliver_id')).pl_slicename() sliver_elem.set('name', name)
def sfa_fields_to_pl_fields(self, type, hrn, sfa_record): pl_record = {} if type == "slice": pl_record["name"] = hrn_to_pl_slicename(hrn) if "instantiation" in sfa_record: pl_record['instantiation'] = sfa_record['instantiation'] else: pl_record["instantiation"] = "plc-instantiated" if "url" in sfa_record: pl_record["url"] = sfa_record["url"] if "description" in sfa_record: pl_record["description"] = sfa_record["description"] if "expires" in sfa_record: date = utcparse(sfa_record['expires']) expires = datetime_to_epoch(date) pl_record["expires"] = expires elif type == "node": if not "hostname" in pl_record: # fetch from sfa_record if "hostname" not in sfa_record: raise MissingSfaInfo("hostname") pl_record["hostname"] = sfa_record["hostname"] if "model" in sfa_record: pl_record["model"] = sfa_record["model"] else: pl_record["model"] = "geni" elif type == "authority": pl_record["login_base"] = PlXrn(xrn=hrn, type='authority').pl_login_base() if "name" not in sfa_record: pl_record["name"] = hrn if "abbreviated_name" not in sfa_record: pl_record["abbreviated_name"] = hrn if "enabled" not in sfa_record: pl_record["enabled"] = True if "is_public" not in sfa_record: pl_record["is_public"] = True return pl_record
def reset_slice(api, xrn): slicename = PlXrn(xrn, type='slice').pl_slicename() if not api.sliver_exists(slicename): raise SliverDoesNotExist(slicename) api.driver.nodemanager.ReCreate(slicename)
def DeleteSliver(api, xrn, creds, call_id): slicename = PlXrn(xrn, type='slice').pl_slicename() api.driver.nodemanager.Destroy(slicename)
def stop_slice(api, xrn, creds): slicename = PlXrn(xrn, type='slice').pl_slicename() api.driver.nodemanager.Stop(slicename)
def test_person001(self): xrn = PlXrn(auth="ple.inria", email="*****@*****.**") self.assertEqual(xrn.get_hrn_type(), ("ple.inria.first_last", 'person'))
def test_slice001(self): xrn = PlXrn(auth="ple", slicename="inria_omftest") self.assertEqual(xrn.get_hrn_type(), ("ple.inria.omftest", 'slice'))
def test_host002(self): xrn = PlXrn(auth="ple\\.inria", hostname="onelab09.pl.sophia.inria.fr") self.assertEqual( xrn.get_hrn_type(), ("ple\\.inria.onelab09\\.pl\\.sophia\\.inria\\.fr", 'node'))
def test_authname_001(self): xrn = PlXrn(xrn='ple.inria.omftest', type='slice') self.assertEqual(xrn.pl_authname(), 'inria')
def get_slivers(self, urns, options=None): if options is None: options={} names = set() slice_ids = set() node_ids = [] slice_hrn = None for urn in urns: xrn = PlXrn(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_hrn = xrn.get_hrn() filter = {} filter['peer_id'] = None if slice_ids: filter['slice_id'] = list(slice_ids) # get all slices all_slices = self.driver.shell.GetSlices(filter, ['slice_id', 'name', 'hrn', 'person_ids', 'node_ids', 'slice_tag_ids', 'expires']) if slice_hrn: slices = [slice for slice in all_slices if slice['hrn'] == slice_hrn] else: slices = all_slices if not slices: return [] slice = slices[0] slice['hrn'] = slice_hrn # get sliver users persons = [] person_ids = [] for slice in slices: person_ids.extend(slice['person_ids']) if person_ids: persons = self.driver.shell.GetPersons(person_ids) # get user keys keys = {} key_ids = [] for person in persons: key_ids.extend(person['key_ids']) if key_ids: key_list = self.driver.shell.GetKeys(key_ids) for key in key_list: keys[key['key_id']] = key # construct user key info users = [] for person in persons: person_urn = hrn_to_urn(self.driver.shell.GetPersonHrn(int(person['person_id'])), 'user') user = { 'login': slice['name'], 'user_urn': person_urn, 'keys': [keys[k_id]['key'] for k_id in person['key_ids'] if k_id in keys] } users.append(user) if node_ids: node_ids = [node_id for node_id in node_ids if node_id in slice['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(slice) 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'] node['services_user'] = users slivers.append(node) return slivers
def register(self, sfa_record, hrn, pub_key): type = sfa_record['type'] pl_record = self.sfa_fields_to_pl_fields(type, hrn, sfa_record) if type == 'authority': sites = self.shell.GetSites({ 'peer_id': None, 'login_base': pl_record['login_base'] }) if not sites: # xxx when a site gets registered through SFA we need to set its max_slices if 'max_slices' not in pl_record: pl_record['max_slices'] = 2 pointer = self.shell.AddSite(pl_record) self.shell.SetSiteHrn(int(pointer), hrn) else: pointer = sites[0]['site_id'] elif type == 'slice': acceptable_fields = ['url', 'instantiation', 'name', 'description'] for key in pl_record.keys(): if key not in acceptable_fields: pl_record.pop(key) slices = self.shell.GetSlices({ 'peer_id': None, 'name': pl_record['name'] }) if not slices: if not pl_record.get('url', None) or not pl_record.get( 'description', None): pl_record['url'] = hrn pl_record['description'] = hrn pointer = self.shell.AddSlice(pl_record) self.shell.SetSliceHrn(int(pointer), hrn) else: pointer = slices[0]['slice_id'] elif type == 'user': persons = self.shell.GetPersons({ 'peer_id': None, 'email': sfa_record['email'] }) if not persons: for key in ['first_name', 'last_name']: if key not in sfa_record: sfa_record[key] = '*from*sfa*' # AddPerson does not allow everything to be set can_add = [ 'first_name', 'last_name', 'title', 'email', 'password', 'phone', 'url', 'bio' ] add_person_dict = dict([(k, sfa_record[k]) for k in sfa_record if k in can_add]) pointer = self.shell.AddPerson(add_person_dict) self.shell.SetPersonHrn(int(pointer), hrn) else: pointer = persons[0]['person_id'] # enable the person's account self.shell.UpdatePerson(pointer, {'enabled': True}) # add this person to the site login_base = get_leaf(sfa_record['authority']) self.shell.AddPersonToSite(pointer, login_base) # What roles should this user have? roles = [] if 'roles' in sfa_record: # if specified in xml, but only low-level roles roles = [ role for role in sfa_record['roles'] if role in ['user', 'tech'] ] # at least user if no other cluse could be found if not roles: roles = ['user'] for role in roles: self.shell.AddRoleToPerson(role, pointer) # Add the user's key if pub_key: self.shell.AddPersonKey(pointer, { 'key_type': 'ssh', 'key': pub_key }) elif type == 'node': login_base = PlXrn(xrn=sfa_record['authority'], type='authority').pl_login_base() nodes = self.shell.GetNodes({ 'peer_id': None, 'hostname': pl_record['hostname'] }) if not nodes: pointer = self.shell.AddNode(login_base, pl_record) self.shell.SetNodeHrn(int(pointer), hrn) else: pointer = nodes[0]['node_id'] return pointer
def get_links(self, sites, nodes, interfaces): topology = Topology() links = [] for (site_id1, site_id2) in topology: site_id1 = int(site_id1) site_id2 = int(site_id2) link = Link() if not site_id1 in sites or site_id2 not in sites: continue site1 = sites[site_id1] site2 = sites[site_id2] # get hrns site1_hrn = self.driver.hrn + '.' + site1['login_base'] site2_hrn = self.driver.hrn + '.' + site2['login_base'] for s1_node_id in site1['node_ids']: for s2_node_id in site2['node_ids']: if s1_node_id not in nodes or s2_node_id not in nodes: continue node1 = nodes[s1_node_id] node2 = nodes[s2_node_id] # set interfaces # just get first interface of the first node if1_xrn = PlXrn(auth=self.driver.hrn, interface='node%s:eth0' % (node1['node_id'])) if1_ipv4 = interfaces[node1['interface_ids'][0]]['ip'] if2_xrn = PlXrn(auth=self.driver.hrn, interface='node%s:eth0' % (node2['node_id'])) if2_ipv4 = interfaces[node2['interface_ids'][0]]['ip'] if1 = Interface({ 'component_id': if1_xrn.urn, 'ipv4': if1_ipv4 }) if2 = Interface({ 'component_id': if2_xrn.urn, 'ipv4': if2_ipv4 }) # set link link = Link({ 'capacity': '1000000', 'latency': '0', 'packet_loss': '0', 'type': 'ipv4' }) link['interface1'] = if1 link['interface2'] = if2 link['component_name'] = "%s:%s" % (site1['login_base'], site2['login_base']) link['component_id'] = PlXrn( auth=self.driver.hrn, interface=link['component_name']).get_urn() link['component_manager_id'] = hrn_to_urn( self.driver.hrn, 'authority+am') links.append(link) return links
def node_to_rspec_node(self, node, sites, interfaces, node_tags, pl_initscripts=[], grain=None, options={}): rspec_node = NodeElement() # 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'] if node['boot_state'] == 'boot': rspec_node['available'] = 'true' else: rspec_node['available'] = 'false' #distinguish between Shared and Reservable nodes if node['node_type'] == 'reservable': rspec_node['exclusive'] = 'true' else: 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'] if tag_id in node_tags ] rspec_node['tags'] = tags return rspec_node
def get_slivers(self, urns, options={}): names = set() slice_ids = set() node_ids = [] slice_hrn = None for urn in urns: xrn = PlXrn(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_hrn = xrn.get_hrn() filter = {} filter['peer_id'] = None if slice_ids: filter['slice_id'] = list(slice_ids) # get all slices all_slices = self.driver.shell.GetSlices(filter, [ 'slice_id', 'name', 'hrn', 'person_ids', 'node_ids', 'slice_tag_ids', 'expires' ]) if slice_hrn: slices = [ slice for slice in all_slices if slice['hrn'] == slice_hrn ] else: slices = all_slices if not slices: return [] slice = slices[0] slice['hrn'] = slice_hrn # get sliver users persons = [] person_ids = [] for slice in slices: person_ids.extend(slice['person_ids']) if person_ids: persons = self.driver.shell.GetPersons(person_ids) # get user keys keys = {} key_ids = [] for person in persons: key_ids.extend(person['key_ids']) if key_ids: key_list = self.driver.shell.GetKeys(key_ids) for key in key_list: keys[key['key_id']] = key # construct user key info users = [] for person in persons: person_urn = hrn_to_urn( self.driver.shell.GetPersonHrn(int(person['person_id'])), 'user') user = { 'login': slice['name'], 'user_urn': person_urn, 'keys': [ keys[k_id]['key'] for k_id in person['key_ids'] if k_id in keys ] } users.append(user) if node_ids: node_ids = [ node_id for node_id in node_ids if node_id in slice['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(slice) 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'] node['services_user'] = users slivers.append(node) return slivers
def instance_to_rspec_node(self, instance): # determine node urn node_xrn = instance.metadata.get('component_id') if not node_xrn: node_xrn = OSXrn('cloud', type='node') else: node_xrn = OSXrn(xrn=node_xrn, type='node') rspec_node = Node() rspec_node['component_id'] = node_xrn.urn rspec_node['component_name'] = node_xrn.name rspec_node['component_manager_id'] = Xrn(self.driver.hrn, 'authority+cm').get_urn() rspec_node['sliver_id'] = OSXrn(name=instance.name, type='slice', id=instance.id).get_urn() if instance.metadata.get('client_id'): rspec_node['client_id'] = instance.metadata.get('client_id') # get sliver details flavor = self.driver.shell.nova_manager.flavors.find(id=instance.flavor['id']) sliver = self.instance_to_sliver(flavor) # get firewall rules fw_rules = [] group_name = instance.metadata.get('security_groups') if group_name: group = self.driver.shell.nova_manager.security_groups.find(name=group_name) for rule in group.rules: port_range ="%s:%s" % (rule['from_port'], rule['to_port']) fw_rule = FWRule({'protocol': rule['ip_protocol'], 'port_range': port_range, 'cidr_ip': rule['ip_range']['cidr']}) fw_rules.append(fw_rule) sliver['fw_rules'] = fw_rules rspec_node['slivers'] = [sliver] # get disk image image = self.driver.shell.image_manager.get_images(id=instance.image['id']) if isinstance(image, list) and len(image) > 0: image = image[0] disk_image = image_to_rspec_disk_image(image) sliver['disk_image'] = [disk_image] # get interfaces rspec_node['services'] = [] rspec_node['interfaces'] = [] addresses = instance.addresses # HACK: public ips are stored in the list of private, but # this seems wrong. Assume pub ip is the last in the list of # private ips until openstack bug is fixed. if addresses.get('private'): login = Login({'authentication': 'ssh-keys', 'hostname': addresses.get('private')[-1]['addr'], 'port':'22', 'username': '******'}) service = Services({'login': login}) rspec_node['services'].append(service) for private_ip in addresses.get('private', []): if_xrn = PlXrn(auth=self.driver.hrn, interface='node%s' % (instance.hostId)) if_client_id = Xrn(if_xrn.urn, type='interface', id="eth%s" %if_index).urn if_sliver_id = Xrn(rspec_node['sliver_id'], type='slice', id="eth%s" %if_index).urn interface = Interface({'component_id': if_xrn.urn, 'client_id': if_client_id, 'sliver_id': if_sliver_id}) interface['ips'] = [{'address': private_ip['addr'], #'netmask': private_ip['network'], 'type': private_ip['version']}] rspec_node['interfaces'].append(interface) # slivers always provide the ssh service for public_ip in addresses.get('public', []): login = Login({'authentication': 'ssh-keys', 'hostname': public_ip['addr'], 'port':'22', 'username': '******'}) service = Services({'login': login}) rspec_node['services'].append(service) return rspec_node
def test_login_base_001(self): xrn = PlXrn(xrn='ple.inria.omftest', type='slice') self.assertEqual(xrn.pl_login_base(), 'inria')
def get_nodes_and_links(self, slice_xrn, slice=None,slivers=[], options={}): # if we are dealing with a slice that has no node just return # and empty list if slice_xrn: if not slice or not slice['node_ids']: return ([],[]) filter = {} tags_filter = {} if slice and 'node_ids' in slice and slice['node_ids']: filter['node_id'] = slice['node_ids'] tags_filter=filter.copy() geni_available = options.get('geni_available') if geni_available == True: filter['boot_state'] = 'boot' filter.update({'peer_id': None}) nodes = self.driver.shell.GetNodes(filter) # get the granularity in second for the reservation system grain = self.driver.shell.GetLeaseGranularity() site_ids = [] interface_ids = [] tag_ids = [] nodes_dict = {} for node in nodes: site_ids.append(node['site_id']) interface_ids.extend(node['interface_ids']) tag_ids.extend(node['node_tag_ids']) nodes_dict[node['node_id']] = node # get sites sites_dict = self.get_sites({'site_id': site_ids}) # get interfaces interfaces = self.get_interfaces({'interface_id':interface_ids}) # get tags node_tags = self.get_node_tags(tags_filter) # get initscripts pl_initscripts = self.get_pl_initscripts() links = self.get_links(sites_dict, nodes_dict, interfaces) rspec_nodes = [] for node in nodes: # skip whitelisted nodes if node['slice_ids_whitelist']: if not slice or slice['slice_id'] not in node['slice_ids_whitelist']: continue rspec_node = Node() # xxx how to retrieve site['login_base'] site_id=node['site_id'] site=sites_dict[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 if not slice: rspec_node['boot_state'] = node['boot_state'] #add the exclusive tag to distinguish between Shared and Reservable nodes if node['node_type'] == 'reservable': rspec_node['exclusive'] = 'true' else: 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. site = sites_dict[node['site_id']] 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']\ if tag_id in node_tags] rspec_node['tags'] = tags if node['node_id'] in slivers: # add sliver info sliver = slivers[node['node_id']] rspec_node['sliver_id'] = sliver['sliver_id'] rspec_node['slivers'] = [sliver] for tag in sliver['tags']: if tag['tagname'] == 'client_id': rspec_node['client_id'] = tag['value'] # slivers always provide the ssh service login = Login({'authentication': 'ssh-keys', 'hostname': node['hostname'], 'port':'22', 'username': sliver['name']}) service = Services({'login': login}) rspec_node['services'] = [service] rspec_nodes.append(rspec_node) return (rspec_nodes, links)