From 64f5f99326d7313c9a9b6341445d98bc7fc76332 Mon Sep 17 00:00:00 2001 From: Andrew Laski Date: Wed, 6 Apr 2016 17:48:36 -0400 Subject: [PATCH] Split out part of map_cell_and_hosts to return a uuid Top level nova-manage methods need to return an exit code. We need a way to run the logic of map_cell_and_hosts and get access to the cell mapping uuid that's used. This splits that logic to a private method that can be shared. The case where all hosts are already mapped to the cell has been modified to return the cell mapping uuid rather than 0. In that case there may still be unmapped instances so getting access to that uuid is beneficial. Change-Id: Ia2d82243fd8e92f270801bcad2222808f2ee1a98 --- nova/cmd/manage.py | 52 ++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index 3562e87f19f9..1f0b7c5da639 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -1202,33 +1202,14 @@ class CellV2Commands(object): instance = instances[-1] print('Next marker: - %s' % instance.uuid) - # TODO(melwitt): Remove this when the oslo.messaging function - # for assembling a transport url from ConfigOpts is available - @args('--transport-url', metavar='', required=True, - dest='transport_url', - help='The transport url for the cell message queue') - @args('--name', metavar='', help='The name of the cell') - @args('--verbose', action='store_true', - help='Return and output the uuid of the created cell') - def map_cell_and_hosts(self, transport_url, name=None, verbose=False): - """EXPERIMENTAL. Create a cell mapping and host mappings for a cell. - - Users not dividing their cloud into multiple cells will be a single - cell v2 deployment and should specify: - - nova-manage cell_v2 map_cell_and_hosts --config-file - - Users running multiple cells can add a cell v2 by specifying: - - nova-manage cell_v2 map_cell_and_hosts --config-file - """ + def _map_cell_and_hosts(self, transport_url, name=None, verbose=False): ctxt = context.RequestContext() cell_mapping_uuid = cell_mapping = None # First, try to detect if a CellMapping has already been created compute_nodes = objects.ComputeNodeList.get_all(ctxt) if not compute_nodes: print(_('No hosts found to map to cell, exiting.')) - return(0) + return None missing_nodes = [] for compute_node in compute_nodes: try: @@ -1250,7 +1231,7 @@ class CellV2Commands(object): cell_mapping_uuid = host_mapping.cell_mapping.uuid if not missing_nodes: print(_('All hosts are already mapped to cell(s), exiting.')) - return(0) + return cell_mapping_uuid # Create the cell mapping in the API database if cell_mapping_uuid is not None: cell_mapping = objects.CellMapping.get_by_uuid( @@ -1269,6 +1250,33 @@ class CellV2Commands(object): host_mapping.create() if verbose: print(cell_mapping_uuid) + return cell_mapping_uuid + + # TODO(melwitt): Remove this when the oslo.messaging function + # for assembling a transport url from ConfigOpts is available + @args('--transport-url', metavar='', required=True, + dest='transport_url', + help='The transport url for the cell message queue') + @args('--name', metavar='', help='The name of the cell') + @args('--verbose', action='store_true', + help='Return and output the uuid of the created cell') + def map_cell_and_hosts(self, transport_url, name=None, verbose=False): + """EXPERIMENTAL. Create a cell mapping and host mappings for a cell. + + Users not dividing their cloud into multiple cells will be a single + cell v2 deployment and should specify: + + nova-manage cell_v2 map_cell_and_hosts --config-file + + Users running multiple cells can add a cell v2 by specifying: + + nova-manage cell_v2 map_cell_and_hosts --config-file + """ + self._map_cell_and_hosts(transport_url, name, verbose) + # online_data_migrations established a pattern of 0 meaning everything + # is done, 1 means run again to do more work. This command doesn't do + # partial work so 0 is appropriate. + return 0 CATEGORIES = {