From 028594b644a518d73542b3b8b43197a6b7d73290 Mon Sep 17 00:00:00 2001 From: Sandrine Avakian Date: Tue, 26 Nov 2013 15:45:08 +0100 Subject: [PATCH] Iotlab moving to geni-v3 : First commit Changing iotlabimporter to use IotlabShell instead of the IotlabDriver (config replaced by api). Adding Describe and list_resources in iotlabaggregate.py. --- sfa/importer/iotlabimporter.py | 55 ++--- sfa/iotlab/iotlabaggregate.py | 380 +++++++++++++++++++++++---------- sfa/iotlab/iotlabdriver.py | 137 +++++++++++- sfa/iotlab/iotlabshell.py | 4 +- 4 files changed, 427 insertions(+), 149 deletions(-) diff --git a/sfa/importer/iotlabimporter.py b/sfa/importer/iotlabimporter.py index fa905ccd..d98d3081 100644 --- a/sfa/importer/iotlabimporter.py +++ b/sfa/importer/iotlabimporter.py @@ -5,13 +5,13 @@ of which slice hrn contains which job. """ from sfa.util.config import Config from sfa.util.xrn import Xrn, get_authority, hrn_to_urn - -from sfa.iotlab.iotlabdriver import IotlabDriver +from sfa.iotlab.iotlabshell import IotlabShell +# from sfa.iotlab.iotlabdriver import IotlabDriver from sfa.iotlab.iotlabpostgres import TestbedAdditionalSfaDB from sfa.trust.certificate import Keypair, convert_public_key from sfa.trust.gid import create_uuid -# using global alchemy.session() here is fine +# using global alchemy.session() here is fine # as importer is on standalone one-shot process from sfa.storage.alchemy import global_dbsession from sfa.storage.model import RegRecord, RegAuthority, RegSlice, RegNode, \ @@ -154,7 +154,7 @@ class IotlabImporter: self.records_by_type_hrn[rec_tuple] = record - def import_nodes(self, site_node_ids, nodes_by_id, iotlabdriver): + def import_nodes(self, site_node_ids, nodes_by_id, testbed_shell): """ Creates appropriate hostnames and RegNode records for each node in @@ -166,9 +166,9 @@ class IotlabImporter: :param nodes_by_id: dictionary , key is the node id, value is the a dict with node information. :type nodes_by_id: dictionary - :param iotlabdriver: IotlabDriver object, used to have access to - iotlabdriver attributes. - :type iotlabdriver: IotlabDriver + :param testbed_shell: IotlabDriver object, used to have access to + testbed_shell attributes. + :type testbed_shell: IotlabDriver :returns: None :rtype: None @@ -183,7 +183,7 @@ class IotlabImporter: - ignored" % (node_id)) continue escaped_hrn = \ - self.hostname_to_hrn_escaped(iotlabdriver.testbed_shell.root_auth, + self.hostname_to_hrn_escaped(testbed_shell.root_auth, node['hostname']) self.logger.info("IOTLABIMPORTER node %s " % (node)) hrn = node['hrn'] @@ -227,7 +227,7 @@ class IotlabImporter: pass node_record.stale = False - def import_sites_and_nodes(self, iotlabdriver): + def import_sites_and_nodes(self, testbed_shell): """ Gets all the sites and nodes from OAR, process the information, @@ -235,13 +235,13 @@ class IotlabImporter: For each site, import the site's nodes to the DB by calling import_nodes. - :param iotlabdriver: IotlabDriver object, used to have access to - iotlabdriver methods and fetching info on sites and nodes. - :type iotlabdriver: IotlabDriver + :param testbed_shell: IotlabDriver object, used to have access to + testbed_shell methods and fetching info on sites and nodes. + :type testbed_shell: IotlabDriver """ - sites_listdict = iotlabdriver.testbed_shell.GetSites() - nodes_listdict = iotlabdriver.testbed_shell.GetNodes() + sites_listdict = testbed_shell.GetSites() + nodes_listdict = testbed_shell.GetNodes() nodes_by_id = dict([(node['node_id'], node) for node in nodes_listdict]) for site in sites_listdict: site_hrn = site['name'] @@ -278,7 +278,7 @@ class IotlabImporter: pass site_record.stale = False - self.import_nodes(site['node_ids'], nodes_by_id, iotlabdriver) + self.import_nodes(site['node_ids'], nodes_by_id, testbed_shell) return @@ -319,7 +319,7 @@ class IotlabImporter: pkey = Keypair(create=True) return (pubkey, pkey) - def import_persons_and_slices(self, iotlabdriver): + def import_persons_and_slices(self, testbed_shell): """ Gets user data from LDAP, process the information. @@ -330,11 +330,11 @@ class IotlabImporter: import the user's slice onto the database as well by calling import_slice. - :param iotlabdriver: IotlabDriver object, used to have access to - iotlabdriver attributes. - :type iotlabdriver: IotlabDriver + :param testbed_shell: IotlabDriver object, used to have access to + testbed_shell attributes. + :type testbed_shell: IotlabDriver """ - ldap_person_listdict = iotlabdriver.testbed_shell.GetPersons() + ldap_person_listdict = testbed_shell.GetPersons() self.logger.info("IOTLABIMPORT \t ldap_person_listdict %s \r\n" % (ldap_person_listdict)) @@ -514,9 +514,12 @@ class IotlabImporter: :param options: :type options: """ - config = Config() - iotlabdriver = IotlabDriver(config) + config = Config () + interface_hrn = config.SFA_INTERFACE_HRN + root_auth = config.SFA_REGISTRY_ROOT_AUTH + + testbed_shell = IotlabShell(config) leases_db = TestbedAdditionalSfaDB(config) #Create special slice table for iotlab @@ -525,14 +528,14 @@ class IotlabImporter: self.logger.info("IotlabImporter.run: testbed_xp table created ") # import site and node records in site into the SFA db. - self.import_sites_and_nodes(iotlabdriver) + self.import_sites_and_nodes(testbed_shell) #import users and slice into the SFA DB. - self.import_persons_and_slices(iotlabdriver) + self.import_persons_and_slices(testbed_shell) ### remove stale records # special records must be preserved - system_hrns = [iotlabdriver.hrn, iotlabdriver.testbed_shell.root_auth, - iotlabdriver.hrn + '.slicemanager'] + system_hrns = [interface_hrn, root_auth, + interface_hrn + '.slicemanager'] for record in self.all_records: if record.hrn in system_hrns: record.stale = False diff --git a/sfa/iotlab/iotlabaggregate.py b/sfa/iotlab/iotlabaggregate.py index 9a8d0b20..8977e209 100644 --- a/sfa/iotlab/iotlabaggregate.py +++ b/sfa/iotlab/iotlabaggregate.py @@ -9,7 +9,7 @@ from sfa.rspecs.rspec import RSpec #from sfa.rspecs.elements.location import Location from sfa.rspecs.elements.hardware_type import HardwareType from sfa.rspecs.elements.login import Login -from sfa.rspecs.elements.services import Services +from sfa.rspecs.elements.services import ServicesElement from sfa.rspecs.elements.sliver import Sliver from sfa.rspecs.elements.lease import Lease from sfa.rspecs.elements.granularity import Granularity @@ -22,32 +22,7 @@ from sfa.util.sfalogging import logger from sfa.util.xrn import Xrn -def iotlab_xrn_to_hostname(xrn): - """Returns a node's hostname from its xrn. - :param xrn: The nodes xrn identifier. - :type xrn: Xrn (from sfa.util.xrn) - :returns: node's hostname. - :rtype: string - - """ - return Xrn.unescape(Xrn(xrn=xrn, type='node').get_leaf()) - - -def iotlab_xrn_object(root_auth, hostname): - """Creates a valid xrn object from the node's hostname and the authority - of the SFA server. - - :param hostname: the node's hostname. - :param root_auth: the SFA root authority. - :type hostname: string - :type root_auth: string - - :returns: the iotlab node's xrn - :rtype: Xrn - - """ - return Xrn('.'.join([root_auth, Xrn.escape(hostname)]), type='node') class IotlabAggregate: @@ -164,7 +139,10 @@ class IotlabAggregate: return ldap_username + def get_nodes(self, slices=None, slivers=[], options=None): + # def node_to_rspec_node(self, node, sites, node_tags, + # grain=None, options={}): """Returns the nodes in the slice using the rspec format, with all the nodes' properties. @@ -185,26 +163,33 @@ class IotlabAggregate: .. seealso:: get_slice_and_slivers """ + # NT: the semantic of this function is not clear to me : # if slice is not defined, then all the nodes should be returned # if slice is defined, we should return only the nodes that # are part of this slice # but what is the role of the slivers parameter ? # So i assume that slice['node_ids'] will be the same as slivers for us - slice_nodes_list = [] - if slices is not None: - for one_slice in slices: - try: - slice_nodes_list = one_slice['node_ids'] - # if we are dealing with a slice that has no node just - # return an empty list. In iotlab a slice can have multiple - # jobs scheduled, so it either has at least one lease or - # not at all. - except KeyError: - return [] + filter_nodes = None + if options: + geni_available = options.get('geni_available') + if geni_available == True: + filter_nodes['boot_state'] = ['Alive'] + + # slice_nodes_list = [] + # if slices is not None: + # for one_slice in slices: + # try: + # slice_nodes_list = one_slice['node_ids'] + # # if we are dealing with a slice that has no node just + # # return an empty list. In iotlab a slice can have multiple + # # jobs scheduled, so it either has at least one lease or + # # not at all. + # except KeyError: + # return [] # get the granularity in second for the reservation system - grain = self.driver.testbed_shell.GetLeaseGranularity() + # grain = self.driver.testbed_shell.GetLeaseGranularity() nodes = self.driver.testbed_shell.GetNodes() @@ -213,89 +198,161 @@ class IotlabAggregate: #if slices, this means we got to list all the nodes given to this slice # Make a list of all the nodes in the slice before getting their #attributes - rspec_nodes = [] + # rspec_nodes = [] - logger.debug("IOTLABAGGREGATE api get_nodes slices %s " - % (slices)) + # logger.debug("IOTLABAGGREGATE api get_nodes slices %s " + # % (slices)) - reserved_nodes = self.driver.testbed_shell.GetNodesCurrentlyInUse() - logger.debug("IOTLABAGGREGATE api get_nodes slice_nodes_list %s " - % (slice_nodes_list)) + # reserved_nodes = self.driver.testbed_shell.GetNodesCurrentlyInUse() + # logger.debug("IOTLABAGGREGATE api get_nodes slice_nodes_list %s " + # % (slice_nodes_list)) for node in nodes: nodes_dict[node['node_id']] = node - if slice_nodes_list == [] or node['hostname'] in slice_nodes_list: - - rspec_node = IotlabNode() - # xxx how to retrieve site['login_base'] - #site_id=node['site_id'] - #site=sites_dict[site_id] - - rspec_node['mobile'] = node['mobile'] - rspec_node['archi'] = node['archi'] - rspec_node['radio'] = node['radio'] - - iotlab_xrn = iotlab_xrn_object(self.driver.testbed_shell.root_auth, - node['hostname']) - rspec_node['component_id'] = iotlab_xrn.urn - rspec_node['component_name'] = node['hostname'] - rspec_node['component_manager_id'] = \ - hrn_to_urn(self.driver.testbed_shell.root_auth, - 'authority+sa') - - # Iotlab's nodes are federated : there is only one authority - # for all Iotlab sites, registered in SFA. - # Removing the part including the site - # in authority_id SA 27/07/12 - rspec_node['authority_id'] = rspec_node['component_manager_id'] - - # do not include boot state ( element) - #in the manifest rspec - - - rspec_node['boot_state'] = node['boot_state'] - if node['hostname'] in reserved_nodes: - rspec_node['boot_state'] = "Reserved" - rspec_node['exclusive'] = 'true' - rspec_node['hardware_types'] = [HardwareType({'name': \ - 'iotlab-node'})] - - - location = IotlabLocation({'country':'France', 'site': \ - node['site']}) - rspec_node['location'] = location - - - position = IotlabPosition() - for field in position : - try: - position[field] = node[field] - except KeyError, error : - logger.log_exc("IOTLABAGGREGATE\t get_nodes \ - position %s "% (error)) - - rspec_node['position'] = position - #rspec_node['interfaces'] = [] - - # Granularity - granularity = Granularity({'grain': grain}) - rspec_node['granularity'] = granularity - rspec_node['tags'] = [] - if node['hostname'] in slivers: - # add sliver info - sliver = slivers[node['hostname']] - rspec_node['sliver_id'] = sliver['sliver_id'] - rspec_node['client_id'] = node['hostname'] - rspec_node['slivers'] = [sliver] - - # 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) + # if slice_nodes_list == [] or node['hostname'] in slice_nodes_list: + + # rspec_node = IotlabNode() + # # xxx how to retrieve site['login_base'] + # #site_id=node['site_id'] + # #site=sites_dict[site_id] + + # rspec_node['mobile'] = node['mobile'] + # rspec_node['archi'] = node['archi'] + # rspec_node['radio'] = node['radio'] + + # iotlab_xrn = xrn_object(self.driver.testbed_shell.root_auth, + # node['hostname']) + # rspec_node['component_id'] = iotlab_xrn.urn + # rspec_node['component_name'] = node['hostname'] + # rspec_node['component_manager_id'] = \ + # hrn_to_urn(self.driver.testbed_shell.root_auth, + # 'authority+sa') + + # # Iotlab's nodes are federated : there is only one authority + # # for all Iotlab sites, registered in SFA. + # # Removing the part including the site + # # in authority_id SA 27/07/12 + # rspec_node['authority_id'] = rspec_node['component_manager_id'] + + # # do not include boot state ( element) + # #in the manifest rspec + + + # rspec_node['boot_state'] = node['boot_state'] + # if node['hostname'] in reserved_nodes: + # rspec_node['boot_state'] = "Reserved" + # rspec_node['exclusive'] = 'true' + # rspec_node['hardware_types'] = [HardwareType({'name': \ + # 'iotlab-node'})] + + + # location = IotlabLocation({'country':'France', 'site': \ + # node['site']}) + # rspec_node['location'] = location + + + # position = IotlabPosition() + # for field in position : + # try: + # position[field] = node[field] + # except KeyError, error : + # logger.log_exc("IOTLABAGGREGATE\t get_nodes \ + # position %s "% (error)) + + # rspec_node['position'] = position + # #rspec_node['interfaces'] = [] + + # # Granularity + # granularity = Granularity({'grain': grain}) + # rspec_node['granularity'] = granularity + # rspec_node['tags'] = [] + # if node['hostname'] in slivers: + # # add sliver info + # sliver = slivers[node['hostname']] + # rspec_node['sliver_id'] = sliver['sliver_id'] + # rspec_node['client_id'] = node['hostname'] + # rspec_node['slivers'] = [sliver] + + # # 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) + return nodes_dict + + def node_to_rspec_node(self, node, grain): + rspec_node = IotlabNode() + # xxx how to retrieve site['login_base'] + #site_id=node['site_id'] + #site=sites_dict[site_id] + + rspec_node['mobile'] = node['mobile'] + rspec_node['archi'] = node['archi'] + rspec_node['radio'] = node['radio'] + + iotlab_xrn = xrn_object(self.driver.testbed_shell.root_auth, + node['hostname']) + rspec_node['component_id'] = iotlab_xrn.urn + rspec_node['component_name'] = node['hostname'] + rspec_node['component_manager_id'] = \ + hrn_to_urn(self.driver.testbed_shell.root_auth, + 'authority+sa') + + # Iotlab's nodes are federated : there is only one authority + # for all Iotlab sites, registered in SFA. + # Removing the part including the site + # in authority_id SA 27/07/12 + rspec_node['authority_id'] = rspec_node['component_manager_id'] + + # do not include boot state ( element) + #in the manifest rspec + + + rspec_node['boot_state'] = node['boot_state'] + # if node['hostname'] in reserved_nodes: + # rspec_node['boot_state'] = "Reserved" + rspec_node['exclusive'] = 'true' + rspec_node['hardware_types'] = [HardwareType({'name': \ + 'iotlab-node'})] + + location = IotlabLocation({'country':'France', 'site': \ + node['site']}) + rspec_node['location'] = location + + + position = IotlabPosition() + for field in position : + try: + position[field] = node[field] + except KeyError, error : + logger.log_exc("IOTLABAGGREGATE\t get_nodes \ + position %s "% (error)) + + rspec_node['position'] = position + + + # Granularity + granularity = Granularity({'grain': grain}) + rspec_node['granularity'] = granularity + rspec_node['tags'] = [] + # if node['hostname'] in slivers: + # # add sliver info + # sliver = slivers[node['hostname']] + # rspec_node['sliver_id'] = sliver['sliver_id'] + # rspec_node['client_id'] = node['hostname'] + # rspec_node['slivers'] = [sliver] + + # # 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] + + return rspec_node def get_all_leases(self, ldap_username): """ @@ -338,7 +395,7 @@ class IotlabAggregate: rspec_lease = Lease() rspec_lease['lease_id'] = lease['lease_id'] #site = node['site_id'] - iotlab_xrn = iotlab_xrn_object(self.driver.testbed_shell.root_auth, + 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,\ @@ -468,3 +525,90 @@ class IotlabAggregate: logger.debug("IotlabAggregate \tget_rspec **** \ FINAL RSPEC %s \r\n" % (rspec.toxml())) return rspec.toxml() + + + def list_resources(self, version = None, options={}): + + version_manager = VersionManager() + version = version_manager.get_version(version) + rspec_version = version_manager._get_version(version.type, version.version, 'ad') + rspec = RSpec(version=rspec_version, user_options=options) + + if not options.get('list_leases') or options['list_leases'] != 'leases': + # get nodes + nodes_dict = self.get_nodes(options) + # 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 + # sites = self.get_sites({'site_id': site_ids}) + # interfaces = self.get_interfaces({'interface_id':interface_ids}) + # node_tags = self.get_node_tags({'node_tag_id': tag_ids}) + # pl_initscripts = self.get_pl_initscripts() + # convert nodes to rspec nodes + grain = self.driver.testbed_shell.GetLeaseGranularity() + rspec_nodes = [] + for node_id in nodes_dict: + node = nodes_dict[node_id] + # rspec_node = self.node_to_rspec_node(node, sites, interfaces, node_tags, pl_initscripts) + rspec_node = self.node_to_rspec_node(node, grain) + rspec_nodes.append(rspec_node) + rspec.version.add_nodes(rspec_nodes) + + # add links + # links = self.get_links(sites, nodes_dict, interfaces) + # rspec.version.add_links(links) + + if not options.get('list_leases') or options.get('list_leases') and options['list_leases'] != 'resources': + leases = self.get_all_leases() + rspec.version.add_leases(leases) + + return rspec.toxml() + + + def describe(self, urns, version=None, options={}): + version_manager = VersionManager() + version = version_manager.get_version(version) + rspec_version = version_manager._get_version(version.type, + version.version, 'manifest') + rspec = RSpec(version=rspec_version, user_options=options) + + # get slivers + geni_slivers = [] + slivers = self.get_slivers(urns, options) + if slivers: + rspec_expires = datetime_to_string(utcparse(slivers[0]['expires'])) + else: + rspec_expires = datetime_to_string(utcparse(time.time())) + rspec.xml.set('expires', rspec_expires) + + # lookup the sliver allocations + geni_urn = urns[0] + sliver_ids = [sliver['sliver_id'] for sliver in slivers] + constraint = SliverAllocation.sliver_id.in_(sliver_ids) + sliver_allocations = self.driver.api.dbsession().query(SliverAllocation).filter(constraint) + sliver_allocation_dict = {} + for sliver_allocation in sliver_allocations: + geni_urn = sliver_allocation.slice_urn + sliver_allocation_dict[sliver_allocation.sliver_id] = sliver_allocation + + # 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) + + return {'geni_urn': geni_urn, + 'geni_rspec': rspec.toxml(), + 'geni_slivers': geni_slivers} \ No newline at end of file diff --git a/sfa/iotlab/iotlabdriver.py b/sfa/iotlab/iotlabdriver.py index 55764317..3117d9a1 100644 --- a/sfa/iotlab/iotlabdriver.py +++ b/sfa/iotlab/iotlabdriver.py @@ -11,7 +11,8 @@ from sfa.rspecs.rspec import RSpec from sfa.util.xrn import Xrn, hrn_to_urn, get_authority -from sfa.iotlab.iotlabaggregate import IotlabAggregate, iotlab_xrn_to_hostname +from sfa.iotlab.iotlabaggregate import IotlabAggregate +from sfa.iotlab.iotlabxrn import xrn_to_hostname from sfa.iotlab.iotlabslices import IotlabSlices @@ -38,7 +39,7 @@ class IotlabDriver(Driver): """ Driver.__init__(self, api) - self.api=api + self.api = api config = api.config self.testbed_shell = IotlabShell(api) self.cache = None @@ -366,7 +367,7 @@ class IotlabDriver(Driver): if get_authority(lease['component_id']) == \ self.testbed_shell.root_auth: single_requested_lease['hostname'] = \ - iotlab_xrn_to_hostname(\ + xrn_to_hostname(\ lease.get('component_id').strip()) single_requested_lease['start_time'] = \ lease.get('start_time') @@ -434,6 +435,7 @@ class IotlabDriver(Driver): return xp_dict + def create_sliver(self, slice_urn, slice_hrn, creds, rspec_string, users, options): """Answer to CreateSliver. @@ -795,3 +797,132 @@ class IotlabDriver(Driver): slice_filter_type='slice_hrn'): ret = self.testbed_shell.DeleteSlice(sfa_record) return True + + def check_sliver_credentials(self, creds, urns): + # build list of cred object hrns + slice_cred_names = [] + for cred in creds: + slice_cred_hrn = Credential(cred=cred).get_gid_object().get_hrn() + slicename = Xrn(xrn=slice_cred_hrn).iotlab_slicename() + logger.debug("IOTLABDRIVER.PY \t check_sliver_credentials slicename %s \r\n \r\n" + % (slicename)) + slice_cred_names.append(slicename) + + # look up slice name of slivers listed in urns arg + + slice_ids = [] + for urn in urns: + sliver_id_parts = Xrn(xrn=urn).get_sliver_id_parts() + try: + slice_ids.append(int(sliver_id_parts[0])) + except ValueError: + pass + + if not slice_ids: + raise Forbidden("sliver urn not provided") + + slices = self.testbed_shell.GetSlices(slice_ids) + sliver_names = [single_slice['name'] for single_slice in slices] + + # make sure we have a credential for every specified sliver ierd + for sliver_name in sliver_names: + if sliver_name not in slice_cred_names: + msg = "Valid credential not found for target: %s" % sliver_name + raise Forbidden(msg) + + ######################################## + ########## aggregate oriented + ######################################## + + + def testbed_name (self): return "iotlab" + + def aggregate_version (self): + return {} + + # first 2 args are None in case of resource discovery + def list_resources (self, version=None, options={}): + aggregate = IotlabAggregate(self) + rspec = aggregate.list_resources(version=version, options=options) + return rspec + + def describe(self, urns, version, options={}): + aggregate = IotlabAggregate(self) + return aggregate.describe(urns, version=version, options=options) + + def status (self, urns, options={}): + aggregate = IotlabAggregate(self) + desc = aggregate.describe(urns, version='GENI 3') + status = {'geni_urn': desc['geni_urn'], + 'geni_slivers': desc['geni_slivers']} + return status + + + def allocate (self, urn, rspec_string, expiration, options={}): + xrn = Xrn(urn) + aggregate = IotlabAggregate(self) + + slices = IotlabSlices(self) + peer = slices.get_peer(xrn.get_hrn()) + sfa_peer = slices.get_sfa_peer(xrn.get_hrn()) + + + slice_record = None + users = options.get('geni_users', []) + if users: + slice_record = users[0].get('slice_record', {}) + logger.debug("IOTLABDRIVER.PY \t ===============allocatte \t\ + \r\n \r\n users %s" % (users)) + # parse rspec + rspec = RSpec(rspec_string) + # requested_attributes = rspec.version.get_slice_attributes() + + # ensure site record exists + # site = slices.verify_site(xrn.hrn, slice_record, peer, sfa_peer, options=options) + # ensure slice record exists + current_slice = slices.verify_slice(xrn.hrn, slice_record, peer, sfa_peer, expiration=expiration, options=options) + # ensure person records exists + persons = slices.verify_persons(xrn.hrn, slice, users, peer, sfa_peer, options=options) + # ensure slice attributes exists + # slices.verify_slice_attributes(slice, requested_attributes, options=options) + + # add/remove slice from nodes + requested_xp_dict = self._process_requested_xp_dict(rspec) + + logger.debug("IOTLABDRIVER.PY \tcreate_sliver requested_xp_dict %s " + % (requested_xp_dict)) + # request_nodes = rspec.version.get_nodes_with_slivers() + # nodes = slices.verify_slice_nodes(urn, slice, request_nodes, peer) + + # add/remove links links + # slices.verify_slice_links(slice, rspec.version.get_link_requests(), nodes) + + # add/remove leases + # rspec_requested_leases = rspec.version.get_leases() + leases = slices.verify_slice_leases(current_slice, requested_xp_dict, peer) + + # handle MyPLC peer association. + # only used by plc and ple. + slices.handle_peer(site, slice, None, peer) + + return aggregate.describe([xrn.get_urn()], version=rspec.version) + + def provision(self, urns, options={}): + # update users + slices = IotlabSlices(self) + aggregate = IotlabAggregate(self) + slivers = aggregate.get_slivers(urns) + current_slice = slivers[0] + peer = slices.get_peer(current_slice['hrn']) + sfa_peer = slices.get_sfa_peer(current_slice['hrn']) + users = options.get('geni_users', []) + persons = slices.verify_persons(current_slice['hrn'], + current_slice, users, peer, sfa_peer, options=options) + slices.handle_peer(None, None, persons, peer) + # update sliver allocation states and set them to geni_provisioned + sliver_ids = [sliver['sliver_id'] for sliver in slivers] + dbsession=self.api.dbsession() + SliverAllocation.set_allocations(sliver_ids, 'geni_provisioned',dbsession) + version_manager = VersionManager() + rspec_version = version_manager.get_version(options['geni_rspec_version']) + return self.describe(urns, rspec_version, options=options) diff --git a/sfa/iotlab/iotlabshell.py b/sfa/iotlab/iotlabshell.py index d8851168..06a8ea66 100644 --- a/sfa/iotlab/iotlabshell.py +++ b/sfa/iotlab/iotlabshell.py @@ -20,7 +20,7 @@ from sfa.trust.certificate import Keypair, convert_public_key from sfa.trust.gid import create_uuid from sfa.trust.hierarchy import Hierarchy -from sfa.iotlab.iotlabaggregate import iotlab_xrn_object +from sfa.iotlab.iotlabxrn import xrn_object class IotlabShell(): """ Class enabled to use LDAP and OAR api calls. """ @@ -985,7 +985,7 @@ class IotlabShell(): #Transform the hostnames into urns (component ids) for node in resa['reserved_nodes']: - iotlab_xrn = iotlab_xrn_object(self.root_auth, node) + iotlab_xrn = xrn_object(self.root_auth, node) resa['component_id_list'].append(iotlab_xrn.urn) if lease_filter_dict: -- 2.43.0