def call(self, xrn, creds, rspec, options): xrn = Xrn(xrn, type='slice') self.api.logger.info("interface: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, xrn.get_hrn(), self.name)) (speaking_for, _) = urn_to_hrn(options.get('geni_speaking_for')) # Find the valid credentials valid_creds = self.api.auth.checkCredentials(creds, 'createsliver', xrn.get_hrn(), speaking_for_hrn=speaking_for) # use the expiration from the first valid credential to determine when # the slivers should expire. expiration = datetime_to_string(Credential(cred=valid_creds[0]).expiration) # make sure request is not empty slivers = RSpec(rspec).version.get_nodes_with_slivers() if not slivers: raise InvalidRSpec("Missing <sliver_type> or <sliver> element. Request rspec must explicitly allocate slivers") # flter rspec through sfatables if self.api.interface in ['aggregate']: chain_name = 'INCOMING' elif self.api.interface in ['slicemgr']: chain_name = 'FORWARD-INCOMING' self.api.logger.debug("Allocate: sfatables on chain %s"%chain_name) origin_hrn = Credential(cred=valid_creds[0]).get_gid_caller().get_hrn() self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, xrn, self.name)) rspec = run_sfatables(chain_name, xrn.get_hrn(), origin_hrn, rspec) slivers = RSpec(rspec).version.get_nodes_with_slivers() if not slivers: raise SfatablesRejected(slice_xrn) result = self.api.manager.Allocate(self.api, xrn.get_urn(), creds, rspec, expiration, options) return result
def test_void(self): void = Xrn(xrn='', type=None) expected = 'urn:publicid:IDN++' self.assertEqual(void.get_hrn(), '') self.assertEqual(void.get_type(), None) self.assertEqual(void.get_urn(), expected) loop = Xrn(xrn=expected) self.assertEqual(loop.get_hrn(), '') # xxx - this is not quite right as the first object has type None self.assertEqual(loop.get_type(), '')
def test_void(self): void=Xrn(xrn='',type=None) expected='urn:publicid:IDN++' self.assertEqual(void.get_hrn(),'') self.assertEqual(void.get_type(),None) self.assertEqual(void.get_urn(),expected) loop=Xrn(xrn=expected) self.assertEqual(loop.get_hrn(),'') # xxx - this is not quite right as the first object has type None self.assertEqual(loop.get_type(),'')
def GetVersion(self, api, options): # peers explicitly in aggregates.xml peers =dict ([ (peername,interface.get_url()) for (peername,interface) in api.aggregates.iteritems() if peername != api.hrn]) version_manager = VersionManager() ad_rspec_versions = [] request_rspec_versions = [] for rspec_version in version_manager.versions: if rspec_version.content_type in ['*', 'ad']: ad_rspec_versions.append(rspec_version.to_dict()) if rspec_version.content_type in ['*', 'request']: request_rspec_versions.append(rspec_version.to_dict()) xrn=Xrn(api.hrn, 'authority+sa') version_more = { 'interface':'slicemgr', 'sfa': 2, 'geni_api': 2, 'geni_api_versions': {'2': 'http://%s:%s' % (api.config.SFA_SM_HOST, api.config.SFA_SM_PORT)}, 'hrn' : xrn.get_hrn(), 'urn' : xrn.get_urn(), 'peers': peers, 'geni_request_rspec_versions': request_rspec_versions, 'geni_ad_rspec_versions': ad_rspec_versions, } sm_version=version_core(version_more) # local aggregate if present needs to have localhost resolved if api.hrn in api.aggregates: local_am_url=api.aggregates[api.hrn].get_url() sm_version['peers'][api.hrn]=local_am_url.replace('localhost',sm_version['hostname']) return sm_version
def allocate (self, urn, rspec_string, expiration, options=None): if options is None: options={} xrn = Xrn(urn) 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(xrn.get_hrn(), users[0]) # collect public keys users = options.get('geni_users', []) 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() slivers = aggregate.run_instances(instance_name, tenant_name, \ rspec_string, key_name, pubkeys) # update all sliver allocation states setting then to geni_allocated sliver_ids = [sliver.id for sliver in slivers] dbsession=self.api.dbsession() SliverAllocation.set_allocations(sliver_ids, 'geni_provisioned',dbsession) return aggregate.describe(urns=[urn], version=rspec.version)
def GetVersion(api): # peers explicitly in aggregates.xml peers =dict ([ (peername,get_serverproxy_url(v)) for (peername,v) in api.aggregates.iteritems() if peername != api.hrn]) version_manager = VersionManager() ad_rspec_versions = [] request_rspec_versions = [] for rspec_version in version_manager.versions: if rspec_version.content_type in ['*', 'ad']: ad_rspec_versions.append(rspec_version.to_dict()) if rspec_version.content_type in ['*', 'request']: request_rspec_versions.append(rspec_version.to_dict()) default_rspec_version = version_manager.get_version("sfa 1").to_dict() xrn=Xrn(api.hrn, 'authority+sa') version_more = {'interface':'slicemgr', 'hrn' : xrn.get_hrn(), 'urn' : xrn.get_urn(), 'peers': peers, 'request_rspec_versions': request_rspec_versions, 'ad_rspec_versions': ad_rspec_versions, 'default_ad_rspec': default_rspec_version } sm_version=version_core(version_more) # local aggregate if present needs to have localhost resolved if api.hrn in api.aggregates: local_am_url=get_serverproxy_url(api.aggregates[api.hrn]) sm_version['peers'][api.hrn]=local_am_url.replace('localhost',sm_version['hostname']) return sm_version
def _record_dict(self, xrn, type, email, key, slices, researchers, pis, url, description, extras): record_dict = {} if xrn: if type: xrn = Xrn(xrn, type) else: xrn = Xrn(xrn) record_dict['urn'] = xrn.get_urn() record_dict['hrn'] = xrn.get_hrn() record_dict['type'] = xrn.get_type() if url: record_dict['url'] = url if description: record_dict['description'] = description if key: try: pubkey = open(key, 'r').read() except IOError: pubkey = key record_dict['reg-keys'] = [pubkey] if slices: record_dict['slices'] = slices if researchers: record_dict['reg-researchers'] = researchers if email: record_dict['email'] = email if pis: record_dict['reg-pis'] = pis if extras: record_dict.update(extras) return record_dict
def allocate(self, urn, rspec_string, expiration, options={}): xrn = Xrn(urn) 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(xrn.get_hrn(), users[0]) # collect public keys users = options.get('geni_users', []) 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() slivers = aggregate.run_instances(instance_name, tenant_name, \ rspec_string, key_name, pubkeys) # update all sliver allocation states setting then to geni_allocated sliver_ids = [sliver.id for sliver in slivers] dbsession = self.api.dbsession() SliverAllocation.set_allocations(sliver_ids, 'geni_provisioned', dbsession) return aggregate.describe(urns=[urn], version=rspec.version)
def _record_dict(self, xrn=None, type=None, url=None, description=None, email='', key=None, slices=[], researchers=[], pis=[]): record_dict = {} if xrn: if type: xrn = Xrn(xrn, type) else: xrn = Xrn(xrn) record_dict['urn'] = xrn.get_urn() record_dict['hrn'] = xrn.get_hrn() record_dict['type'] = xrn.get_type() if url: record_dict['url'] = url if description: record_dict['description'] = description if key: try: pubkey = open(key, 'r').read() except IOError: pubkey = key record_dict['keys'] = [pubkey] if slices: record_dict['slices'] = slices if researchers: record_dict['researcher'] = researchers if email: record_dict['email'] = email if pis: record_dict['pi'] = pis return record_dict
def GetVersion(self, api, options): # peers explicitly in aggregates.xml peers =dict ([ (peername,interface.get_url()) for (peername,interface) in api.aggregates.iteritems() if peername != api.hrn]) version_manager = VersionManager() ad_rspec_versions = [] request_rspec_versions = [] cred_types = [{'geni_type': 'geni_sfa', 'geni_version': str(i)} for i in range(4)[-2:]] for rspec_version in version_manager.versions: if rspec_version.content_type in ['*', 'ad']: ad_rspec_versions.append(rspec_version.to_dict()) if rspec_version.content_type in ['*', 'request']: request_rspec_versions.append(rspec_version.to_dict()) xrn=Xrn(api.hrn, 'authority+sm') version_more = { 'interface':'slicemgr', 'sfa': 2, 'geni_api': 3, 'geni_api_versions': {'3': 'http://%s:%s' % (api.config.SFA_SM_HOST, api.config.SFA_SM_PORT)}, 'hrn' : xrn.get_hrn(), 'urn' : xrn.get_urn(), 'peers': peers, 'geni_single_allocation': 0, # Accept operations that act on as subset of slivers in a given state. 'geni_allocate': 'geni_many',# Multiple slivers can exist and be incrementally added, including those which connect or overlap in some way. 'geni_credential_types': cred_types, } sm_version=version_core(version_more) # local aggregate if present needs to have localhost resolved if api.hrn in api.aggregates: local_am_url=api.aggregates[api.hrn].get_url() sm_version['peers'][api.hrn]=local_am_url.replace('localhost',sm_version['hostname']) return sm_version
def SliverStatus (self, api, xrn, creds, options): call_id = options.get('call_id') if Callids().already_handled(call_id): return {} xrn = Xrn(xrn,'slice') slice_urn=xrn.get_urn() slice_hrn=xrn.get_hrn() return self.driver.sliver_status (slice_urn, slice_hrn)
def list(self, xrn, type=None, recursive=False): """List names registered at a given authority - possibly filtered by type""" xrn = Xrn(xrn, type) options = {'recursive': recursive} records = self.api.manager.List(self.api, xrn.get_hrn(), options=options) for record in records: if not type or record['type'] == type: print "%s (%s)" % (record['hrn'], record['type'])
def GetVersion(api): peers =dict ([ (peername,v._ServerProxy__host) for (peername,v) in api.registries.iteritems() if peername != api.hrn]) xrn=Xrn(api.hrn) return version_core({'interface':'registry', 'hrn':xrn.get_hrn(), 'urn':xrn.get_urn(), 'peers':peers})
def DeleteSliver(self, api, xrn, creds, options): call_id = options.get('call_id') if Callids().already_handled(call_id): return True xrn = Xrn(xrn, 'slice') slice_urn=xrn.get_urn() slice_hrn=xrn.get_hrn() return self.driver.delete_sliver (slice_urn, slice_hrn, creds, options)
def RenewSliver(self, api, xrn, creds, expiration_time, options): call_id = options.get('call_id') if Callids().already_handled(call_id): return True xrn = Xrn(xrn, 'slice') slice_urn=xrn.get_urn() slice_hrn=xrn.get_hrn() return self.driver.renew_sliver (slice_urn, slice_hrn, creds, expiration_time, options)
def GetVersion(self, api, options): peers = dict ( [ (hrn,interface.get_url()) for (hrn,interface) in api.registries.iteritems() if hrn != api.hrn]) xrn=Xrn(api.hrn,type='authority') return version_core({'interface':'registry', 'sfa': 3, 'hrn':xrn.get_hrn(), 'urn':xrn.get_urn(), 'peers':peers})
def GetTicket(self, api, xrn, creds, rspec, users, options): xrn = Xrn(xrn) slice_urn=xrn.get_urn() slice_hrn=xrn.get_hrn() # xxx sounds like GetTicket is dead, but if that gets resurrected we might wish # to pass 'users' over to the driver as well return self.driver.get_ticket (slice_urn, slice_hrn, creds, rspec, options)
def GetVersion(self, api, options): peers = dict ( [ (hrn,interface.get_url()) for (hrn,interface) in api.registries.iteritems() if hrn != api.hrn]) xrn=Xrn(api.hrn) return version_core({'interface':'registry', 'sfa': 2, 'geni_api': 2, 'hrn':xrn.get_hrn(), 'urn':xrn.get_urn(), 'peers':peers})
def call(self, xrn, creds, rspec, options): xrn = Xrn(xrn, type='slice') self.api.logger.info("interface: %s\ttarget-hrn: %s\tmethod-name: %s" % (self.api.interface, xrn.get_hrn(), self.name)) (speaking_for, _) = urn_to_hrn(options.get('geni_speaking_for')) # Find the valid credentials valid_creds = self.api.auth.checkCredentials( creds, 'createsliver', xrn.get_hrn(), speaking_for_hrn=speaking_for) # use the expiration from the first valid credential to determine when # the slivers should expire. expiration = datetime_to_string( Credential(cred=valid_creds[0]).expiration) # make sure request is not empty slivers = RSpec(rspec).version.get_nodes_with_slivers() if not slivers: raise InvalidRSpec( "Missing <sliver_type> or <sliver> element. Request rspec must explicitly allocate slivers" ) # flter rspec through sfatables if self.api.interface in ['aggregate']: chain_name = 'INCOMING' elif self.api.interface in ['slicemgr']: chain_name = 'FORWARD-INCOMING' self.api.logger.debug("Allocate: sfatables on chain %s" % chain_name) origin_hrn = Credential(cred=valid_creds[0]).get_gid_caller().get_hrn() self.api.logger.info( "interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" % (self.api.interface, origin_hrn, xrn, self.name)) rspec = run_sfatables(chain_name, xrn.get_hrn(), origin_hrn, rspec) slivers = RSpec(rspec).version.get_nodes_with_slivers() if not slivers: raise SfatablesRejected(slice_xrn) result = self.api.manager.Allocate(self.api, xrn.get_urn(), creds, rspec, expiration, options) return result
def list(self, xrn, type=None, recursive=False, verbose=False): """List names registered at a given authority - possibly filtered by type""" xrn = Xrn(xrn, type) options_dict = {'recursive': recursive} records = self.api.manager.List(self.api, xrn.get_hrn(), options=options_dict) list = filter_records(type, records) # terminal_render expects an options object class Options: pass options=Options() options.verbose=verbose terminal_render (list, options)
def GetVersion(api): xrn=Xrn(api.hrn) request_rspec_versions = [dict(sfa_rspec_version)] ad_rspec_versions = [dict(sfa_rspec_version)] version_more = {'interface':'aggregate', 'testbed':'myplc', 'hrn':xrn.get_hrn(), 'request_rspec_versions': request_rspec_versions, 'ad_rspec_versions': ad_rspec_versions, 'default_ad_rspec': dict(sfa_rspec_version) } return version_core(version_more)
def call(self, xrn, creds, type): xrn=Xrn(xrn,type=type) # validate the cred valid_creds = self.api.auth.checkCredentials(creds, "remove") self.api.auth.verify_object_permission(xrn.get_hrn()) #log the call origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn() self.api.logger.info("interface: %s\tmethod-name: %s\tcaller-hrn: %s\ttarget-urn: %s"%( self.api.interface, self.name, origin_hrn, xrn.get_urn())) return self.api.manager.Remove(self.api, xrn)
def CreateSliver(self, api, xrn, creds, rspec_string, users, options): """ Create the sliver[s] (slice) at this aggregate. Verify HRN and initialize the slice record in PLC if necessary. """ call_id = options.get('call_id') if Callids().already_handled(call_id): return "" xrn = Xrn(xrn, 'slice') slice_urn=xrn.get_urn() slice_hrn=xrn.get_hrn() return self.driver.create_sliver (slice_urn, slice_hrn, creds, rspec_string, users, options)
def ListResources(self, api, creds, options): call_id = options.get('call_id') if Callids().already_handled(call_id): return "" # get slice's hrn from options slice_xrn = options.get('geni_slice_urn', None) # pass None if no slice is specified if not slice_xrn: slice_hrn, slice_urn = None, None else: xrn = Xrn(slice_xrn) slice_urn=xrn.get_urn() slice_hrn=xrn.get_hrn() return self.driver.list_resources (slice_urn, slice_hrn, creds, options)
def allocate(self, urn, rspec_string, expiration, options={}): xrn = Xrn(urn) aggregate = PlAggregate(self) slices = PlSlices(self) 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', {}) # 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, sfa_peer, options=options) # ensure slice record exists slice = slices.verify_slice(xrn.hrn, slice_record, sfa_peer, expiration=expiration, options=options) # ensure person records exists persons = slices.verify_persons(xrn.hrn, slice, users, sfa_peer, options=options) # ensure slice attributes exists slices.verify_slice_attributes(slice, requested_attributes, options=options) # add/remove slice from nodes request_nodes = rspec.version.get_nodes_with_slivers() nodes = slices.verify_slice_nodes(urn, slice, request_nodes) # 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(slice, rspec_requested_leases) return aggregate.describe([xrn.get_urn()], version=rspec.version)
def call(self, xrn, creds, rspec, options): xrn = Xrn(xrn, type='slice') # Find the valid credentials valid_creds = self.api.auth.checkCredentialsSpeaksFor(creds, 'createsliver', xrn.get_hrn(), options=options) the_credential = Credential(cred=valid_creds[0]) # use the expiration from the first valid credential to determine when # the slivers should expire. expiration = datetime_to_string(the_credential.expiration) self.api.logger.debug("Allocate, received expiration from credential: %s"%expiration) # turned off, as passing an empty rspec is indeed useful for cleaning up the slice # # make sure request is not empty # slivers = RSpec(rspec).version.get_nodes_with_slivers() # if not slivers: # raise InvalidRSpec("Missing <sliver_type> or <sliver> element. Request rspec must explicitly allocate slivers") # flter rspec through sfatables if self.api.interface in ['aggregate']: chain_name = 'INCOMING' elif self.api.interface in ['slicemgr']: chain_name = 'FORWARD-INCOMING' self.api.logger.debug("Allocate: sfatables on chain %s"%chain_name) actual_caller_hrn = the_credential.actual_caller_hrn() self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, actual_caller_hrn, xrn.get_hrn(), self.name)) rspec = run_sfatables(chain_name, xrn.get_hrn(), actual_caller_hrn, rspec) # turned off, as passing an empty rspec is indeed useful for cleaning up the slice # slivers = RSpec(rspec).version.get_nodes_with_slivers() # if not slivers: # raise SfatablesRejected(slice_xrn) # pass this to the driver code in case they need it options['actual_caller_hrn'] = actual_caller_hrn result = self.api.manager.Allocate(self.api, xrn.get_urn(), creds, rspec, expiration, options) return result
def call(self, xrn, creds, type): xrn = Xrn(xrn, type=type) # validate the cred valid_creds = self.api.auth.checkCredentials(creds, "remove") self.api.auth.verify_object_permission(xrn.get_hrn()) #log the call origin_hrn = Credential( string=valid_creds[0]).get_gid_caller().get_hrn() self.api.logger.info( "interface: %s\tmethod-name: %s\tcaller-hrn: %s\ttarget-urn: %s" % (self.api.interface, self.name, origin_hrn, xrn.get_urn())) return self.api.manager.Remove(self.api, xrn)
def GetVersion(self, api, options): xrn=Xrn(api.hrn) version = version_core() version_generic = { 'interface':'aggregate', 'sfa': 2, 'geni_api': 2, 'geni_api_versions': {'2': 'http://%s:%s' % (api.config.SFA_AGGREGATE_HOST, api.config.SFA_AGGREGATE_PORT)}, 'hrn':xrn.get_hrn(), 'urn':xrn.get_urn(), } version.update(version_generic) testbed_version = self.driver.aggregate_version() version.update(testbed_version) return version
def list(self, xrn, type=None, recursive=False, verbose=False): """List names registered at a given authority - possibly filtered by type""" xrn = Xrn(xrn, type) options_dict = {'recursive': recursive} records = self.api.manager.List(self.api, xrn.get_hrn(), options=options_dict) list = filter_records(type, records) # terminal_render expects an options object class Options: pass options = Options() options.verbose = verbose terminal_render(list, options)
def GetVersion(api, options): version_manager = VersionManager() ad_rspec_versions = [] request_rspec_versions = [] for rspec_version in version_manager.versions: if rspec_version.content_type in ['*', 'ad']: ad_rspec_versions.append(rspec_version.to_dict()) if rspec_version.content_type in ['*', 'request']: request_rspec_versions.append(rspec_version.to_dict()) xrn=Xrn(api.hrn) version_more = {'interface':'aggregate', 'sfa': 1, 'geni_api': '2', 'testbed':'myplc', 'hrn':xrn.get_hrn(), 'geni_request_rspec_versions': request_rspec_versions, 'geni_ad_rspec_versions': ad_rspec_versions, } return version_core(version_more)
def GetVersion(api): version_manager = VersionManager() ad_rspec_versions = [] request_rspec_versions = [] for rspec_version in version_manager.versions: if rspec_version.content_type in ['*', 'ad']: ad_rspec_versions.append(rspec_version.to_dict()) if rspec_version.content_type in ['*', 'request']: request_rspec_versions.append(rspec_version.to_dict()) default_rspec_version = version_manager.get_version("sfa 1").to_dict() xrn=Xrn(api.hrn) version_more = {'interface':'aggregate', 'testbed':'myplc', 'hrn':xrn.get_hrn(), 'request_rspec_versions': request_rspec_versions, 'ad_rspec_versions': ad_rspec_versions, 'default_ad_rspec': default_rspec_version } return version_core(version_more)
def _record_dict(self, xrn=None, type=None, url=None, description=None, email='', key=None, slices=[], researchers=[], pis=[], extras={}): record_dict = {} if xrn: if type: xrn = Xrn(xrn, type) else: xrn = Xrn(xrn) record_dict['urn'] = xrn.get_urn() record_dict['hrn'] = xrn.get_hrn() record_dict['type'] = xrn.get_type() if url: record_dict['url'] = url if description: record_dict['description'] = description if key: try: pubkey = open(key, 'r').read() except IOError: pubkey = key record_dict['keys'] = [pubkey] if slices: record_dict['slices'] = slices if researchers: record_dict['researcher'] = researchers if email: record_dict['email'] = email if pis: record_dict['pi'] = pis if extras: record_dict.update(extras) return record_dict
def allocate (self, urn, rspec_string, expiration, options=None): if options is None: options={} xrn = Xrn(urn) aggregate = PlAggregate(self) slices = PlSlices(self) 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', {}) # 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, sfa_peer, options=options) # ensure slice record exists slice = slices.verify_slice(xrn.hrn, slice_record, sfa_peer, expiration=expiration, options=options) # ensure person records exists persons = slices.verify_persons(xrn.hrn, slice, users, sfa_peer, options=options) # ensure slice attributes exists slices.verify_slice_attributes(slice, requested_attributes, options=options) # add/remove slice from nodes request_nodes = rspec.version.get_nodes_with_slivers() nodes = slices.verify_slice_nodes(urn, slice, request_nodes) # 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(slice, rspec_requested_leases) return aggregate.describe([xrn.get_urn()], version=rspec.version)
def GetVersion(self, api, options): xrn=Xrn(api.hrn, type='authority+am') version = version_core() cred_types = [{'geni_type': 'geni_sfa', 'geni_version': str(i)} for i in range(4)[-2:]] geni_api_versions = ApiVersions().get_versions() geni_api_versions['3'] = 'http://%s:%s' % (api.config.sfa_aggregate_host, api.config.sfa_aggregate_port) version_generic = { 'testbed': api.driver.testbed_name(), 'interface':'aggregate', 'sfa': 3, 'hrn':xrn.get_hrn(), 'urn':xrn.get_urn(), 'geni_api': 3, 'geni_api_versions': geni_api_versions, 'geni_single_allocation': 0, # Accept operations that act on as subset of slivers in a given state. 'geni_allocate': 'geni_many',# Multiple slivers can exist and be incrementally added, including those which connect or overlap in some way. 'geni_credential_types': cred_types, 'geni_handles_speaksfor': True, # supports 'speaks for' credentials } version.update(version_generic) version.update(self.rspec_versions()) testbed_version = api.driver.aggregate_version() version.update(testbed_version) return version
def stop_slice(self, api, xrn, creds): xrn = Xrn(xrn) slice_urn=xrn.get_urn() slice_hrn=xrn.get_hrn() return self.driver.stop_slice (slice_urn, slice_hrn, creds)
def GetVersion(api): xrn=Xrn(api.hrn) return version_core({'interface':'aggregate', 'testbed':'myplc.vini', 'hrn':xrn.get_hrn(), })
def reset_slice(self, api, xrn): xrn = Xrn(xrn) slice_urn=xrn.get_urn() slice_hrn=xrn.get_hrn() return self.driver.reset_slice (slice_urn, slice_hrn)
def allocate (self, urn, rspec_string, expiration, options=None): if options is None: options={} aggregate = OSAggregate(self) rspec = RSpec(rspec_string) xrn = Xrn(urn) slice_hrn = xrn.get_hrn() tenant_name = OSXrn(xrn=slice_hrn, type='slice').get_hrn() instance_name = hrn_to_os_slicename(slice_hrn) tenants = self.shell.auth_manager.tenants.findall() # collect public keys & get the user name users = options.get('geni_users', []) pubkeys = [] key_name = None if len(users) >= 1: for user in users: # TODO: We currently support one user name. user_name = Xrn(user.get('urn')).get_hrn() pubkeys.extend(user['keys']) for tenant in tenants: # Check if the tenant of the user exists in local OS or not if tenant_name == tenant.name: try: self.shell.auth_manager.users.find(name=user_name) except: user = self.register_federation(user_hrn=user_name, \ slice_hrn=tenant_name, keys=pubkeys, email=None) break else: user = self.register_federation(user_hrn=user_name, \ slice_hrn=tenant_name, keys=None, email=None) # Update connection for the current client self.shell.compute_manager.connect(username=user_name, tenant=tenant_name, password=user_name) keypair_list = self.shell.compute_manager.keypairs.list() keyname = OSXrn(xrn=user_name, type='user').get_slicename() for keypair in keypair_list: if keyname == keypair.name: key_name = keypair.name break else: raise SfaNotImplemented("No handle!") # Update initial connection info self.init_compute_manager_conn() # key_name = aggregate.create_instance_key(slice_hrn, users[0]) # In case of federation or non-options elif len(users) < 1: if options.get('actual_caller_hrn') is None: user_name = xrn.get_authority_hrn() + '.' + xrn.leaf.split('-')[0] else: user_name = options.get('actual_caller_hrn') for tenant in tenants: # Check if the tenant of the user in local OS or not if tenant_name == tenant.name: try: self.shell.auth_manager.users.find(name=user_name) except: user = self.register_federation(user_hrn=user_name, \ slice_hrn=tenant_name, keys=pubkeys, email=None) break else: user = self.register_federation(user_hrn=user_name, \ slice_hrn=tenant_name, keys=None, email=None) # TODO: Wrapper for federation needs at least one pubkey of the user extracted by 'options'!! # name = OSXrn(xrn=user_name, type='user').get_slicename() # key_name = self.shell.compute_manager.keypairs.get(name).name else: raise SfaNotImplemented("No handle!") slivers = aggregate.run_instances(tenant_name, user_name, rspec_string, key_name, pubkeys) # Update sliver allocations for sliver in slivers: component_id = sliver.metadata.get('component_id') sliver_id = OSXrn(name=('koren'+'.'+ sliver.name), id=sliver.id, type='node+openstack').get_urn() record = SliverAllocation( sliver_id=sliver_id, component_id=component_id, allocation_state='geni_allocated') record.sync(self.api.dbsession()) return aggregate.describe(urns=[urn], version=rspec.version)