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 perform_operational_action(self, urns, action, options={}): aggregate = OSAggregate(self) action = action.lower() if action == 'geni_start': action_method = aggregate.start_instances elif action == 'geni_stop': action_method = aggregate.stop_instances elif action == 'geni_restart': action_method = aggreate.restart_instances else: raise UnsupportedOperation(action) # fault if sliver is not full allocated (operational status is geni_pending_allocation) description = self.describe(urns, None, options) for sliver in description['geni_slivers']: if sliver['geni_operational_status'] == 'geni_pending_allocation': raise UnsupportedOperation( action, "Sliver must be fully allocated (operational status is not geni_pending_allocation)" ) # # Perform Operational Action Here # instances = aggregate.get_instances(urns) for instance in instances: tenant_name = self.driver.shell.auth_manager.client.tenant_name action_method(tenant_name, instance.name, instance.id) description = self.describe(urns) geni_slivers = self.describe(urns, None, options)['geni_slivers'] return geni_slivers
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 status(self, urns, options={}): aggregate = OSAggregate(self) desc = aggregate.describe(urns) status = { 'geni_urn': desc['geni_urn'], 'geni_slivers': desc['geni_slivers'] } return status
def provision(self, urns, options={}): # update sliver allocation states and set them to geni_provisioned 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) 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 describe(self, urns, version=None, options={}): aggregate = OSAggregate(self) return aggregate.describe(urns, version=version, options=options)
def list_resources(self, version=None, options={}): aggregate = OSAggregate(self) rspec = aggregate.list_resources(version=version, options=options) return rspec