summaryrefslogtreecommitdiff
path: root/nova/cmd
diff options
context:
space:
mode:
authorHongbin Lu <hongbin034@gmail.com>2017-12-01 23:03:04 +0000
committerHongbin Lu <hongbin034@gmail.com>2017-12-07 23:38:47 +0000
commitc7b51a63b0c3b5ad80979060bbfe49287e6da847 (patch)
treef0782bd373b459f59408fd3d697430f8e8b5bad1 /nova/cmd
parent81544829d14aebaaa717ffbe6ec33c67a2f11b7f (diff)
downloadnova-c7b51a63b0c3b5ad80979060bbfe49287e6da847.tar.gz
Add support for listing hosts in cellv2
Add a ``nova-manage cell_v2 list_hosts`` command for listing hosts in one or all v2 cells. Change-Id: Ie8eaa8701aafac10e030568107b8e6255a60434d Closes-Bug: #1735687
Diffstat (limited to 'nova/cmd')
-rw-r--r--nova/cmd/manage.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py
index 939f524da3..956d3dba57 100644
--- a/nova/cmd/manage.py
+++ b/nova/cmd/manage.py
@@ -1838,6 +1838,34 @@ class CellV2Commands(object):
return 0
@args('--cell_uuid', metavar='<cell_uuid>', dest='cell_uuid',
+ help=_('The uuid of the cell.'))
+ def list_hosts(self, cell_uuid=None):
+ """Lists the hosts in one or all v2 cells."""
+ ctxt = context.get_admin_context()
+ if cell_uuid:
+ # Find the CellMapping given the uuid.
+ try:
+ cell_mapping = objects.CellMapping.get_by_uuid(ctxt, cell_uuid)
+ except exception.CellMappingNotFound:
+ print(_('Cell with uuid %s was not found.') % cell_uuid)
+ return 1
+
+ host_mappings = objects.HostMappingList.get_by_cell_id(
+ ctxt, cell_mapping.id)
+ else:
+ host_mappings = objects.HostMappingList.get_all(ctxt)
+
+ field_names = [_('Cell Name'), _('Cell UUID'), _('Hostname')]
+
+ t = prettytable.PrettyTable(field_names)
+ for host in sorted(host_mappings, key=lambda _host: _host.host):
+ fields = [host.cell_mapping.name, host.cell_mapping.uuid,
+ host.host]
+ t.add_row(fields)
+ print(t)
+ return 0
+
+ @args('--cell_uuid', metavar='<cell_uuid>', dest='cell_uuid',
required=True, help=_('The uuid of the cell.'))
@args('--host', metavar='<host>', dest='host',
required=True, help=_('The host to delete.'))