def get_rspec(self, slice_xrn=None, version = None, options={}): version_manager = VersionManager() version = version_manager.get_version(version) if not slice_xrn: rspec_version = version_manager._get_version(version.type, version.version, 'ad') else: rspec_version = version_manager._get_version(version.type, version.version, 'manifest') slice, slivers = self.get_slice_and_slivers(slice_xrn) rspec = RSpec(version=rspec_version, user_options=options) if slice and 'expires' in slice: rspec.xml.set('expires', datetime_to_string(utcparse(slice['expires']))) nodes = self.get_nodes(slice_xrn, slice, slivers, options) rspec.version.add_nodes(nodes) # add sliver defaults default_sliver = slivers.get(None, []) if default_sliver: default_sliver_attribs = default_sliver.get('tags', []) for attrib in default_sliver_attribs: logger.info(attrib) rspec.version.add_default_sliver_attribute(attrib['tagname'], attrib['value']) return rspec.toxml()
def create_sliver (self, slice_urn, slice_hrn, creds, rspec_string, users, options): aggregate = OSAggregate(self) # assume first user is the caller and use their context # for the ec2/euca api connection. Also, use the first users # key as the project key. key_name = None if len(users) > 1: key_name = aggregate.create_instance_key(slice_hrn, users[0]) # collect public keys pubkeys = [] for user in users: pubkeys.extend(user['keys']) rspec = RSpec(rspec_string) instance_name = hrn_to_os_slicename(slice_hrn) tenant_name = OSXrn(xrn=slice_hrn, type='slice').get_tenant_name() instances = aggregate.run_instances(instance_name, tenant_name, rspec_string, key_name, pubkeys) rspec_nodes = [] for instance in instances: rspec_nodes.append(aggregate.instance_to_rspec_node(slice_urn, instance)) version_manager = VersionManager() manifest_version = version_manager._get_version(rspec.version.type, rspec.version.version, 'manifest') manifest_rspec = RSpec(version=manifest_version, user_options=options) manifest_rspec.version.add_nodes(rspec_nodes) return manifest_rspec.toxml()
def merge(self, in_rspec): """ Merge contents for specified rspec with current rspec """ if not in_rspec: return from sfa.rspecs.rspec import RSpec if isinstance(in_rspec, RSpec): rspec = in_rspec else: rspec = RSpec(in_rspec) if rspec.version.type.lower() == 'protogeni': from sfa.rspecs.rspec_converter import RSpecConverter in_rspec = RSpecConverter.to_sfa_rspec(rspec.toxml()) rspec = RSpec(in_rspec) # just copy over all networks current_networks = self.get_networks() networks = rspec.version.get_networks() for network in networks: current_network = network.get('name') if current_network and current_network not in current_networks: self.xml.append(network.element) current_networks.append(current_network)
def describe(self, urns, version=None, options={}): # update nova connection tenant_name = OSXrn(xrn=urns[0], type='slice').get_tenant_name() self.driver.shell.nova_manager.connect(tenant=tenant_name) instances = self.get_instances(urns) # lookup the sliver allocations 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: sliver_allocation_dict[sliver_allocation.sliver_id] = sliver_allocation geni_slivers = [] rspec_nodes = [] for instance in instances: rspec_nodes.append(self.instance_to_rspec_node(instance)) geni_sliver = self.instance_to_geni_sliver(instance, sliver_sllocation_dict) geni_slivers.append(geni_sliver) 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) rspec.xml.set('expires', datetime_to_string(utcparse(time.time()))) rspec.version.add_nodes(rspec_nodes) result = {'geni_urn': Xrn(urns[0]).get_urn(), 'geni_rspec': rspec.toxml(), 'geni_slivers': geni_slivers} return result
def list_resources(self, parent, typename): assert(typename == "SFAPNode" or not typename) assert(parent == None) list_resources = self.__sfi.bootstrap.server_proxy(self.__sfi.sm_url).ListResources(self.__credentials,self.__options) self.__sfi.bootstrap.server_proxy(self.__sfi.sm_url) logger.debug( "ListResources at %s returned : %s"%(self.__sfi.sm_url,list_resources['value'])) rspec = RSpec(list_resources['value']) nodes = rspec.version.get_nodes() networks = rspec.version.get_networks() for node in nodes: version = {'namespace': None, 'version': '1', 'type': 'SFA', 'extensions': [], 'schema': None} rspec_tmp = RSpec(version = version) rspec_tmp.version.add_network(networks[0]['name']) rspec_tmp.version.add_nodes([node]) component_name = '' component_name = node['component_name'] rspec_tmp.version.add_slivers(hostnames = [component_name]) rspec_tmp_xml = RSpecConverter.to_sfa_rspec(rspec_tmp.toxml()) self.__instances.add(component_name) rspec_xml = {} rspec_xml['xmlRspec'] = rspec_tmp_xml self.__rspecs['/SFAPNode-%s' %component_name] = rspec_xml logger.debug("PNodes %s " %component_name) logger.debug(self.__rspecs) return [ Identifier("/SFAPNode-%s" %i) for i in self.__instances ]
def describe(self, urns, version=None, options=None): if options is 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) # Update connection for the current user xrn = Xrn(urns[0], type='slice') user_name = xrn.get_authority_hrn() + '.' + xrn.leaf.split('-')[0] tenant_name = OSXrn(xrn=urns[0], type='slice').get_hrn() self.driver.shell.compute_manager.connect(username=user_name, tenant=tenant_name, password=user_name) # For delay to collect instance info time.sleep(3) # Get instances from the Openstack instances = self.get_instances(xrn) # Add sliver(s) from instance(s) geni_slivers = [] rspec.xml.set( 'expires', datetime_to_string(utcparse(time.time())) ) rspec_nodes = [] for instance in instances: rspec_nodes.append(self.instance_to_rspec_node(instance)) geni_sliver = self.instance_to_geni_sliver(instance) geni_slivers.append(geni_sliver) rspec.version.add_nodes(rspec_nodes) result = { 'geni_urn': xrn.get_urn(), 'geni_rspec': rspec.toxml(), 'geni_slivers': geni_slivers } return result
def Provision(self, api, xrn, creds, options): call_id = options.get('call_id') if Callids().already_handled(call_id): return "" version_manager = VersionManager() def _Provision(aggregate, server, xrn, credential, options): tStart = time.time() try: # Need to call GetVersion at an aggregate to determine the supported # rspec type/format beofre calling CreateSliver at an Aggregate. server_version = api.get_cached_server_version(server) result = server.Provision(xrn, credential, options) return {"aggregate": aggregate, "result": result, "elapsed": time.time()-tStart, "status": "success"} except: logger.log_exc('Something wrong in _Allocate with URL %s'%server.url) return {"aggregate": aggregate, "elapsed": time.time()-tStart, "status": "exception", "exc_info": sys.exc_info()} # attempt to use delegated credential first cred = api.getDelegatedCredential(creds) if not cred: cred = api.getCredential() # get the callers hrn valid_cred = api.auth.checkCredentials(creds, 'createsliver', xrn)[0] caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn() multiclient = MultiClient() for aggregate in api.aggregates: # prevent infinite loop. Dont send request back to caller # unless the caller is the aggregate's SM if caller_hrn == aggregate and aggregate != api.hrn: continue interface = api.aggregates[aggregate] server = api.server_proxy(interface, cred) # Just send entire RSpec to each aggregate multiclient.run(_Provision, aggregate, server, xrn, [cred], options) results = multiclient.get_results() # Set the manifest of KOREN manifest_version = version_manager._get_version('KOREN', '1', 'manifest') # manifest_version = version_manager._get_version('GENI', '3', 'manifest') result_rspec = RSpec(version=manifest_version) geni_slivers = [] geni_urn = None for result in results: self.add_slicemgr_stat(result_rspec, "Provision", result["aggregate"], result["elapsed"], result["status"], result.get("exc_info",None)) if result["status"]=="success": try: res = result['result']['value'] geni_urn = res['geni_urn'] result_rspec.version.merge(ReturnValue.get_value(res['geni_rspec'])) geni_slivers.extend(res['geni_slivers']) except: api.logger.log_exc("SM.Provision: Failed to merge aggregate rspec") return { 'geni_urn': geni_urn, 'geni_rspec': result_rspec.toxml(), 'geni_slivers': geni_slivers }
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=version, user_options=options) nodes = self.get_aggregate_nodes() rspec.version.add_nodes(nodes) return rspec.toxml()
def Provision(self, api, xrn, creds, options): call_id = options.get('call_id') if Callids().already_handled(call_id): return "" version_manager = VersionManager() def _Provision(aggregate, server, xrn, credential, options): tStart = time.time() try: # Need to call GetVersion at an aggregate to determine the supported # rspec type/format beofre calling CreateSliver at an Aggregate. server_version = api.get_cached_server_version(server) result = server.Provision(xrn, credential, options) return {"aggregate": aggregate, "result": result, "elapsed": time.time()-tStart, "status": "success"} except: logger.log_exc('Something wrong in _Allocate with URL %s'%server.url) return {"aggregate": aggregate, "elapsed": time.time()-tStart, "status": "exception", "exc_info": sys.exc_info()} # attempt to use delegated credential first cred = api.getDelegatedCredential(creds) if not cred: cred = api.getCredential() # get the callers hrn valid_cred = api.auth.checkCredentials(creds, 'createsliver', xrn)[0] caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn() multiclient = MultiClient() for aggregate in api.aggregates: # prevent infinite loop. Dont send request back to caller # unless the caller is the aggregate's SM if caller_hrn == aggregate and aggregate != api.hrn: continue interface = api.aggregates[aggregate] server = api.server_proxy(interface, cred) # Just send entire RSpec to each aggregate multiclient.run(_Provision, aggregate, server, xrn, [cred], options) results = multiclient.get_results() manifest_version = version_manager._get_version('GENI', '3', 'manifest') result_rspec = RSpec(version=manifest_version) geni_slivers = [] geni_urn = None for result in results: self.add_slicemgr_stat(result_rspec, "Provision", result["aggregate"], result["elapsed"], result["status"], result.get("exc_info",None)) if result["status"]=="success": try: res = result['result']['value'] geni_urn = res['geni_urn'] result_rspec.version.merge(ReturnValue.get_value(res['geni_rspec'])) geni_slivers.extend(res['geni_slivers']) except: api.logger.log_exc("SM.Provision: Failed to merge aggregate rspec") return { 'geni_urn': geni_urn, 'geni_rspec': result_rspec.toxml(), 'geni_slivers': geni_slivers }
def to_sfa_rspec(rspec, content_type=None): if not isinstance(rspec, RSpec): pg_rspec = RSpec(rspec) else: pg_rspec = rspec version_manager = VersionManager() sfa_version = version_manager._get_version('sfa', '1') sfa_rspec = RSpec(version=sfa_version) #nodes = pg_rspec.version.get_nodes() #sfa_rspec.version.add_nodes(nodes()) #sfa_rspec.version.add_links(pg_rspec.version.get_links()) #return sfa_rspec.toxml() # get network networks = pg_rspec.version.get_networks() network_hrn = networks[0]["name"] network_element = sfa_rspec.xml.add_element('network', name=network_hrn, id=network_hrn) # get nodes pg_nodes_elements = pg_rspec.version.get_nodes() nodes_with_slivers = pg_rspec.version.get_nodes_with_slivers() i = 1 for pg_node in pg_nodes_elements: attribs = dict(pg_node.items()) attribs['id'] = 'n' + str(i) node_element = network_element.add_element('node') for attrib in attribs: if type(attribs[attrib]) == str: node_element.set(attrib, attribs[attrib]) urn = pg_node["component_id"] if urn: if type(urn) == list: # legacy code, not sure if urn is ever a list... urn = urn[0] hostname = Xrn.urn_split(urn)[-1] hostname_element = node_element.add_element('hostname') hostname_element.set_text(hostname) if hostname in nodes_with_slivers: node_element.add_element('sliver') for hardware_type in pg_node["hardware_types"]: if "name" in hardware_type: node_element.add_element("hardware_type", name=hardware_type["name"]) # just copy over remaining child elements #for child in pg_node_element.getchildren(): # node_element.append(transform(child).getroot()) i = i + 1 return sfa_rspec.toxml()
def list_resources(self, version = None, options=None): """ Returns an advertisement Rspec of available resources at this aggregate. This Rspec contains a resource listing along with their description, providing sufficient information for clients to be able to select among available resources. :param options: various options. The valid options are: {boolean geni_compressed <optional>; struct geni_rspec_version { string type; #case insensitive , string version; # case insensitive}} . The only mandatory options if options is specified is geni_rspec_version. :type options: dictionary :returns: On success, the value field of the return struct will contain a geni.rspec advertisment RSpec :rtype: Rspec advertisement in xml. .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#RSpecdatatype .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3#ListResources """ if options is 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) # variable ldap_username to be compliant with get_all_leases # prototype. Now unused in geni-v3 since we are getting all the leases # here ldap_username = None if not options.get('list_leases') or options['list_leases'] != 'leases': # get nodes nodes_dict = self.get_nodes(options) # no interfaces on iotlab nodes # convert nodes to rspec nodes rspec_nodes = [] for node_id in nodes_dict: node = nodes_dict[node_id] rspec_node = self.node_to_rspec_node(node) 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(ldap_username) rspec.version.add_leases(leases) return rspec.toxml()
def list_resources(self, version=None, options={}): """ Returns an advertisement Rspec of available resources at this aggregate. This Rspec contains a resource listing along with their description, providing sufficient information for clients to be able to select among available resources. :param options: various options. The valid options are: {boolean geni_compressed <optional>; struct geni_rspec_version { string type; #case insensitive , string version; # case insensitive}} . The only mandatory options if options is specified is geni_rspec_version. :type options: dictionary :returns: On success, the value field of the return struct will contain a geni.rspec advertisment RSpec :rtype: Rspec advertisement in xml. .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#RSpecdatatype .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3#ListResources """ 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) # variable ldap_username to be compliant with get_all_leases # prototype. Now unused in geni-v3 since we are getting all the leases # here ldap_username = None if not options.get( 'list_leases') or options['list_leases'] != 'leases': # get nodes nodes_dict = self.get_nodes(options) # no interfaces on iotlab nodes # convert nodes to rspec nodes rspec_nodes = [] for node_id in nodes_dict: node = nodes_dict[node_id] rspec_node = self.node_to_rspec_node(node) 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(ldap_username) rspec.version.add_leases(leases) return rspec.toxml()
def get_rspec(self, slice_xrn=None, version=None, options={}): version_manager = VersionManager() version = version_manager.get_version(version) if not slice_xrn: rspec_version = version_manager._get_version(version.type, version.version, 'ad') nodes = self.get_aggregate_nodes() else: rspec_version = version_manager._get_version(version.type, version.version, 'manifest') nodes = self.get_slice_nodes(slice_xrn) rspec = RSpec(version=rspec_version, user_options=options) rspec.version.add_nodes(nodes) return rspec.toxml()
def to_sfa_rspec(rspec, content_type = None): if not isinstance(rspec, RSpec): pg_rspec = RSpec(rspec) else: pg_rspec = rspec version_manager = VersionManager() sfa_version = version_manager._get_version('sfa', '1') sfa_rspec = RSpec(version=sfa_version) #nodes = pg_rspec.version.get_nodes() #sfa_rspec.version.add_nodes(nodes()) #sfa_rspec.version.add_links(pg_rspec.version.get_links()) #return sfa_rspec.toxml() # get network networks = pg_rspec.version.get_networks() network_hrn = networks[0]["name"] network_element = sfa_rspec.xml.add_element('network', name=network_hrn, id=network_hrn) # get nodes pg_nodes_elements = pg_rspec.version.get_nodes() nodes_with_slivers = pg_rspec.version.get_nodes_with_slivers() i = 1 for pg_node in pg_nodes_elements: attribs = dict(pg_node.items()) attribs['id'] = 'n'+str(i) node_element = network_element.add_element('node') for attrib in attribs: if type(attribs[attrib]) == str: node_element.set(attrib, attribs[attrib]) urn = pg_node["component_id"] if urn: if type(urn)==list: # legacy code, not sure if urn is ever a list... urn = urn[0] hostname = Xrn.urn_split(urn)[-1] hostname_element = node_element.add_element('hostname') hostname_element.set_text(hostname) if hostname in nodes_with_slivers: node_element.add_element('sliver') for hardware_type in pg_node["hardware_types"]: if "name" in hardware_type: node_element.add_element("hardware_type", name=hardware_type["name"]) # just copy over remaining child elements #for child in pg_node_element.getchildren(): # node_element.append(transform(child).getroot()) i = i+1 return sfa_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 }
def create(self, opts, args): server = self.get_server_from_opts(opts) server_version = self.get_cached_server_version(server) slice_hrn = args[0] slice_urn = hrn_to_urn(slice_hrn, 'slice') user_cred = self.get_user_cred() slice_cred = self.get_slice_cred(slice_hrn).save_to_string(save_parents=True) # delegate the cred to the callers root authority delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority)+'.slicemanager') #delegated_cred = self.delegate_cred(slice_cred, get_authority(slice_hrn)) #creds.append(delegated_cred) rspec_file = self.get_rspec_file(args[1]) rspec = open(rspec_file).read() # need to pass along user keys to the aggregate. # users = [ # { urn: urn:publicid:IDN+emulab.net+user+alice # keys: [<ssh key A>, <ssh key B>] # }] users = [] slice_records = self.registry.Resolve(slice_urn, [user_cred.save_to_string(save_parents=True)]) if slice_records and 'researcher' in slice_records[0] and slice_records[0]['researcher']!=[]: slice_record = slice_records[0] user_hrns = slice_record['researcher'] user_urns = [hrn_to_urn(hrn, 'user') for hrn in user_hrns] user_records = self.registry.Resolve(user_urns, [user_cred.save_to_string(save_parents=True)]) if 'sfa' not in server_version: users = pg_users_arg(user_records) rspec = RSpec(rspec) rspec.filter({'component_manager_id': server_version['urn']}) rspec = RSpecConverter.to_pg_rspec(rspec.toxml(), content_type='request') creds = [slice_cred] else: users = sfa_users_arg(user_records, slice_record) creds = [slice_cred, delegated_cred] call_args = [slice_urn, creds, rspec, users] if self.server_supports_call_id_arg(server): call_args.append(unique_call_id()) result = server.CreateSliver(*call_args) if opts.file is None: print result else: save_rspec_to_file (result, opts.file) return result
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 = 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 rspec_nodes = [] for node in nodes: rspec_node = self.node_to_rspec_node(node, sites, interfaces, node_tags, pl_initscripts) 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_leases() rspec.version.add_leases(leases) return rspec.toxml()
def get_rspec(self, slice_xrn=None, version=None, options={}): version_manager = VersionManager() version = version_manager.get_version(version) if not slice_xrn: rspec_version = version_manager._get_version( version.type, version.version, 'ad') else: rspec_version = version_manager._get_version( version.type, version.version, 'manifest') slice, slivers = self.get_slice_and_slivers(slice_xrn) rspec = RSpec(version=rspec_version, user_options=options) if slice and 'expires' in slice: rspec.xml.set('expires', datetime_to_string(utcparse(slice['expires']))) if not options.get('list_leases') or options.get( 'list_leases') and options['list_leases'] != 'leases': nodes = self.get_nodes(slice_xrn, slice, slivers, options) rspec.version.add_nodes(nodes) # add sliver defaults default_sliver = slivers.get(None, []) if default_sliver: default_sliver_attribs = default_sliver.get('tags', []) for attrib in default_sliver_attribs: logger.info(attrib) rspec.version.add_default_sliver_attribute( attrib['tagname'], attrib['value']) # add wifi channels channels = self.get_channels(slice, options) rspec.version.add_channels(channels) if not options.get('list_leases') or options.get( 'list_leases') and options['list_leases'] != 'resources': leases_channels = self.get_leases_and_channels(slice, slice_xrn) rspec.version.add_leases(leases_channels) return rspec.toxml()
def _CreateSliver(aggregate, server, xrn, credential, rspec, users, options): tStart = time.time() try: # Need to call GetVersion at an aggregate to determine the supported # rspec type/format beofre calling CreateSliver at an Aggregate. server_version = api.get_cached_server_version(server) requested_users = users if 'sfa' not in server_version and 'geni_api' in server_version: # sfa aggregtes support both sfa and pg rspecs, no need to convert # if aggregate supports sfa rspecs. otherwise convert to pg rspec rspec = RSpec(RSpecConverter.to_pg_rspec(rspec, 'request')) filter = {'component_manager_id': server_version['urn']} rspec.filter(filter) rspec = rspec.toxml() requested_users = sfa_to_pg_users_arg(users) rspec = server.CreateSliver(xrn, credential, rspec, requested_users, options) return {"aggregate": aggregate, "rspec": rspec, "elapsed": time.time()-tStart, "status": "success"} except: logger.log_exc('Something wrong in _CreateSliver with URL %s'%server.url) return {"aggregate": aggregate, "elapsed": time.time()-tStart, "status": "exception", "exc_info": sys.exc_info()}
def to_sfa_rspec(rspec, content_type = None): if not isinstance(rspec, RSpec): pg_rspec = RSpec(rspec) else: pg_rspec = rspec version_manager = VersionManager() sfa_version = version_manager._get_version('sfa', '1') sfa_rspec = RSpec(version=sfa_version) # get network network_urn = pg_rspec.version.get_network() network, _ = urn_to_hrn(network_urn) network_element = sfa_rspec.xml.add_element('network', {'name': network, 'id': network}) # get nodes pg_nodes_elements = pg_rspec.version.get_node_elements() nodes_with_slivers = pg_rspec.version.get_nodes_with_slivers() i = 1 for pg_node_element in pg_nodes_elements: attribs = dict(pg_node_element.attrib.items()) attribs['id'] = 'n'+str(i) node_element = sfa_rspec.xml.add_element('node', attribs, parent=network_element) urn = pg_node_element.xpath('@component_id', namespaces=pg_rspec.namespaces) if urn: urn = urn[0] hostname = Xrn.urn_split(urn)[-1] hostname_element = sfa_rspec.xml.add_element('hostname', parent=node_element, text=hostname) if hostname in nodes_with_slivers: sfa_rspec.xml.add_element('sliver', parent=node_element) urn_element = sfa_rspec.xml.add_element('urn', parent=node_element, text=urn) # just copy over remaining child elements for child in pg_node_element.getchildren(): node_element.append(transform(child).getroot()) i = i+1 return sfa_rspec.toxml()
def describe(self, urns, version=None, options=None): if options is 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}
def Describe(self, api, creds, xrns, options): def _Describe(server, xrn, creds, options): return server.Describe(xrn, creds, options) call_id = options.get('call_id') if Callids().already_handled(call_id): return {} # attempt to use delegated credential first cred = api.getDelegatedCredential(creds) if not cred: cred = api.getCredential() multiclient = MultiClient() for aggregate in api.aggregates: interface = api.aggregates[aggregate] server = api.server_proxy(interface, cred) multiclient.run (_Describe, server, xrns, [cred], options) results = [ReturnValue.get_value(result) for result in multiclient.get_results()] # get rid of any void result - e.g. when call_id was hit, where by convention we return {} results = [ result for result in results if result and result.get('geni_urn')] # do not try to combine if there's no result if not results : return {} # otherwise let's merge stuff version_manager = VersionManager() manifest_version = version_manager._get_version('GENI', '3', 'manifest') result_rspec = RSpec(version=manifest_version) geni_slivers = [] geni_urn = None for result in results: try: geni_urn = result['geni_urn'] result_rspec.version.merge(ReturnValue.get_value(result['geni_rspec'])) geni_slivers.extend(result['geni_slivers']) except: api.logger.log_exc("SM.Provision: Failed to merge aggregate rspec") return { 'geni_urn': geni_urn, 'geni_rspec': result_rspec.toxml(), 'geni_slivers': geni_slivers }
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) # get nodes nodes = self.get_nodes(options) nodes_dict = {} for node in nodes: nodes_dict[node['node_id']] = node # convert nodes to rspec nodes rspec_nodes = [] for node in nodes: rspec_node = self.node_to_rspec_node(node) rspec_nodes.append(rspec_node) rspec.version.add_nodes(rspec_nodes) return rspec.toxml()
def list_resources(self, version = None, options=None): if options is 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 = 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 rspec_nodes = [] for node in nodes: rspec_node = self.node_to_rspec_node(node, sites, interfaces, node_tags, pl_initscripts) 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_leases() rspec.version.add_leases(leases) return rspec.toxml()
def get_rspec(self, slice_xrn=None, version = None, options=None): if options is None: options={} version_manager = VersionManager() version = version_manager.get_version(version) if not slice_xrn: rspec_version = version_manager._get_version(version.type, version.version, 'ad') else: rspec_version = version_manager._get_version(version.type, version.version, 'manifest') slice, slivers = self.get_slice_and_slivers(slice_xrn) rspec = RSpec(version=rspec_version, user_options=options) if slice and 'expires' in slice: rspec.xml.set('expires', datetime_to_string(utcparse(slice['expires']))) if not options.get('list_leases') or options.get('list_leases') and options['list_leases'] != 'leases': nodes = self.get_nodes(slice_xrn, slice, slivers, options) rspec.version.add_nodes(nodes) # add sliver defaults default_sliver = slivers.get(None, []) if default_sliver: default_sliver_attribs = default_sliver.get('tags', []) for attrib in default_sliver_attribs: logger.info(attrib) rspec.version.add_default_sliver_attribute(attrib['tagname'], attrib['value']) # add wifi channels channels = self.get_channels(slice, options) rspec.version.add_channels(channels) if not options.get('list_leases') or options.get('list_leases') and options['list_leases'] != 'resources': leases_channels = self.get_leases_and_channels(slice, slice_xrn) rspec.version.add_leases(leases_channels) return rspec.toxml()
if command.opts.infile: attrs = command.get_attribute_dict() rspec = RSpec(command.opts.infile) nodes = [] if command.opts.nodefile: f = open(command.opts.nodefile, "r") nodes = f.read().split() f.close() for name in attrs: print >> sys.stderr, name, attrs[name] for value in attrs[name]: if not nodes: try: rspec.version.remove_default_sliver_attribute(name, value) except: logger.log_exc( "sfiDeleteAttribute FAILED on all nodes: %s=%s" % (name, value)) else: for node in nodes: try: rspec.version.remove_sliver_attribute( node, name, value) except: logger.log_exc( "sfiDeleteAttribute FAILED on node %s: %s=%s" % (node, name, value)) print rspec.toxml()
def get_rspec(self, slice_xrn=None, login=None, version=None, options=None): """ Returns xml rspec: - a full advertisement rspec with the testbed resources if slice_xrn is not specified.If a lease option is given, also returns the leases scheduled on the testbed. - a manifest Rspec with the leases and nodes in slice's leases if slice_xrn is not None. :param slice_xrn: srn of the slice :type slice_xrn: string :param login: user'uid (ldap login) on cortexlab :type login: string :param version: can be set to sfa or cortexlab :type version: RSpecVersion :param options: used to specify if the leases should also be included in the returned rspec. :type options: dict :returns: Xml Rspec. :rtype: XML """ ldap_username = None rspec = None version_manager = VersionManager() version = version_manager.get_version(version) logger.debug("CortexlabAggregate \t get_rspec ***version %s \ version.type %s version.version %s options %s \r\n" % (version, version.type, version.version, options)) if slice_xrn is None: rspec_version = version_manager._get_version( version.type, version.version, 'ad') else: rspec_version = version_manager._get_version( version.type, version.version, 'manifest') slices, slivers = self.get_slice_and_slivers(slice_xrn, login) if slice_xrn and slices is not None: #Get user associated with this slice #for one_slice in slices : ldap_username = self.find_ldap_username_from_slice(slices[0]) # ldap_username = slices[0]['reg_researchers'][0].__dict__['hrn'] # # ldap_username = slices[0]['user'] # tmp = ldap_username.split('.') # ldap_username = tmp[1] logger.debug("CortexlabAggregate \tget_rspec **** \ LDAP USERNAME %s \r\n" \ % (ldap_username)) #at this point sliver may be empty if no cortexlab job #is running for this user/slice. rspec = RSpec(version=rspec_version, user_options=options) logger.debug("\r\n \r\n CortexlabAggregate \tget_rspec *** \ slice_xrn %s slices %s\r\n \r\n" % (slice_xrn, slices)) if options is not None: lease_option = options['list_leases'] else: #If no options are specified, at least print the resources lease_option = 'all' #if slice_xrn : #lease_option = 'all' if lease_option in ['all', 'resources']: #if not options.get('list_leases') or options.get('list_leases') #and options['list_leases'] != 'leases': nodes = self.get_nodes() logger.debug("\r\n") logger.debug("CortexlabAggregate \t lease_option %s \ get rspec ******* nodes %s" % (lease_option, nodes)) sites_set = set([node['location']['site'] for node in nodes]) #In case creating a job, slice_xrn is not set to None rspec.version.add_nodes(nodes) if slice_xrn and slices is not None: # #Get user associated with this slice # #for one_slice in slices : # ldap_username = slices[0]['reg_researchers'] # # ldap_username = slices[0]['user'] # tmp = ldap_username.split('.') # ldap_username = tmp[1] # # ldap_username = tmp[1].split('_')[0] logger.debug("CortexlabAggregate \tget_rspec **** \ version type %s ldap_ user %s \r\n" \ % (version.type, ldap_username)) #TODO : Change the version of Rspec here in case of pbm -SA 09/01/14 if version.type in ["Cortexlab", "Iotlab"]: rspec.version.add_connection_information( ldap_username, sites_set) default_sliver = slivers.get('default_sliver', []) if default_sliver and len(nodes) is not 0: #default_sliver_attribs = default_sliver.get('tags', []) logger.debug("CortexlabAggregate \tget_rspec **** \ default_sliver%s \r\n" % (default_sliver)) for attrib in default_sliver: rspec.version.add_default_sliver_attribute( attrib, default_sliver[attrib]) if lease_option in ['all', 'leases']: leases = self.get_all_leases(ldap_username) rspec.version.add_leases(leases) logger.debug("CortexlabAggregate \tget_rspec **** \ FINAL RSPEC %s \r\n" % (rspec.toxml())) return rspec.toxml()
def build_rspec(cls, slice_urn, resources, leases, flowspace, vms, rspec_version='GENI 3 request'): """ Builds a RSpecs based on the specified resources and leases. Args: slice_urn (string) : the urn of the slice [UNUSED] [HRN in NITOS ?] Returns: string : the string version of the created RSpec. """ import time start_time = None end_time = None # Default duration for WiLab is 2 hours duration_default = 120 for lease in leases: if 'end_time' in lease: end_time = lease['end_time'] start_time = lease['start_time'] break if start_time is None: # start_time = Now start_time = time.time() if end_time is None: end_time = int(start_time + duration_default*60) #raise Exception, "end_time is mandatory in leases" # duration in seconds from now till end_time duration = end_time - start_time # duration in minutes duration = duration / 60 duration = int(duration) if duration < duration_default: duration = duration_default Log.tmp("start_time = ",start_time) Log.tmp("end_time = ",end_time) Log.tmp("duration = ",duration) # RSpec will have expires date = now + duration rspec = RSpec(version=rspec_version, ttl=duration, expires=end_time) nodes = [] channels = [] links = [] # XXX Here it is only about mappings and hooks between ontologies i = 0 for urn in resources: # XXX TO BE CORRECTED, this handles None values if not urn: continue resource = dict() # TODO: take into account the case where we send a dict of URNs without keys #resource['component_id'] = resource.pop('urn') resource['component_id'] = urn resource_hrn, resource_type = urn_to_hrn(urn) # resource['component_id']) # build component_manager_id # The only change for WiLab compared to Generic SFAWrapParser cm = urn.split("+") resource['component_manager_id'] = "%s+%s+authority+cm" % (cm[0],cm[1]) #print "resource_type", resource_type if resource_type == 'node': #print "NODE", resource, cls resource['client_id'] = "PC" + str(i) resource = cls.on_build_resource_hook(resource) nodes.append(resource) elif resource_type == 'link': links.append(resource) elif resource_type == 'channel': channels.append(resource) else: raise Exception, "Not supported type of resource" i = i + 1 #for node in nodes: # print "NODE:", node rspec.version.add_nodes(nodes, rspec_content_type="request") #rspec.version.add_links(links) #rspec.version.add_channels(channels) #sfa_leases = cls.manifold_to_sfa_leases(leases, slice_urn) ##print "sfa_leases", sfa_leases #if sfa_leases: # # SFAWRAP BUG ??? # # rspec.version.add_leases bugs with an empty set of leases # # slice_id = leases[0]['slice_id'] # # TypeError: list indices must be integers, not str # rspec.version.add_leases(sfa_leases, []) # XXX Empty channels for now return rspec.toxml()
def describe(self, urns, version=None, options=None): """ describe method returns slice slivers (allocated resources) and leases (OAR job submission). We search in lease table of SFA database all OAR jobs id for this slice and match OAR jobs with state Waiting or Running. If OAR job id doesn't exist the experiment is terminated and we delete the database table entry. Otherwise we add slivers and leases in the response :returns: geni_slivers : a list of allocated slivers with information about their allocation and operational state geni_urn : the URN of the slice in which the sliver has been allocated geni_rspec: a RSpec describing the allocated slivers and leases :rtype: dict :Example: <rspec> ... <node component_manager_id="urn:publicid:IDN+iotlab+authority+sa" component_id= "urn:publicid:IDN+iotlab+node+m3-10.grenoble.iot-lab.info" client_id="m3-10.grenoble.iot-lab.info" sliver_id="urn:publicid:IDN+iotlab+sliver+9953-m3-10" exclusive="true" component_name="m3-10.grenoble.iot-lab.info"> <hardware_type name="iotlab-node"/> <location country="France"/> <granularity grain="30"/> <sliver_type name="iotlab-exclusive"/> </node> <lease slice_id="urn:publicid:IDN+onelab:inria+slice+test_iotlab" start_time="1427792428" duration="29"> <node component_id= "urn:publicid:IDN+iotlab+node+m3-10.grenoble.iot-lab.info"/> </lease> ... </rspec> """ # pylint:disable=R0914,W0212 logger.warning("iotlabaggregate describe") logger.warning("iotlabaggregate describe urns : %s" % urns) if not options: 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) xrn = Xrn(urns[0]) geni_slivers = [] nodes = self.driver.shell.get_nodes() reserved_nodes = self.driver.shell.get_reserved_nodes() if not "error" in nodes and not "error" in reserved_nodes: # find OAR jobs id for one slice in SFA database db_leases = [ (lease.job_id, lease.slice_hrn) for lease in self.driver.api.dbsession().query(LeaseTable).filter(LeaseTable.slice_hrn == xrn.hrn).all() ] leases = [] for job_id, slice_hrn in db_leases: # OAR job terminated, we delete entry in database if not job_id in reserved_nodes: self._delete_db_lease(job_id) else: # onelab slice = job submission from OneLAB lease = reserved_nodes[job_id] lease["slice_id"] = hrn_to_urn(slice_hrn, "slice") leases.append(lease) # get slivers slivers = self.get_slivers(urns, leases, nodes) if slivers: date = utcparse(slivers[0]["expires"]) rspec_expires = datetime_to_string(date) else: rspec_expires = datetime_to_string(utcparse(time.time())) rspec.xml.set("expires", rspec_expires) rspec_nodes = [] for sliver in slivers: rspec_node = self.sliver_to_rspec_node(sliver) rspec_nodes.append(rspec_node) geni_sliver = self.rspec_node_to_geni_sliver(rspec_node) geni_slivers.append(geni_sliver) logger.warning("iotlabaggregate describe geni_slivers %s" % geni_slivers) rspec.version.add_nodes(rspec_nodes) rspec_leases = self.leases_to_rspec_leases(leases) logger.warning("iotlabaggregate describe rspec_leases %s" % rspec_leases) rspec.version.add_leases(rspec_leases) return {"geni_urn": urns[0], "geni_rspec": rspec.toxml(), "geni_slivers": geni_slivers}
def describe(self, urns, version=None, options=None): """ Retrieve a manifest RSpec describing the resources contained by the named entities, e.g. a single slice or a set of the slivers in a slice. This listing and description should be sufficiently descriptive to allow experimenters to use the resources. :param urns: If a slice urn is supplied and there are no slivers in the given slice at this aggregate, then geni_rspec shall be a valid manifest RSpec, containing no node elements - no resources. :type urns: list or strings :param options: various options. the valid options are: {boolean geni_compressed <optional>; struct geni_rspec_version { string type; #case insensitive , string version; # case insensitive}} :type options: dictionary :returns: On success returns the following dictionary {geni_rspec: <geni.rspec, a Manifest RSpec>, geni_urn: <string slice urn of the containing slice>, geni_slivers:{ geni_sliver_urn: <string sliver urn>, geni_expires: <dateTime.rfc3339 allocation expiration string, as in geni_expires from SliversStatus>, geni_allocation_status: <string sliver state - e.g. geni_allocated or geni_provisioned >, geni_operational_status: <string sliver operational state>, geni_error: <optional string. The field may be omitted entirely but may not be null/None, explaining any failure for a sliver.>} .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3#Describe .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#urns """ if options is 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) query = self.driver.api.dbsession().query(SliverAllocation) sliver_allocations = query.filter((constraint)).all() sliver_allocation_dict = {} for sliver_allocation in sliver_allocations: geni_urn = sliver_allocation.slice_urn sliver_allocation_dict[sliver_allocation.sliver_id] = \ sliver_allocation if not options.get('list_leases') or options['list_leases'] != 'leases': # 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) if not options.get('list_leases') or options['list_leases'] == 'resources': if slivers: leases = self.get_leases(slivers[0]) rspec.version.add_leases(leases) return {'geni_urn': geni_urn, 'geni_rspec': rspec.toxml(), 'geni_slivers': geni_slivers}
def Allocate(self, api, xrn, creds, rspec_str, expiration, options): call_id = options.get('call_id') if Callids().already_handled(call_id): return "" version_manager = VersionManager() def _Allocate(aggregate, server, xrn, credential, rspec, options): tStart = time.time() try: # Need to call GetVersion at an aggregate to determine the supported # rspec type/format beofre calling CreateSliver at an Aggregate. #server_version = api.get_cached_server_version(server) #if 'sfa' not in server_version and 'geni_api' in server_version: # sfa aggregtes support both sfa and pg rspecs, no need to convert # if aggregate supports sfa rspecs. otherwise convert to pg rspec #rspec = RSpec(RSpecConverter.to_pg_rspec(rspec, 'request')) #filter = {'component_manager_id': server_version['urn']} #rspec.filter(filter) #rspec = rspec.toxml() result = server.Allocate(xrn, credential, rspec, options) return {"aggregate": aggregate, "result": result, "elapsed": time.time()-tStart, "status": "success"} except: logger.log_exc('Something wrong in _Allocate with URL %s'%server.url) return {"aggregate": aggregate, "elapsed": time.time()-tStart, "status": "exception", "exc_info": sys.exc_info()} # Validate the RSpec against PlanetLab's schema --disabled for now # The schema used here needs to aggregate the PL and VINI schemas # schema = "/var/www/html/schemas/pl.rng" rspec = RSpec(rspec_str) # schema = None # if schema: # rspec.validate(schema) # if there is a <statistics> section, the aggregates don't care about it, # so delete it. self.drop_slicemgr_stats(rspec) # attempt to use delegated credential first cred = api.getDelegatedCredential(creds) if not cred: cred = api.getCredential() # get the callers hrn hrn, type = urn_to_hrn(xrn) valid_cred = api.auth.checkCredentials(creds, 'createsliver', hrn)[0] caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn() multiclient = MultiClient() for aggregate in api.aggregates: # prevent infinite loop. Dont send request back to caller # unless the caller is the aggregate's SM if caller_hrn == aggregate and aggregate != api.hrn: continue interface = api.aggregates[aggregate] server = api.server_proxy(interface, cred) # Just send entire RSpec to each aggregate multiclient.run(_Allocate, aggregate, server, xrn, [cred], rspec.toxml(), options) results = multiclient.get_results() manifest_version = version_manager._get_version(rspec.version.type, rspec.version.version, 'manifest') result_rspec = RSpec(version=manifest_version) geni_urn = None geni_slivers = [] for result in results: self.add_slicemgr_stat(result_rspec, "Allocate", result["aggregate"], result["elapsed"], result["status"], result.get("exc_info",None)) if result["status"]=="success": try: res = result['result']['value'] geni_urn = res['geni_urn'] result_rspec.version.merge(ReturnValue.get_value(res['geni_rspec'])) geni_slivers.extend(res['geni_slivers']) except: api.logger.log_exc("SM.Allocate: Failed to merge aggregate rspec") return { 'geni_urn': geni_urn, 'geni_rspec': result_rspec.toxml(), 'geni_slivers': geni_slivers }
def build_sfa_rspec(self, slice_id, resources, properties, leases): """ Build the XML RSpec from list of resources' urns. eg. resources = ["urn:publicid:IDN+ple:modenaple+node+planetlab-1.ing.unimo.it"] """ #if isinstance(resources, str): # resources = eval(resources) # rspec_type and rspec_version should be set in the config of the platform, # we use GENIv3 as default one if not if self.config: if 'rspec_type' and 'rspec_version' in self.config: rspec_version = self.config['rspec_type'] + ' ' + self.config['rspec_version'] else: rspec_version = 'GENI 3' # extend rspec version with "content_type" rspec_version += ' request' rspec = RSpec(version=rspec_version) nodes = [] channels = [] links = [] self._log.debug("Building RSpec for resources %s" % resources) cardinal = 0 wilab = False for urn in resources: # XXX TO BE CORRECTED, this handles None values if not urn: continue self._log.debug(urn) resource = dict() # TODO: take into account the case where we send a dict of URNs without keys #resource['component_id'] = resource.pop('urn') resource['component_id'] = urn resource_hrn, resource_type = urn_to_hrn(resource['component_id']) # build component_manager_id top_auth = resource_hrn.split('.')[0] cm = urn.split("+") resource['component_manager_id'] = "%s+%s+authority+cm" % (cm[0],top_auth) if resource_type == 'node': # XXX dirty hack WiLab !!! # Commented Lucia, doesn't work for wilabt # if self.config: # if 'wilab2' in self.config['sm']: # resource['client_id'] = "PC" # resource['sliver_type'] = "raw-pc" if 'wilab2' in urn: wilab = True resource['client_id'] = "node%s" % cardinal resource['sliver_type'] = "raw-pc" resource['disk_image'] = "hola" top_auth = resource_hrn.replace("\\", "").split('.') top_auth.pop() top_auth = '.'.join(top_auth) cm = urn.split("+") resource['component_manager_id'] = "%s+%s+authority+cm" % (cm[0],top_auth) cardinal += 1 nodes.append(resource) elif resource_type == 'link': links.append(resource) elif resource_type == 'channel': channels.append(resource) else: raise Exception, "Not supported type of resource" rspec.version.add_nodes(nodes, rspec_content_type="request") #rspec.version.add_leases(leases) #rspec.version.add_links(links) #rspec.version.add_channels(channels) #self._log.debug("request rspec: %s"%rspec.toxml()) string = rspec.toxml() if wilab and properties is not None: ## dirty hack for the f4f demo b = string.split('\n') for i, n in enumerate(b): if 'sliver_type name="raw-pc"' in n: b[i] = '<sliver_type name="raw-pc">' b.insert(i+1, '<disk_image name="urn:publicid:IDN+wall2.ilabt.iminds.be+image+emulab-ops//%s"/>' % properties['disk_image']) #b.insert(i+1, '<disk_image name="urn:publicid:IDN+wilab2.ilabt.iminds.be+image+nepi:%s"/>' % properties['disk_image']) b.insert(i+2, '</sliver_type>') string = ''.join(b) self._log.debug("request rspec : %s" % string) return string
def list_resources(self, version=None, options=None): """ list_resources method sends a RSpec with all Iot-LAB testbed nodes and leases (OAR job submission). For leases we get all OAR jobs with state Waiting or Running. If we have an entry in SFA database (lease table) with OAR job id this submission was launched by SFA driver, otherwise it was launched by Iot-LAB Webportal or CLI-tools :Example: <rspec> ... <node component_manager_id="urn:publicid:IDN+iotlab+authority+sa" component_id= "urn:publicid:IDN+iotlab+node+m3-10.devgrenoble.iot-lab.info" exclusive="true" component_name="m3-10.devgrenoble.iot-lab.info"> <hardware_type name="iotlab-node"/> <location country="France"/> <granularity grain="60"/> ... </node> ... <lease slice_id="urn:publicid:IDN+onelab:inria+slice+test_iotlab" start_time="1427792400" duration="30"> <node component_id= "urn:publicid:IDN+iotlab+node+m3-10.grenoble.iot-lab.info"/> </lease> ... </rspec> """ # pylint:disable=R0914,W0212 logger.warning("iotlabaggregate list_resources") logger.warning("iotlabaggregate list_resources options %s" % options) if not options: 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) nodes = self.driver.shell.get_nodes() reserved_nodes = self.driver.shell.get_reserved_nodes() if not "error" in nodes and not "error" in reserved_nodes: # convert nodes to rspec nodes rspec_nodes = [] for node in nodes: rspec_node = self.node_to_rspec_node(nodes[node]) rspec_nodes.append(rspec_node) rspec.version.add_nodes(rspec_nodes) leases = [] db_leases = {} # find OAR jobs id for all slices in SFA database for lease in self.driver.api.dbsession().query(LeaseTable).all(): db_leases[lease.job_id] = lease.slice_hrn for lease_id in reserved_nodes: # onelab slice = job submission from OneLAB if lease_id in db_leases: reserved_nodes[lease_id]["slice_id"] = hrn_to_urn(db_leases[lease_id], "slice") # iotlab slice = job submission from Iot-LAB else: reserved_nodes[lease_id]["slice_id"] = hrn_to_urn( self.driver.root_auth + "." + reserved_nodes[lease_id]["owner"] + "_slice", "slice" ) leases.append(reserved_nodes[lease_id]) rspec_leases = self.leases_to_rspec_leases(leases) logger.warning("iotlabaggregate list_resources rspec_leases %s" % rspec_leases) rspec.version.add_leases(rspec_leases) return rspec.toxml()
def describe(self, urns, version=None, options=None): if options is 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 if not options.get('list_leases') or options['list_leases'] != 'leases': # add slivers site_ids = [] interface_ids = [] tag_ids = [] nodes_dict = {} for sliver in slivers: site_ids.append(sliver['site_id']) interface_ids.extend(sliver['interface_ids']) tag_ids.extend(sliver['node_tag_ids']) nodes_dict[sliver['node_id']] = sliver 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() rspec_nodes = [] for sliver in slivers: if sliver['slice_ids_whitelist'] and sliver['slice_id'] not in sliver['slice_ids_whitelist']: continue rspec_node = self.sliver_to_rspec_node(sliver, sites, interfaces, node_tags, pl_initscripts, sliver_allocation_dict) # manifest node element shouldn't contain available attribute rspec_node.pop('available') 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) # add sliver defaults #default_sliver = slivers.get(None, []) #if default_sliver: # default_sliver_attribs = default_sliver.get('tags', []) # for attrib in default_sliver_attribs: # rspec.version.add_default_sliver_attribute(attrib['tagname'], attrib['value']) # add links links = self.get_links(sites, nodes_dict, interfaces) rspec.version.add_links(links) if not options.get('list_leases') or options['list_leases'] != 'resources': if slivers: leases = self.get_leases(slivers[0]) rspec.version.add_leases(leases) return {'geni_urn': geni_urn, 'geni_rspec': rspec.toxml(), 'geni_slivers': geni_slivers}
def CreateSliver(api, xrn, creds, rspec_str, users, call_id): version_manager = VersionManager() def _CreateSliver(aggregate, server, xrn, credential, rspec, users, call_id): tStart = time.time() try: # Need to call GetVersion at an aggregate to determine the supported # rspec type/format beofre calling CreateSliver at an Aggregate. server_version = api.get_cached_server_version(server) requested_users = users if 'sfa' not in server_version and 'geni_api' in server_version: # sfa aggregtes support both sfa and pg rspecs, no need to convert # if aggregate supports sfa rspecs. otherwise convert to pg rspec rspec = RSpec(RSpecConverter.to_pg_rspec(rspec, 'request')) filter = {'component_manager_id': server_version['urn']} rspec.filter(filter) rspec = rspec.toxml() requested_users = sfa_to_pg_users_arg(users) args = [xrn, credential, rspec, requested_users] if _call_id_supported(api, server): args.append(call_id) rspec = server.CreateSliver(*args) return {"aggregate": aggregate, "rspec": rspec, "elapsed": time.time()-tStart, "status": "success"} except: logger.log_exc('Something wrong in _CreateSliver with URL %s'%server.url) return {"aggregate": aggregate, "elapsed": time.time()-tStart, "status": "exception"} if Callids().already_handled(call_id): return "" # Validate the RSpec against PlanetLab's schema --disabled for now # The schema used here needs to aggregate the PL and VINI schemas # schema = "/var/www/html/schemas/pl.rng" rspec = RSpec(rspec_str) schema = None if schema: rspec.validate(schema) # if there is a <statistics> section, the aggregates don't care about it, # so delete it. drop_slicemgr_stats(rspec) # attempt to use delegated credential first cred = api.getDelegatedCredential(creds) if not cred: cred = api.getCredential() # get the callers hrn hrn, type = urn_to_hrn(xrn) valid_cred = api.auth.checkCredentials(creds, 'createsliver', hrn)[0] caller_hrn = Credential(string=valid_cred).get_gid_caller().get_hrn() threads = ThreadManager() for aggregate in api.aggregates: # prevent infinite loop. Dont send request back to caller # unless the caller is the aggregate's SM if caller_hrn == aggregate and aggregate != api.hrn: continue interface = api.aggregates[aggregate] server = api.get_server(interface, cred) # Just send entire RSpec to each aggregate threads.run(_CreateSliver, aggregate, server, xrn, [cred], rspec.toxml(), users, call_id) results = threads.get_results() manifest_version = version_manager._get_version(rspec.version.type, rspec.version.version, 'manifest') result_rspec = RSpec(version=manifest_version) for result in results: add_slicemgr_stat(result_rspec, "CreateSliver", result["aggregate"], result["elapsed"], result["status"]) if result["status"]=="success": try: result_rspec.version.merge(result["rspec"]) except: api.logger.log_exc("SM.CreateSliver: Failed to merge aggregate rspec") return result_rspec.toxml()
def build_sfa_rspec(self, slice_id, resources, properties, leases): """ Build the XML RSpec from list of resources' urns. eg. resources = ["urn:publicid:IDN+ple:modenaple+node+planetlab-1.ing.unimo.it"] """ #if isinstance(resources, str): # resources = eval(resources) # rspec_type and rspec_version should be set in the config of the platform, # we use GENIv3 as default one if not if self.config: if 'rspec_type' and 'rspec_version' in self.config: rspec_version = self.config['rspec_type'] + ' ' + self.config[ 'rspec_version'] else: rspec_version = 'GENI 3' # extend rspec version with "content_type" rspec_version += ' request' rspec = RSpec(version=rspec_version) nodes = [] channels = [] links = [] self._log.debug("Building RSpec for resources %s" % resources) cardinal = 0 wilab = False for urn in resources: # XXX TO BE CORRECTED, this handles None values if not urn: continue self._log.debug(urn) resource = dict() # TODO: take into account the case where we send a dict of URNs without keys #resource['component_id'] = resource.pop('urn') resource['component_id'] = urn resource_hrn, resource_type = urn_to_hrn(resource['component_id']) # build component_manager_id top_auth = resource_hrn.split('.')[0] cm = urn.split("+") resource['component_manager_id'] = "%s+%s+authority+cm" % ( cm[0], top_auth) if resource_type == 'node': # XXX dirty hack WiLab !!! # Commented Lucia, doesn't work for wilabt # if self.config: # if 'wilab2' in self.config['sm']: # resource['client_id'] = "PC" # resource['sliver_type'] = "raw-pc" if 'wilab2' in urn: wilab = True resource['client_id'] = "node%s" % cardinal resource['sliver_type'] = "raw-pc" resource['disk_image'] = "hola" top_auth = resource_hrn.replace("\\", "").split('.') top_auth.pop() top_auth = '.'.join(top_auth) cm = urn.split("+") resource['component_manager_id'] = "%s+%s+authority+cm" % ( cm[0], top_auth) cardinal += 1 nodes.append(resource) elif resource_type == 'link': links.append(resource) elif resource_type == 'channel': channels.append(resource) else: raise Exception, "Not supported type of resource" rspec.version.add_nodes(nodes, rspec_content_type="request") #rspec.version.add_leases(leases) #rspec.version.add_links(links) #rspec.version.add_channels(channels) #self._log.debug("request rspec: %s"%rspec.toxml()) string = rspec.toxml() if wilab and properties is not None: ## dirty hack for the f4f demo b = string.split('\n') for i, n in enumerate(b): if 'sliver_type name="raw-pc"' in n: b[i] = '<sliver_type name="raw-pc">' b.insert( i + 1, '<disk_image name="urn:publicid:IDN+wall2.ilabt.iminds.be+image+emulab-ops//%s"/>' % properties['disk_image']) #b.insert(i+1, '<disk_image name="urn:publicid:IDN+wilab2.ilabt.iminds.be+image+nepi:%s"/>' % properties['disk_image']) b.insert(i + 2, '</sliver_type>') string = ''.join(b) self._log.debug("request rspec : %s" % string) return string
def build_rspec(cls, slice_urn, resources, leases, flowspace, vms, rspec_version='GENI 3 request'): """ Builds a RSpecs based on the specified resources and leases. Args: slice_urn (string) : the urn of the slice [UNUSED] [HRN in NITOS ?] Returns: string : the string version of the created RSpec. """ rspec = RSpec(version=rspec_version) nodes = [] channels = [] links = [] # XXX Here it is only about mappings and hooks between ontologies for urn in resources: # XXX TO BE CORRECTED, this handles None values if not urn: continue resource = dict() # TODO: take into account the case where we send a dict of URNs without keys #resource['component_id'] = resource.pop('urn') resource['component_id'] = urn resource_hrn, resource_type = urn_to_hrn(urn) # resource['component_id']) # build component_manager_id top_auth = resource_hrn.split('.')[0] cm = urn.split("+") resource['component_manager_id'] = "%s+%s+authority+cm" % (cm[0],top_auth) #print "resource_type", resource_type if resource_type == 'node': #print "NODE", resource, cls resource = cls.on_build_resource_hook(resource) nodes.append(resource) elif resource_type == 'link': links.append(resource) elif resource_type == 'channel': channels.append(resource) else: raise Exception, "Not supported type of resource" #for node in nodes: # print "NODE:", node rspec.version.add_nodes(nodes, rspec_content_type="request") #rspec.version.add_links(links) #rspec.version.add_channels(channels) sfa_leases = cls.manifold_to_sfa_leases(leases, slice_urn) #print "sfa_leases", sfa_leases if sfa_leases: # SFAWRAP BUG ??? # rspec.version.add_leases bugs with an empty set of leases # slice_id = leases[0]['slice_id'] # TypeError: list indices must be integers, not str rspec.version.add_leases(sfa_leases, []) # XXX Empty channels for now 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 if not options.get( 'list_leases') or options['list_leases'] != 'leases': # add slivers site_ids = [] interface_ids = [] tag_ids = [] nodes_dict = {} for sliver in slivers: site_ids.append(sliver['site_id']) interface_ids.extend(sliver['interface_ids']) tag_ids.extend(sliver['node_tag_ids']) nodes_dict[sliver['node_id']] = sliver 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() rspec_nodes = [] for sliver in slivers: if sliver['slice_ids_whitelist'] and sliver[ 'slice_id'] not in sliver['slice_ids_whitelist']: continue rspec_node = self.sliver_to_rspec_node(sliver, sites, interfaces, node_tags, pl_initscripts, sliver_allocation_dict) # manifest node element shouldn't contain available attribute rspec_node.pop('available') 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) # add sliver defaults #default_sliver = slivers.get(None, []) #if default_sliver: # default_sliver_attribs = default_sliver.get('tags', []) # for attrib in default_sliver_attribs: # rspec.version.add_default_sliver_attribute(attrib['tagname'], attrib['value']) # add links links = self.get_links(sites, nodes_dict, interfaces) rspec.version.add_links(links) if not options.get( 'list_leases') or options['list_leases'] != 'resources': if slivers: leases = self.get_leases(slivers[0]) rspec.version.add_leases(leases) return { 'geni_urn': geni_urn, 'geni_rspec': rspec.toxml(), 'geni_slivers': geni_slivers }
def describe(self, urns, version=None, options={}): """ Retrieve a manifest RSpec describing the resources contained by the named entities, e.g. a single slice or a set of the slivers in a slice. This listing and description should be sufficiently descriptive to allow experimenters to use the resources. :param urns: If a slice urn is supplied and there are no slivers in the given slice at this aggregate, then geni_rspec shall be a valid manifest RSpec, containing no node elements - no resources. :type urns: list or strings :param options: various options. the valid options are: {boolean geni_compressed <optional>; struct geni_rspec_version { string type; #case insensitive , string version; # case insensitive}} :type options: dictionary :returns: On success returns the following dictionary {geni_rspec: <geni.rspec, a Manifest RSpec>, geni_urn: <string slice urn of the containing slice>, geni_slivers:{ geni_sliver_urn: <string sliver urn>, geni_expires: <dateTime.rfc3339 allocation expiration string, as in geni_expires from SliversStatus>, geni_allocation_status: <string sliver state - e.g. geni_allocated or geni_provisioned >, geni_operational_status: <string sliver operational state>, geni_error: <optional string. The field may be omitted entirely but may not be null/None, explaining any failure for a sliver.>} .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3#Describe .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#urns """ 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] logger.debug(" Cortexlabaggregate.PY \tDescribe sliver_ids %s " % (sliver_ids)) constraint = SliverAllocation.sliver_id.in_(sliver_ids) query = self.driver.api.dbsession().query(SliverAllocation) sliver_allocations = query.filter((constraint)).all() logger.debug( " Cortexlabaggregate.PY \tDescribe sliver_allocations %s " % (sliver_allocations)) 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) logger.debug( " Cortexlabaggregate.PY \tDescribe sliver_allocation_dict %s " % (sliver_allocation_dict)) geni_sliver = self.rspec_node_to_geni_sliver( rspec_node, sliver_allocation_dict) geni_slivers.append(geni_sliver) logger.debug(" Cortexlabaggregate.PY \tDescribe rspec_nodes %s\ rspec %s " % (rspec_nodes, rspec)) rspec.version.add_nodes(rspec_nodes) return { 'geni_urn': geni_urn, 'geni_rspec': rspec.toxml(), 'geni_slivers': geni_slivers }
def get_rspec(self, slice_xrn=None, login=None, version=None, options=None): """ Returns xml rspec: - a full advertisement rspec with the testbed resources if slice_xrn is not specified.If a lease option is given, also returns the leases scheduled on the testbed. - a manifest Rspec with the leases and nodes in slice's leases if slice_xrn is not None. :param slice_xrn: srn of the slice :type slice_xrn: string :param login: user'uid (ldap login) on iotlab :type login: string :param version: can be set to sfa or iotlab :type version: RSpecVersion :param options: used to specify if the leases should also be included in the returned rspec. :type options: dict :returns: Xml Rspec. :rtype: XML """ ldap_username = None rspec = None version_manager = VersionManager() version = version_manager.get_version(version) logger.debug("IotlabAggregate \t get_rspec ***version %s \ version.type %s version.version %s options %s \r\n" % (version, version.type, version.version, options)) if slice_xrn is None: rspec_version = version_manager._get_version(version.type, version.version, 'ad') else: rspec_version = version_manager._get_version( version.type, version.version, 'manifest') slices, slivers = self.get_slice_and_slivers(slice_xrn, login) if slice_xrn and slices is not None: #Get user associated with this slice #for one_slice in slices : ldap_username = self.find_ldap_username_from_slice(slices[0]) # ldap_username = slices[0]['reg_researchers'][0].__dict__['hrn'] # # ldap_username = slices[0]['user'] # tmp = ldap_username.split('.') # ldap_username = tmp[1] logger.debug("IotlabAggregate \tget_rspec **** \ LDAP USERNAME %s \r\n" \ % (ldap_username)) #at this point sliver may be empty if no iotlab job #is running for this user/slice. rspec = RSpec(version=rspec_version, user_options=options) logger.debug("\r\n \r\n IotlabAggregate \tget_rspec *** \ slice_xrn %s slices %s\r\n \r\n" % (slice_xrn, slices)) if options is not None: lease_option = options['list_leases'] else: #If no options are specified, at least print the resources lease_option = 'all' #if slice_xrn : #lease_option = 'all' if lease_option in ['all', 'resources']: #if not options.get('list_leases') or options.get('list_leases') #and options['list_leases'] != 'leases': nodes = self.get_nodes() logger.debug("\r\n") logger.debug("IotlabAggregate \t lease_option %s \ get rspec ******* nodes %s" % (lease_option, nodes)) sites_set = set([node['location']['site'] for node in nodes]) #In case creating a job, slice_xrn is not set to None rspec.version.add_nodes(nodes) if slice_xrn and slices is not None: # #Get user associated with this slice # #for one_slice in slices : # ldap_username = slices[0]['reg_researchers'] # # ldap_username = slices[0]['user'] # tmp = ldap_username.split('.') # ldap_username = tmp[1] # # ldap_username = tmp[1].split('_')[0] logger.debug("IotlabAggregate \tget_rspec **** \ version type %s ldap_ user %s \r\n" \ % (version.type, ldap_username)) if version.type == "Iotlab": rspec.version.add_connection_information( ldap_username, sites_set) default_sliver = slivers.get('default_sliver', []) if default_sliver and len(nodes) is not 0: #default_sliver_attribs = default_sliver.get('tags', []) logger.debug("IotlabAggregate \tget_rspec **** \ default_sliver%s \r\n" % (default_sliver)) for attrib in default_sliver: rspec.version.add_default_sliver_attribute( attrib, default_sliver[attrib]) if lease_option in ['all','leases']: leases = self.get_all_leases(ldap_username) rspec.version.add_leases(leases) logger.debug("IotlabAggregate \tget_rspec **** \ FINAL RSPEC %s \r\n" % (rspec.toxml())) return rspec.toxml()
print "Missing link list -- exiting" command.parser.print_help() sys.exit(1) if command.opts.infile: infile = file(command.opts.infile) else: infile = sys.stdin if command.opts.outfile: outfile = file(command.opts.outfile, "w") else: outfile = sys.stdout ad_rspec = RSpec(infile) links = file(command.opts.linkfile).read().split('\n') link_tuples = map(lambda x: tuple(x.split()), links) version_manager = VersionManager() try: type = ad_rspec.version.type version_num = ad_rspec.version.version request_version = version_manager._get_version(type, version_num, 'request') request_rspec = RSpec(version=request_version) request_rspec.version.merge(ad_rspec) request_rspec.version.add_link_requests(link_tuples) except: logger.log_exc("sfiAddLinks FAILED with links %s" % links) sys.exit(1) print >> outfile, request_rspec.toxml() sys.exit(0)
result_version = version_manager._get_version(rspec_version.type, rspec_version.version, 'ad') rspec = RSpec(version=result_version) for result in results: self.add_slicemgr_stat(rspec, "ListResources", result["aggregate"], result["elapsed"], result["status"], result.get("exc_info",None)) if result["status"]=="success": res = result['result']['value'] try: rspec.version.merge(ReturnValue.get_value(res)) except: api.logger.log_exc("SM.ListResources: Failed to merge aggregate rspec") # cache the result if self.cache and not xrn: api.logger.debug("SliceManager.ListResources caches advertisement") self.cache.add(version_string, rspec.toxml()) return rspec.toxml() def Allocate(self, api, xrn, creds, rspec_str, expiration, options): call_id = options.get('call_id') if Callids().already_handled(call_id): return "" version_manager = VersionManager() def _Allocate(aggregate, server, xrn, credential, rspec, options): tStart = time.time() try: # Need to call GetVersion at an aggregate to determine the supported # rspec type/format beofre calling CreateSliver at an Aggregate. #server_version = api.get_cached_server_version(server)
from sfa.util.sfalogging import logger from sfa.client.sfi_commands import Commands from sfa.rspecs.rspec import RSpec logger.enable_console() command = Commands(usage="%prog [options] node1 node2...", description="Delete slivers from the RSpec. " + "This command reads in an RSpec and outputs a modified " + "RSpec. Use this to remove nodes from your slice.") command.add_nodefile_option() command.prep() if command.opts.infile: rspec = RSpec(command.opts.infile) nodes = [] if command.opts.nodefile: f = open(command.opts.nodefile, "r") nodes = f.read().split() f.close() try: slivers = [{'hostname': node} for node in nodes] rspec.version.remove_slivers(slivers) print rspec.toxml() except: logger.log_exc("sfiDeleteSliver FAILED with nodes %s" % nodes)
if not command.opts.linkfile: print "Missing link list -- exiting" command.parser.print_help() sys.exit(1) if command.opts.infile: infile=file(command.opts.infile) else: infile=sys.stdin if command.opts.outfile: outfile=file(command.opts.outfile,"w") else: outfile=sys.stdout ad_rspec = RSpec(infile) links = file(command.opts.linkfile).read().split('\n') link_tuples = map(lambda x: tuple(x.split()), links) version_manager = VersionManager() try: type = ad_rspec.version.type version_num = ad_rspec.version.version request_version = version_manager._get_version(type, version_num, 'request') request_rspec = RSpec(version=request_version) request_rspec.version.merge(ad_rspec) request_rspec.version.add_link_requests(link_tuples) except: logger.log_exc("sfiAddLinks FAILED with links %s" % links) sys.exit(1) print >>outfile, request_rspec.toxml() sys.exit(0)