def delete(self, urns, options={}): # collect sliver ids so we can update sliver allocation states after # we remove the slivers. aggregate = unigetestbedAggregate(self) slivers = aggregate.get_slivers(urns) if slivers: slice_id = slivers[0]['slice_id'] node_ids = [] sliver_ids = [] for sliver in slivers: node_ids.append(sliver['node_id']) sliver_ids.append(sliver['sliver_id']) # determine if this is a peer slice # xxx I wonder if this would not need to use PlSlices.get_peer instead # in which case plc.peers could be deprecated as this here # is the only/last call to this last method in plc.peers slice_hrn = unigetestbedXrn(auth=self.hrn, slicename=slivers[0]['slice_name']).get_hrn() try: self.shell.DeleteSliceFromNodes({'slice_id': slice_id, 'node_ids': node_ids}) # delete sliver allocation states dbsession=self.api.dbsession() SliverAllocation.delete_allocations(sliver_ids,dbsession) finally: pass # prepare return struct geni_slivers = [] for sliver in slivers: geni_slivers.append( {'geni_sliver_urn': sliver['sliver_id'], 'geni_allocation_status': 'geni_unallocated', 'geni_expires': datetime_to_string(utcparse(sliver['expires']))}) return geni_slivers
def delete(self, urns, options={}): # collect sliver ids so we can update sliver allocation states after # we remove the slivers. aggregate = OSAggregate(self) instances = aggregate.get_instances(urns) sliver_ids = [] for instance in instances: sliver_hrn = "%s.%s" % (self.driver.hrn, instance.id) sliver_ids.append(Xrn(sliver_hrn, type='sliver').urn) # delete the instance aggregate.delete_instance(instance) # delete sliver allocation states dbsession = self.api.dbsession() SliverAllocation.delete_allocations(sliver_ids, dbsession) # return geni_slivers geni_slivers = [] for sliver_id in sliver_ids: geni_slivers.append({ 'geni_sliver_urn': sliver['sliver_id'], 'geni_allocation_status': 'geni_unallocated', 'geni_expires': None }) return geni_slivers
def delete (self, urns, options=None): if options is None: options={} # collect sliver ids so we can update sliver allocation states after # we remove the slivers. aggregate = OSAggregate(self) instances = aggregate.get_instances(urns) sliver_ids = [] for instance in instances: sliver_hrn = "%s.%s" % (self.driver.hrn, instance.id) sliver_ids.append(Xrn(sliver_hrn, type='sliver').urn) # delete the instance aggregate.delete_instance(instance) # delete sliver allocation states dbsession=self.api.dbsession() SliverAllocation.delete_allocations(sliver_ids, dbsession) # return geni_slivers geni_slivers = [] for sliver_id in sliver_ids: geni_slivers.append( {'geni_sliver_urn': sliver['sliver_id'], 'geni_allocation_status': 'geni_unallocated', 'geni_expires': None}) return geni_slivers
def delete(self, urns, options=None): if options is None: options={} aggregate = OSAggregate(self) # Update connection for the current client 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.shell.compute_manager.connect(username=user_name, tenant=tenant_name, password=user_name) # collect sliver ids so we can update sliver allocation states after # we remove the slivers. instances = aggregate.get_instances(xrn) # Release the floating IPs of instances servers = aggregate.check_floatingip(instances, False) aggregate.delete_floatingip(servers) sliver_ids = [] id_set = set() for instance in instances: sliver_id = OSXrn(name=('koren'+'.'+ instance.name), id=instance.id, type='node+openstack').get_urn() sliver_ids.append(sliver_id) # delete the instance related with requested tenant aggregate.delete_instance(instance) id_set.add(instance.tenant_id) tenant_ids = list(id_set) for tenant_id in tenant_ids: # Delete both the router(s) and interfaces related with requested tenant aggregate.delete_router(tenant_id=tenant_id) # Delete both the network and subnet related with requested tenant aggregate.delete_network(tenant_id=tenant_id) # Delete sliver allocation states dbsession=self.api.dbsession() SliverAllocation.delete_allocations(sliver_ids, dbsession) # Return geni_slivers geni_slivers = [] for sliver_id in sliver_ids: geni_slivers.append( { 'geni_sliver_urn': sliver_id, 'geni_allocation_status': 'geni_unallocated', # 'geni_expires': datetime_to_string(utcparse(time.time())) }) 'geni_expires': None }) return geni_slivers
def delete(self, urns, options={}): # collect sliver ids so we can update sliver allocation states after # we remove the slivers. aggregate = PlAggregate(self) slivers = aggregate.get_slivers(urns) if slivers: slice_id = slivers[0]['slice_id'] slice_name = slivers[0]['name'] node_ids = [] sliver_ids = [] for sliver in slivers: node_ids.append(sliver['node_id']) sliver_ids.append(sliver['sliver_id']) # leases leases = self.shell.GetLeases({ 'name': slice_name, 'node_id': node_ids }) leases_ids = [lease['lease_id'] for lease in leases] slice_hrn = self.shell.GetSliceHrn(int(slice_id)) try: self.shell.DeleteSliceFromNodes(slice_id, node_ids) if len(leases_ids) > 0: self.shell.DeleteLeases(leases_ids) # delete sliver allocation states dbsession = self.api.dbsession() SliverAllocation.delete_allocations(sliver_ids, dbsession) finally: pass # prepare return struct geni_slivers = [] for sliver in slivers: geni_slivers.append({ 'geni_sliver_urn': sliver['sliver_id'], 'geni_allocation_status': 'geni_unallocated', 'geni_expires': datetime_to_string(utcparse(sliver['expires'])) }) return geni_slivers
def delete(self, urns, options={}): # collect sliver ids so we can update sliver allocation states after # we remove the slivers. aggregate = DummyAggregate(self) slivers = aggregate.get_slivers(urns) if slivers: slice_id = slivers[0]['slice_id'] node_ids = [] sliver_ids = [] for sliver in slivers: node_ids.append(sliver['node_id']) sliver_ids.append(sliver['sliver_id']) # determine if this is a peer slice # xxx I wonder if this would not need to use PlSlices.get_peer instead # in which case plc.peers could be deprecated as this here # is the only/last call to this last method in plc.peers slice_hrn = DummyXrn(auth=self.hrn, slicename=slivers[0]['slice_name']).get_hrn() try: self.shell.DeleteSliceFromNodes({ 'slice_id': slice_id, 'node_ids': node_ids }) # delete sliver allocation states dbsession = self.api.dbsession() SliverAllocation.delete_allocations(sliver_ids, dbsession) finally: pass # prepare return struct geni_slivers = [] for sliver in slivers: geni_slivers.append({ 'geni_sliver_urn': sliver['sliver_id'], 'geni_allocation_status': 'geni_unallocated', 'geni_expires': datetime_to_string(utcparse(sliver['expires'])) }) return geni_slivers
def delete(self, urns, options=None): if options is None: options={} # collect sliver ids so we can update sliver allocation states after # we remove the slivers. aggregate = PlAggregate(self) slivers = aggregate.get_slivers(urns) if slivers: slice_id = slivers[0]['slice_id'] slice_name = slivers[0]['name'] node_ids = [] sliver_ids = [] for sliver in slivers: node_ids.append(sliver['node_id']) sliver_ids.append(sliver['sliver_id']) # leases leases = self.shell.GetLeases({'name': slice_name, 'node_id': node_ids}) leases_ids = [lease['lease_id'] for lease in leases ] slice_hrn = self.shell.GetSliceHrn(int(slice_id)) try: self.shell.DeleteSliceFromNodes(slice_id, node_ids) if len(leases_ids) > 0: self.shell.DeleteLeases(leases_ids) # delete sliver allocation states dbsession=self.api.dbsession() SliverAllocation.delete_allocations(sliver_ids,dbsession) finally: pass # prepare return struct geni_slivers = [] for sliver in slivers: geni_slivers.append( {'geni_sliver_urn': sliver['sliver_id'], 'geni_allocation_status': 'geni_unallocated', 'geni_expires': datetime_to_string(utcparse(sliver['expires']))}) return geni_slivers
def func(*args, **kwds): if name == "list_resources": (version, options) = args slice_urn = slice_hrn = None creds = [] rspec = getattr(self.driver, "list_resources")(slice_urn, slice_hrn, [], options) result = rspec elif name == "describe": (urns, version, options) = args slice_urn = urns[0] slice_hrn, type = urn_to_hrn(slice_urn) creds = [] rspec = getattr(self.driver, "list_resources")(slice_urn, slice_hrn, creds, options) # SliverAllocation if len(urns) == 1 and Xrn(xrn=urns[0]).type == 'slice': constraint = SliverAllocation.slice_urn.in_(urns) else: constraint = SliverAllocation.sliver_id.in_(urns) sliver_allocations = self.driver.api.dbsession().query( SliverAllocation).filter(constraint) sliver_status = getattr(self.driver, "sliver_status")(slice_urn, slice_hrn) if 'geni_expires' in sliver_status.keys(): geni_expires = sliver_status['geni_expires'] else: geni_expires = '' geni_slivers = [] for sliver_allocation in sliver_allocations: geni_sliver = {} geni_sliver['geni_expires'] = geni_expires geni_sliver[ 'geni_allocation'] = sliver_allocation.allocation_state geni_sliver[ 'geni_sliver_urn'] = sliver_allocation.sliver_id geni_sliver['geni_error'] = '' if geni_sliver['geni_allocation'] == 'geni_allocated': geni_sliver[ 'geni_operational_status'] = 'geni_pending_allocation' else: geni_sliver['geni_operational_status'] = 'geni_ready' geni_slivers.append(geni_sliver) result = { 'geni_urn': slice_urn, 'geni_rspec': rspec, 'geni_slivers': geni_slivers } elif name == "allocate": (slice_urn, rspec_string, expiration, options) = args slice_hrn, type = urn_to_hrn(slice_urn) creds = [] users = options.get('sfa_users', []) manifest_string = getattr(self.driver, "create_sliver")(slice_urn, slice_hrn, creds, rspec_string, users, options) # slivers allocation rspec = RSpec(manifest_string) slivers = rspec.version.get_nodes_with_slivers() ##SliverAllocation for sliver in slivers: client_id = sliver['client_id'] component_id = sliver['component_id'] component_name = sliver['component_name'] slice_name = slice_hrn.replace('.', '-') component_short_name = component_name.split('.')[0] # self.driver.hrn sliver_hrn = '%s.%s-%s' % (self.driver.hrn, slice_name, component_short_name) sliver_id = Xrn(sliver_hrn, type='sliver').urn record = SliverAllocation( sliver_id=sliver_id, client_id=client_id, component_id=component_id, slice_urn=slice_urn, allocation_state='geni_allocated') record.sync() # return manifest rspec_version = RSpec(rspec_string).version rspec_version_str = "%s" % rspec_version options['geni_rspec_version'] = { 'version': rspec_version_str.split(' ')[1], 'type': rspec_version_str.lower().split(' ')[0] } result = self.describe([slice_urn], rspec_version, options) elif name == "provision": (urns, options) = args if len(urns) == 1 and Xrn(xrn=urns[0]).type == 'slice': constraint = SliverAllocation.slice_urn.in_(urns) else: constraint = SliverAllocation.sliver_id.in_(urns) dbsession = self.driver.api.dbsession() sliver_allocations = dbsession.query(SliverAllocation).filter( constraint) for sliver_allocation in sliver_allocations: sliver_allocation.allocation_state = 'geni_provisioned' dbsession.commit() result = self.describe(urns, '', options) elif name == "status": urns = args options = {} options['geni_rspec_version'] = { 'version': '3', 'type': 'GENI' } descr = self.describe(urns[0], '', options) result = { 'geni_urn': descr['geni_urn'], 'geni_slivers': descr['geni_slivers'] } elif name == "delete": (urns, options) = args slice_urn = urns[0] slice_hrn, type = urn_to_hrn(slice_urn) creds = [] options['geni_rspec_version'] = { 'version': '3', 'type': 'GENI' } descr = self.describe(urns, '', options) result = [] for sliver_allocation in descr['geni_slivers']: geni_sliver = { 'geni_sliver_urn': sliver_allocation['geni_sliver_urn'], 'geni_allocation_status': 'geni_unallocated', 'geni_expires': sliver_allocation['geni_expires'], 'geni_error': sliver_allocation['geni_error'] } result.append(geni_sliver) getattr(self.driver, "delete_sliver")(slice_urn, slice_hrn, creds, options) #SliverAllocation constraints = SliverAllocation.slice_urn.in_(urns) dbsession = self.driver.api.dbsession() sliver_allocations = dbsession.query(SliverAllocation).filter( constraints) sliver_ids = [ sliver_allocation.sliver_id for sliver_allocation in sliver_allocations ] SliverAllocation.delete_allocations(sliver_ids, dbsession) elif name == "renew": (urns, expiration_time, options) = args slice_urn = urns[0] slice_hrn, type = urn_to_hrn(slice_urn) creds = [] getattr(self.driver, "renew_sliver")(slice_urn, slice_hrn, creds, expiration_time, options) options['geni_rspec_version'] = { 'version': '3', 'type': 'GENI' } descr = self.describe(urns, '', options) result = descr['geni_slivers'] elif name == "perform_operational_action": (urns, action, options) = args options['geni_rspec_version'] = { 'version': '3', 'type': 'GENI' } result = self.describe(urns, '', options)['geni_slivers'] else: # same as v2 ( registry methods) result = getattr(self.driver, name)(*args, **kwds) return result
def func(*args, **kwds): if name == "list_resources": (version, options) = args slice_urn = slice_hrn = None creds = [] rspec = getattr(self.driver, "list_resources")(slice_urn, slice_hrn, [], options) result = rspec elif name == "describe": (urns, version, options) = args slice_urn = urns[0] slice_hrn, type = urn_to_hrn(slice_urn) creds = [] rspec = getattr(self.driver, "list_resources")(slice_urn, slice_hrn, creds, options) # SliverAllocation if len(urns) == 1 and Xrn(xrn=urns[0]).type == 'slice': constraint = SliverAllocation.slice_urn.in_(urns) else: constraint = SliverAllocation.sliver_id.in_(urns) sliver_allocations = self.driver.api.dbsession().query (SliverAllocation).filter (constraint) sliver_status = getattr(self.driver, "sliver_status")(slice_urn, slice_hrn) if 'geni_expires' in sliver_status.keys(): geni_expires = sliver_status['geni_expires'] else: geni_expires = '' geni_slivers = [] for sliver_allocation in sliver_allocations: geni_sliver = {} geni_sliver['geni_expires'] = geni_expires geni_sliver['geni_allocation'] = sliver_allocation.allocation_state geni_sliver['geni_sliver_urn'] = sliver_allocation.sliver_id geni_sliver['geni_error'] = '' if geni_sliver['geni_allocation'] == 'geni_allocated': geni_sliver['geni_operational_status'] = 'geni_pending_allocation' else: geni_sliver['geni_operational_status'] = 'geni_ready' geni_slivers.append(geni_sliver) result = {'geni_urn': slice_urn, 'geni_rspec': rspec, 'geni_slivers': geni_slivers} elif name == "allocate": (slice_urn, rspec_string, expiration, options) = args slice_hrn, type = urn_to_hrn(slice_urn) creds = [] users = options.get('sfa_users', []) manifest_string = getattr(self.driver, "create_sliver")(slice_urn, slice_hrn, creds, rspec_string, users, options) # slivers allocation rspec = RSpec(manifest_string) slivers = rspec.version.get_nodes_with_slivers() ##SliverAllocation for sliver in slivers: client_id = sliver['client_id'] component_id = sliver['component_id'] component_name = sliver['component_name'] slice_name = slice_hrn.replace('.','-') component_short_name = component_name.split('.')[0] # self.driver.hrn sliver_hrn = '%s.%s-%s' % (self.driver.hrn, slice_name, component_short_name) sliver_id = Xrn(sliver_hrn, type='sliver').urn record = SliverAllocation(sliver_id=sliver_id, client_id=client_id, component_id=component_id, slice_urn = slice_urn, allocation_state='geni_allocated') record.sync(self.driver.api.dbsession()) # return manifest rspec_version = RSpec(rspec_string).version rspec_version_str = "%s"%rspec_version options['geni_rspec_version'] = {'version': rspec_version_str.split(' ')[1], 'type': rspec_version_str.lower().split(' ')[0]} result = self.describe([slice_urn], rspec_version, options) elif name == "provision": (urns, options) = args if len(urns) == 1 and Xrn(xrn=urns[0]).type == 'slice': constraint = SliverAllocation.slice_urn.in_(urns) else: constraint = SliverAllocation.sliver_id.in_(urns) dbsession = self.driver.api.dbsession() sliver_allocations = dbsession.query (SliverAllocation).filter(constraint) for sliver_allocation in sliver_allocations: sliver_allocation.allocation_state = 'geni_provisioned' dbsession.commit() result = self.describe(urns, '', options) elif name == "status": urns = args options = {} options['geni_rspec_version'] = {'version': '3', 'type': 'GENI'} descr = self.describe(urns[0], '', options) result = {'geni_urn': descr['geni_urn'], 'geni_slivers': descr['geni_slivers']} elif name == "delete": (urns, options) = args slice_urn = urns[0] slice_hrn, type = urn_to_hrn(slice_urn) creds = [] options['geni_rspec_version'] = {'version': '3', 'type': 'GENI'} descr = self.describe(urns, '', options) result = [] for sliver_allocation in descr['geni_slivers']: geni_sliver = {'geni_sliver_urn': sliver_allocation['geni_sliver_urn'], 'geni_allocation_status': 'geni_unallocated', 'geni_expires': sliver_allocation['geni_expires'], 'geni_error': sliver_allocation['geni_error']} result.append(geni_sliver) getattr(self.driver, "delete_sliver")(slice_urn, slice_hrn, creds, options) #SliverAllocation constraints = SliverAllocation.slice_urn.in_(urns) dbsession = self.driver.api.dbsession() sliver_allocations = dbsession.query(SliverAllocation).filter(constraints) sliver_ids = [sliver_allocation.sliver_id for sliver_allocation in sliver_allocations] SliverAllocation.delete_allocations(sliver_ids, dbsession) elif name == "renew": (urns, expiration_time, options) = args slice_urn = urns[0] slice_hrn, type = urn_to_hrn(slice_urn) creds = [] getattr(self.driver, "renew_sliver")(slice_urn, slice_hrn, creds, expiration_time, options) options['geni_rspec_version'] = {'version': '3', 'type': 'GENI'} descr = self.describe(urns, '', options) result = descr['geni_slivers'] elif name == "perform_operational_action": (urns, action, options) = args options['geni_rspec_version'] = {'version': '3', 'type': 'GENI'} result = self.describe(urns, '', options)['geni_slivers'] else: # same as v2 ( registry methods) result=getattr(self.driver, name)(*args, **kwds) return result