[AU]: Add command to modify edge appliance size

$ nsxadmin -r edges -o nsx-update --property edge-id=edge-55 --property
size=compact
NSX Plugin in use: nsxv
==== [NSX] Update Edge ====
Updating NSXv edge: edge-55 with properties
{'edge-id': 'edge-55', 'size': 'compact'}

Change-Id: I004ec9c9ac480c28186d069e230878201283eb25
This commit is contained in:
Amey Bhide 2016-01-27 13:55:13 -08:00
parent ad5908d923
commit a7d261ce57
3 changed files with 46 additions and 8 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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)