Skip to content

Commit

Permalink
Support flavor create call with cells
Browse files Browse the repository at this point in the history
Change-Id: I3bfe5a302227e86b9dccac685f89f165abd941b4
  • Loading branch information
sorrison committed Jan 8, 2015
1 parent 2d9c32e commit 5abc884
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions nova/cells/manager.py
Expand Up @@ -612,3 +612,7 @@ def remove_host_from_aggregate(self, ctxt, cell_name,
response = self.msg_runner.remove_host_from_aggregate(
ctxt, cell_name, aggregate_id, host_name)
return self._response_to_aggregate(response)

def flavor_create(self, ctxt, cell_name, values):
response = self.msg_runner.flavor_create(ctxt,
cell_name, values)
9 changes: 9 additions & 0 deletions nova/cells/messaging.py
Expand Up @@ -997,6 +997,9 @@ def remove_host_from_aggregate(self, message, aggregate_id, host_name):
message.ctxt, aggregate_id, host_name)
return jsonutils.to_primitive(response)

def flavor_create(self, message, values):
return self.db.flavor_create(message.ctxt, values)


class _BroadcastMessageMethods(_BaseMessageMethods):
"""These are the methods that can be called as a part of a broadcast
Expand Down Expand Up @@ -1942,6 +1945,12 @@ def remove_host_from_aggregate(self, ctxt, cell_name,
cell_name, need_response=True)
return message.process()

def flavor_create(self, ctxt, cell_name, values):
message = _TargetedMessage(self, ctxt, 'flavor_create',
dict(values=values),
'down', cell_name, need_response=True)
return message.process()

@staticmethod
def get_message_types():
return _CELL_MESSAGE_TYPE_TO_MESSAGE_CLS.keys()
Expand Down
6 changes: 6 additions & 0 deletions nova/cells/rpcapi.py
Expand Up @@ -612,6 +612,12 @@ def backup_instance(self, ctxt, instance, image_id, backup_type, rotation):
backup_type=backup_type,
rotation=rotation)

def flavor_create(self, ctxt, cell_name, values):
cctxt = self.client.prepare(version='1.24.1')
return cctxt.call(ctxt, 'flavor_create',
cell_name=cell_name,
values=values)

def rebuild_instance(self, ctxt, instance, new_pass, injected_files,
image_ref, orig_image_ref, orig_sys_metadata, bdms,
recreate=False, on_shared_storage=False, host=None,
Expand Down
11 changes: 10 additions & 1 deletion nova/compute/flavors.py
Expand Up @@ -25,6 +25,7 @@
from oslo.db import exception as db_exc
import six

from nova.cells import rpcapi as cell_rpcapi
from nova import context
from nova import db
from nova import exception
Expand Down Expand Up @@ -91,6 +92,9 @@ def _int_or_none(val):
def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None,
swap=0, rxtx_factor=1.0, is_public=True):
"""Creates flavors."""
cell = None
if CONF.cells.enable and '@' in name:
cell, name = name.split('@')
if not flavorid:
flavorid = uuid.uuid4()

Expand Down Expand Up @@ -171,7 +175,12 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None,
raise exception.InvalidInput(reason=_("is_public must be a boolean"))

try:
return db.flavor_create(context.get_admin_context(), kwargs)
ctxt = context.get_admin_context()
if cell:
cells_rpcapi = cell_rpcapi.CellsAPI()
return cells_rpcapi.flavor_create(ctxt, cell, kwargs)
else:
return db.flavor_create(ctxt, kwargs)
except db_exc.DBError as e:
LOG.exception(_LE('DB error: %s'), e)
raise exception.FlavorCreateFailed()
Expand Down

0 comments on commit 5abc884

Please sign in to comment.