예제 #1
0
    def provision(self, urns, options=None):
        if options is None: options={}
        # update sliver allocation states and set them to geni_provisioned
        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)
        
        instances = aggregate.get_instances(xrn)
        # Allocate new floating IP per the instance
        servers = aggregate.check_floatingip(instances, True)
        aggregate.create_floatingip(tenant_name, servers)

        sliver_ids=[]
        for instance in instances:
            sliver_id = OSXrn(name=('koren'+'.'+ instance.name), id=instance.id, type='node+openstack').get_urn()
            sliver_ids.append(sliver_id)
        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)
예제 #2
0
    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