def allocate(self, urn, rspec_string, expiration, options={}): xrn = Xrn(urn) aggregate = DummyAggregate(self) slices = DummySlices(self) 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 slice record exists slice = slices.verify_slice(xrn.hrn, slice_record, expiration=expiration, options=options) # ensure person records exists #persons = slices.verify_persons(xrn.hrn, slice, users, peer, sfa_peer, options=options) # add/remove slice from nodes request_nodes = rspec.version.get_nodes_with_slivers() nodes = slices.verify_slice_nodes(urn, slice, request_nodes) return aggregate.describe([xrn.get_urn()], version=rspec.version)
def create_sliver(self, slice_urn, slice_hrn, creds, rspec_string, users, options): aggregate = DummyAggregate(self) slices = DummySlices(self) sfa_peer = slices.get_sfa_peer(slice_hrn) slice_record = None if users: slice_record = users[0].get("slice_record", {}) # parse rspec rspec = RSpec(rspec_string) requested_attributes = rspec.version.get_slice_attributes() # ensure slice record exists slice = slices.verify_slice(slice_hrn, slice_record, sfa_peer, options=options) # ensure user records exists # users = slices.verify_users(slice_hrn, slice, users, sfa_peer, options=options) # add/remove slice from nodes requested_slivers = [] for node in rspec.version.get_nodes_with_slivers(): hostname = None if node.get("component_name"): hostname = node.get("component_name").strip() elif node.get("component_id"): hostname = xrn_to_hostname(node.get("component_id").strip()) if hostname: requested_slivers.append(hostname) requested_slivers_ids = [] for hostname in requested_slivers: node_id = self.shell.GetNodes({"hostname": hostname})[0]["node_id"] requested_slivers_ids.append(node_id) nodes = slices.verify_slice_nodes(slice, requested_slivers_ids) return aggregate.get_rspec(slice_xrn=slice_urn, version=rspec.version)
def status (self, urns, options=None): if options is None: options={} aggregate = DummyAggregate(self) desc = aggregate.describe(urns, version='GENI 3') status = {'geni_urn': desc['geni_urn'], 'geni_slivers': desc['geni_slivers']} return status
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 status(self, urns, options={}): aggregate = DummyAggregate(self) desc = aggregate.describe(urns, version='GENI 3') status = { 'geni_urn': desc['geni_urn'], 'geni_slivers': desc['geni_slivers'] } return status
def renew (self, urns, expiration_time, options={}): aggregate = DummyAggregate(self) slivers = aggregate.get_slivers(urns) if not slivers: raise SearchFailed(urns) slice = slivers[0] requested_time = utcparse(expiration_time) record = {'expires': int(datetime_to_epoch(requested_time))} self.shell.UpdateSlice({'slice_id': slice['slice_id'], 'fileds': record}) description = self.describe(urns, 'GENI 3', options) return description['geni_slivers']
def list_resources(self, slice_urn, slice_hrn, creds, options): version_manager = VersionManager() # get the rspec's return format from options rspec_version = version_manager.get_version(options.get("geni_rspec_version")) version_string = "rspec_%s" % (rspec_version) aggregate = DummyAggregate(self) rspec = aggregate.get_rspec(slice_xrn=slice_urn, version=rspec_version, options=options) return rspec
def renew(self, urns, expiration_time, options={}): aggregate = DummyAggregate(self) slivers = aggregate.get_slivers(urns) if not slivers: raise SearchFailed(urns) slice = slivers[0] requested_time = utcparse(expiration_time) record = {'expires': int(datetime_to_epoch(requested_time))} self.shell.UpdateSlice({ 'slice_id': slice['slice_id'], 'fileds': record }) description = self.describe(urns, 'GENI 3', options) return description['geni_slivers']
def provision(self, urns, options={}): # update users slices = DummySlices(self) aggregate = DummyAggregate(self) slivers = aggregate.get_slivers(urns) slice = slivers[0] geni_users = options.get('geni_users', []) #users = slices.verify_users(None, slice, geni_users, options=options) # update sliver allocation states and set them to geni_provisioned sliver_ids = [sliver['sliver_id'] for sliver in slivers] dbsession=self.api.dbsession() SliverAllocation.set_allocations(sliver_ids, 'geni_provisioned',dbsession) version_manager = VersionManager() rspec_version = version_manager.get_version(options['geni_rspec_version']) return self.describe(urns, rspec_version, options=options)
def provision(self, urns, options={}): # update users slices = DummySlices(self) aggregate = DummyAggregate(self) slivers = aggregate.get_slivers(urns) slice = slivers[0] geni_users = options.get('geni_users', []) #users = slices.verify_users(None, slice, geni_users, options=options) # update sliver allocation states and set them to geni_provisioned sliver_ids = [sliver['sliver_id'] for sliver in slivers] dbsession = self.api.dbsession() SliverAllocation.set_allocations(sliver_ids, 'geni_provisioned', dbsession) version_manager = VersionManager() rspec_version = version_manager.get_version( options['geni_rspec_version']) return self.describe(urns, rspec_version, options=options)
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 allocate (self, urn, rspec_string, expiration, options={}): xrn = Xrn(urn) aggregate = DummyAggregate(self) slices = DummySlices(self) 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 slice record exists slice = slices.verify_slice(xrn.hrn, slice_record, expiration=expiration, options=options) # ensure person records exists #persons = slices.verify_persons(xrn.hrn, slice, users, peer, sfa_peer, options=options) # add/remove slice from nodes request_nodes = rspec.version.get_nodes_with_slivers() nodes = slices.verify_slice_nodes(urn, slice, request_nodes) return aggregate.describe([xrn.get_urn()], version=rspec.version)
def describe(self, urns, version, options={}): aggregate = DummyAggregate(self) return aggregate.describe(urns, version=version, options=options)
def list_resources (self, version=None, options={}): aggregate = DummyAggregate(self) rspec = aggregate.list_resources(version=version, options=options) return rspec
def list_resources(self, version=None, options={}): aggregate = DummyAggregate(self) rspec = aggregate.list_resources(version=version, options=options) return rspec
def describe(self, urns, version, options=None): if options is None: options={} aggregate = DummyAggregate(self) return aggregate.describe(urns, version=version, options=options)