diff --git a/vmware_nsx/plugins/nsx_v/vshield/vcns.py b/vmware_nsx/plugins/nsx_v/vshield/vcns.py index c572a0eadf..1cb4ca5f9e 100644 --- a/vmware_nsx/plugins/nsx_v/vshield/vcns.py +++ b/vmware_nsx/plugins/nsx_v/vshield/vcns.py @@ -824,6 +824,12 @@ class Vcns(object): uri += "?async=true" return self.do_request(HTTP_PUT, uri, request_config) + def change_edge_appliance_size(self, edge_id, size): + """Change the size of edge appliances.""" + uri = ("/api/4.0/edges/%s/appliances/?size=%s" % + (edge_id, size)) + return self.do_request(HTTP_POST, uri) + def upload_edge_certificate(self, edge_id, request): """Creates a certificate on the specified Edge appliance.""" uri = '%s/%s/%s' % (TRUSTSTORE_PREFIX, CERTIFICATE, edge_id) diff --git a/vmware_nsx/shell/admin/plugins/nsxv/resources/edges.py b/vmware_nsx/shell/admin/plugins/nsxv/resources/edges.py index 04f4c5cb6a..7155916248 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv/resources/edges.py +++ b/vmware_nsx/shell/admin/plugins/nsxv/resources/edges.py @@ -28,6 +28,8 @@ from neutron.common import exceptions from vmware_nsx._i18n import _LE, _LI from vmware_nsx.db import nsxv_db +import vmware_nsx.plugins.nsx_v.vshield.common.constants as nsxv_constants +import vmware_nsx.plugins.nsx_v.vshield.common.exceptions as nsxv_exceptions LOG = logging.getLogger(__name__) nsxv = utils.get_nsxv_client() @@ -116,6 +118,34 @@ def nsx_delete_orphaned_edges(resource, event, trigger, **kwargs): pprint.pformat(get_orphaned_edges())) +def change_edge_ha(properties): + ha = bool(properties.get('highavailability').lower() == "true") + request = { + 'featureType': 'highavailability_4.0', + 'enabled': ha} + try: + nsxv.enable_ha(properties.get('edge-id'), request, async=False) + except nsxv_exceptions.ResourceNotFound as e: + LOG.error(_LE("Edge %s not found"), properties.get('edge-id')) + except exceptions.NeutronException as e: + LOG.error(_LE("%s"), str(e)) + + +def change_edge_appliance_size(properties): + size = properties.get('size') + if size not in nsxv_constants.ALLOWED_EDGE_SIZES: + LOG.error(_LE("Edge appliance size not in %(size)s"), + {'size': nsxv_constants.ALLOWED_EDGE_SIZES}) + return + try: + nsxv.change_edge_appliance_size( + properties.get('edge-id'), size) + except nsxv_exceptions.ResourceNotFound as e: + LOG.error(_LE("Edge %s not found"), properties.get('edge-id')) + except exceptions.NeutronException as e: + LOG.error(_LE("%s"), str(e)) + + @admin_utils.output_header def nsx_update_edge(resource, event, trigger, **kwargs): """Update edge properties""" @@ -132,14 +162,9 @@ def nsx_update_edge(resource, event, trigger, **kwargs): 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} - try: - nsxv.enable_ha(properties.get('edge-id'), ha_request, async=False) - except exceptions.NeutronException as e: - LOG.error(_LE("%s"), str(e)) + change_edge_ha(properties) + elif properties.get('size'): + change_edge_appliance_size(properties) registry.subscribe(nsx_list_edges, diff --git a/vmware_nsx/tests/unit/nsx_v/vshield/fake_vcns.py b/vmware_nsx/tests/unit/nsx_v/vshield/fake_vcns.py index 3702e3e3a8..1359674058 100644 --- a/vmware_nsx/tests/unit/nsx_v/vshield/fake_vcns.py +++ b/vmware_nsx/tests/unit/nsx_v/vshield/fake_vcns.py @@ -1122,3 +1122,10 @@ class FakeVcns(object): } response = '' return (header, response) + + def change_edge_appliance_size(self, edge_id, size): + header = { + 'status': 204 + } + response = {} + return (header, response)