summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/ec2/cloud.py65
-rw-r--r--nova/api/openstack/servers.py29
2 files changed, 14 insertions, 80 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index 161d2d038..7978e08a0 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -94,7 +94,7 @@ class CloudController(object):
"""
def __init__(self):
self.network_manager = utils.import_object(FLAGS.network_manager)
- self.compute_api = compute_api.ComputeAPI()
+ self.compute_api = compute_api.ComputeAPI(self.network_manager)
self.image_service = S3ImageService()
self.setup()
@@ -752,7 +752,6 @@ class CloudController(object):
instance_types.get_by_type(kwargs.get('instance_type', None)),
self.image_service,
kwargs['image_id'],
- self._get_network_topic(context),
min_count=int(kwargs.get('min_count', max_count)),
max_count=max_count,
kernel_id=kwargs.get('kernel_id'),
@@ -768,65 +767,11 @@ class CloudController(object):
def terminate_instances(self, context, instance_id, **kwargs):
"""Terminate each instance in instance_id, which is a list of ec2 ids.
-
- instance_id is a kwarg so its name cannot be modified.
- """
- ec2_id_list = instance_id
+ instance_id is a kwarg so its name cannot be modified."""
logging.debug("Going to start terminating instances")
- for id_str in ec2_id_list:
- internal_id = ec2_id_to_internal_id(id_str)
- logging.debug("Going to try and terminate %s" % id_str)
- try:
- instance_ref = db.instance_get_by_internal_id(context,
- internal_id)
- except exception.NotFound:
- logging.warning("Instance %s was not found during terminate",
- id_str)
- continue
-
- if (instance_ref['state_description'] == 'terminating'):
- logging.warning("Instance %s is already being terminated",
- id_str)
- continue
- now = datetime.datetime.utcnow()
- self.compute_api.update_instance(context,
- instance_ref['id'],
- state_description='terminating',
- state=0,
- terminated_at=now)
-
- # FIXME(ja): where should network deallocate occur?
- address = db.instance_get_floating_address(context,
- instance_ref['id'])
- if address:
- logging.debug("Disassociating address %s" % address)
- # NOTE(vish): Right now we don't really care if the ip is
- # disassociated. We may need to worry about
- # checking this later. Perhaps in the scheduler?
- network_topic = self._get_network_topic(context)
- rpc.cast(context,
- network_topic,
- {"method": "disassociate_floating_ip",
- "args": {"floating_address": address}})
-
- address = db.instance_get_fixed_address(context,
- instance_ref['id'])
- if address:
- logging.debug("Deallocating address %s" % address)
- # NOTE(vish): Currently, nothing needs to be done on the
- # network node until release. If this changes,
- # we will need to cast here.
- self.network_manager.deallocate_fixed_ip(context.elevated(),
- address)
-
- host = instance_ref['host']
- if host:
- rpc.cast(context,
- db.queue_get_for(context, FLAGS.compute_topic, host),
- {"method": "terminate_instance",
- "args": {"instance_id": instance_ref['id']}})
- else:
- db.instance_destroy(context, instance_ref['id'])
+ for ec2_id in instance_id:
+ internal_id = ec2_id_to_internal_id(ec2_id)
+ self.compute_api.delete_instance(context, internal_id)
return True
def reboot_instances(self, context, instance_id, **kwargs):
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 519250e60..e7ab17d03 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -18,11 +18,12 @@
import webob
from webob import exc
+from nova import context
+from nova import exception
from nova import flags
from nova import rpc
from nova import utils
from nova import wsgi
-from nova import context
from nova.api.openstack import faults
from nova.compute import api as compute_api
from nova.compute import instance_types
@@ -82,7 +83,6 @@ class Controller(wsgi.Controller):
if not db_driver:
db_driver = FLAGS.db_driver
self.db_driver = utils.import_object(db_driver)
- self.network_manager = utils.import_object(FLAGS.network_manager)
self.compute_api = compute_api.ComputeAPI()
super(Controller, self).__init__()
@@ -120,11 +120,11 @@ class Controller(wsgi.Controller):
""" Destroys a server """
user_id = req.environ['nova.context']['user']['id']
ctxt = context.RequestContext(user_id, user_id)
- instance = self.db_driver.instance_get_by_internal_id(ctxt, int(id))
- if instance and instance['user_id'] == user_id:
- self.db_driver.instance_destroy(ctxt, id)
- return faults.Fault(exc.HTTPAccepted())
- return faults.Fault(exc.HTTPNotFound())
+ try:
+ self.compute_api.delete_instance(ctxt, int(id))
+ except exception.NotFound:
+ return faults.Fault(exc.HTTPNotFound())
+ return exc.HTTPAccepted()
def create(self, req):
""" Creates a new server for a given user """
@@ -139,7 +139,6 @@ class Controller(wsgi.Controller):
instance_types.get_by_flavor_id(env['server']['flavorId']),
utils.import_object(FLAGS.image_service),
env['server']['imageId'],
- self._get_network_topic(ctxt),
name=env['server']['name'],
description=env['server']['name'],
key_name=key_pair['name'],
@@ -166,7 +165,7 @@ class Controller(wsgi.Controller):
if 'name' in inst_dict['server']:
update_dict['display_name'] = inst_dict['server']['name']
- self.compute_api.update_instance(ctxt, instance['id'], update_dict)
+ self.compute_api.update_instance(ctxt, instance['id'], **update_dict)
return exc.HTTPNoContent()
def action(self, req, id):
@@ -185,14 +184,4 @@ class Controller(wsgi.Controller):
# TODO(gundlach): pass reboot_type, support soft reboot in
# virt driver
self.compute_api.reboot(ctxt, id)
-
- def _get_network_topic(self, context):
- """Retrieves the network host for a project"""
- network_ref = self.network_manager.get_network(context)
- host = network_ref['host']
- if not host:
- host = rpc.call(context,
- FLAGS.network_topic,
- {"method": "set_network_host",
- "args": {"network_id": network_ref['id']}})
- return self.db_driver.queue_get_for(context, FLAGS.network_topic, host)
+ return exc.HTTPAccepted()