From a98053dacd2401d1064053ca77dd1a42ddca3391 Mon Sep 17 00:00:00 2001 From: Amey Bhide Date: Thu, 12 Nov 2015 13:31:11 -0800 Subject: [PATCH] [Admin Utility]: Add command to enable NSXv Edge HA Change-Id: I88fb8478fd840ec575654ff0fdc4426922007d15 --- .../admin/plugins/nsxv/resources/edges.py | 31 +++++++++++++++++-- vmware_nsx/plugins/nsx_v/vshield/vcns.py | 6 ++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/tools/python-nsxadmin/admin/plugins/nsxv/resources/edges.py b/tools/python-nsxadmin/admin/plugins/nsxv/resources/edges.py index 599a5e4ddc..45ec5c5532 100644 --- a/tools/python-nsxadmin/admin/plugins/nsxv/resources/edges.py +++ b/tools/python-nsxadmin/admin/plugins/nsxv/resources/edges.py @@ -18,20 +18,21 @@ import logging from admin.plugins.common import constants from admin.plugins.common import formatters from admin.plugins.common.utils import output_header +from admin.plugins.common.utils import parse_multi_keyval_opt from admin.plugins.common.utils import query_yes_no import admin.plugins.nsxv.resources.utils as utils from admin.shell import Operations from neutron.callbacks import registry -from neutron.i18n import _LI +from neutron.i18n import _LE, _LI from vmware_nsx.db import nsxv_db LOG = logging.getLogger(__name__) +nsxv = utils.get_nsxv_client() def get_nsxv_edges(): - nsxv = utils.get_nsxv_client() edges = nsxv.get_edges()[1] return edges['edgePage'].get('data', []) @@ -102,6 +103,29 @@ def nsx_delete_orphaned_edges(resource, event, trigger, **kwargs): LOG.info(_LI("After delete; Orphaned Edges: %s"), get_orphaned_edges()) +@output_header +def nsx_update_edge(resource, event, trigger, **kwargs): + """Update edge properties""" + if not kwargs.get('property'): + LOG.error(_LE("Need to specify edge-id parameter and " + "attribute to update. Add --property edge-id= " + "--property highavailability=True")) + return + properties = parse_multi_keyval_opt(kwargs['property']) + if not properties.get('edge-id'): + LOG.error(_LE("Need to specify edge-id. " + "Add --property edge-id=")) + return + LOG.info(_LI("Updating NSXv edge: %(edge)s with properties\n%(prop)s"), + {'edge': properties.get('edge-id'), 'prop': properties}) + if properties.get('highavailability'): + ha = bool(properties.get('highavailability').lower() == "true") + ha_request = { + 'featureType': 'highavailability_4.0', + 'enabled': ha} + return nsxv.enable_ha(properties.get('edge-id'), ha_request, async=False) + + registry.subscribe(nsx_list_edges, constants.EDGES, Operations.LIST.value) @@ -114,3 +138,6 @@ registry.subscribe(nsx_list_orphaned_edges, registry.subscribe(nsx_delete_orphaned_edges, constants.EDGES, Operations.CLEAN.value) +registry.subscribe(nsx_update_edge, + constants.EDGES, + Operations.NSX_UPDATE.value) diff --git a/vmware_nsx/plugins/nsx_v/vshield/vcns.py b/vmware_nsx/plugins/nsx_v/vshield/vcns.py index 3484b76e1f..541e619bf4 100644 --- a/vmware_nsx/plugins/nsx_v/vshield/vcns.py +++ b/vmware_nsx/plugins/nsx_v/vshield/vcns.py @@ -801,9 +801,11 @@ class Vcns(object): return self.do_request(HTTP_PUT, uri, et.tostring(tuning), format='xml', decode=True) - def enable_ha(self, edge_id, request_config): + def enable_ha(self, edge_id, request_config, async=True): """Enable HA in the given edge.""" - uri = "/api/4.0/edges/%s/highavailability/config?async=true" % edge_id + uri = "/api/4.0/edges/%s/highavailability/config" % edge_id + if async: + uri += "?async=true" return self.do_request(HTTP_PUT, uri, request_config) def upload_edge_certificate(self, edge_id, request):