From e927fbefcf7b5a8481f595543546745e41c0b5ea Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Sun, 27 Nov 2016 05:36:28 -0800 Subject: [PATCH] Admin utility: add in ability to update edge reservations There may be certain cases when an admin wants to update the edge reservations she/he can do it as follows: 1. Use the admin utility to update cpu reservetsions - use resource cpu 2. Use the admin utility to update memory reservations - use resource memory The following can be set: limits, shares, reservations. Change-Id: Ib14cc70bc162aae1b7bc0afdff1872b021d9a0c9 --- doc/source/admin_util.rst | 4 ++ .../admin/plugins/nsxv/resources/edges.py | 43 ++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/doc/source/admin_util.rst b/doc/source/admin_util.rst index 64459a60fb..09de6d8623 100644 --- a/doc/source/admin_util.rst +++ b/doc/source/admin_util.rst @@ -48,6 +48,10 @@ Edges nsxadmin -o nsx-update -r edges -p edge-id=edge-55 --property syslog-server=none +- Update reservations of an edge:: + + nsxadmin -o nsx-update -r edges -p edge-id=edge-55 --property resource= --property limit= --property reservation= --property shares= + Orphaned Edges ~~~~~~~~~~~~~~ diff --git a/vmware_nsx/shell/admin/plugins/nsxv/resources/edges.py b/vmware_nsx/shell/admin/plugins/nsxv/resources/edges.py index 11a7c1a59c..ecc6e59536 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv/resources/edges.py +++ b/vmware_nsx/shell/admin/plugins/nsxv/resources/edges.py @@ -279,6 +279,40 @@ def change_edge_appliance(edge_id): change_edge_ha(az.edge_ha, edge_id) +def change_edge_appliance_reservations(properties): + reservations = {} + res = {} + if properties.get('limit'): + res['limit'] = properties.get('limit') + if properties.get('reservation'): + res['reservation'] = properties.get('reservation') + if properties.get('shares'): + res['shares'] = properties.get('shares') + resource = properties.get('resource') + if not res: + LOG.error(_LE("Please configure reservations")) + return + if resource == 'cpu': + reservations['cpuReservation'] = res + elif resource == 'memory': + reservations['memoryReservation'] = res + else: + LOG.error(_LE("Please configure resource")) + return + edge_id = properties.get('edge-id') + h, edge = nsxv.get_edge(edge_id) + appliances = edge['appliances']['appliances'] + for appliance in appliances: + appliance.update(reservations) + request = {'appliances': appliances} + try: + nsxv.change_edge_appliance(edge_id, request) + except nsxv_exceptions.ResourceNotFound as e: + LOG.error(_LE("Edge %s not found"), 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""" @@ -288,7 +322,12 @@ def nsx_update_edge(resource, event, trigger, **kwargs): "--property size= or --property appliances=True. " "For syslog, add --property syslog-server=|none and " "(optional) --property syslog-server2= and/or " - "(optional) --property syslog-proto=[tcp/udp]") + "(optional) --property syslog-proto=[tcp/udp] " + "For edge reservations, add " + "--property resource=cpu|memory and " + "(optional) --property limit= and/or " + "(optional) --property shares= and/or " + "(optional) --property reservation=") if not kwargs.get('property'): LOG.error(usage_msg) return @@ -312,6 +351,8 @@ def nsx_update_edge(resource, event, trigger, **kwargs): delete_edge_syslog(properties['edge-id']) else: change_edge_syslog(properties) + elif properties.get('resource'): + change_edge_appliance_reservations(properties) else: # no attribute was specified LOG.error(usage_msg)