diff --git a/doc/source/admin_util.rst b/doc/source/admin_util.rst index 7fd77bd81b..3784ba041e 100644 --- a/doc/source/admin_util.rst +++ b/doc/source/admin_util.rst @@ -471,6 +471,16 @@ LBaaS nsxadmin -r lb-monitors -o list +Rate Limit +~~~~~~~~~~ +- Show the current NSX rate limit: + + nsxadmin -r rate-limit -o show + +- Update the NSX rate limit: + +nsxadmin -r rate-limit -o nsx-update --property value=<> + NSXtvd ------ diff --git a/vmware_nsx/shell/admin/plugins/common/constants.py b/vmware_nsx/shell/admin/plugins/common/constants.py index 76cc56460a..238a83d3a6 100644 --- a/vmware_nsx/shell/admin/plugins/common/constants.py +++ b/vmware_nsx/shell/admin/plugins/common/constants.py @@ -44,6 +44,7 @@ LB_SERVICES = 'lb-services' LB_VIRTUAL_SERVERS = 'lb-virtual-servers' LB_POOLS = 'lb-pools' LB_MONITORS = 'lb-monitors' +RATE_LIMIT = 'rate-limit' # NSXV only Resource Constants EDGES = 'edges' diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/http_service.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/http_service.py new file mode 100644 index 0000000000..2bf6824f21 --- /dev/null +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/http_service.py @@ -0,0 +1,74 @@ +# Copyright 2016 VMware, Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron_lib.callbacks import registry +from oslo_log import log as logging + +from vmware_nsx.shell.admin.plugins.common import constants +from vmware_nsx.shell.admin.plugins.common import utils as admin_utils +from vmware_nsx.shell.admin.plugins.nsxv3.resources import utils +import vmware_nsx.shell.resources as shell +from vmware_nsxlib.v3 import nsx_constants + +LOG = logging.getLogger(__name__) +neutron_client = utils.NeutronDbClient() + + +@admin_utils.output_header +def nsx_rate_limit_show(resource, event, trigger, **kwargs): + """Show the current NSX rate limit.""" + + nsxlib = utils.get_connected_nsxlib() + if not nsxlib.feature_supported(nsx_constants.FEATURE_RATE_LIMIT): + LOG.error("This utility is not available for NSX version %s", + nsxlib.get_version()) + return + + rate_limit = nsxlib.http_services.get_rate_limit() + LOG.info("Current NSX rate limit is %s", rate_limit) + + +@admin_utils.output_header +def nsx_rate_limit_update(resource, event, trigger, **kwargs): + """Set the NSX rate limit + + The default value is 40. 0 means no limit + """ + nsxlib = utils.get_connected_nsxlib() + if not nsxlib.feature_supported(nsx_constants.FEATURE_RATE_LIMIT): + LOG.error("This utility is not available for NSX version %s", + nsxlib.get_version()) + return + + rate_limit = None + if kwargs.get('property'): + properties = admin_utils.parse_multi_keyval_opt(kwargs['property']) + rate_limit = properties.get('value', None) + if rate_limit is None: + usage = ("nsxadmin -r rate-limit -o nsx-update " + "--property value=") + LOG.error("Missing parameters. Usage: %s", usage) + return + + nsxlib.http_services.update_rate_limit(rate_limit) + LOG.info("NSX rate limit was updated to %s", rate_limit) + + +registry.subscribe(nsx_rate_limit_show, + constants.RATE_LIMIT, + shell.Operations.SHOW.value) + +registry.subscribe(nsx_rate_limit_update, + constants.RATE_LIMIT, + shell.Operations.NSX_UPDATE.value) diff --git a/vmware_nsx/shell/resources.py b/vmware_nsx/shell/resources.py index 8e71d77a90..cca463745a 100644 --- a/vmware_nsx/shell/resources.py +++ b/vmware_nsx/shell/resources.py @@ -130,7 +130,10 @@ nsxv3_resources = { constants.LB_POOLS: Resource(constants.LB_POOLS, [Operations.LIST.value]), constants.LB_MONITORS: Resource(constants.LB_MONITORS, - [Operations.LIST.value]) + [Operations.LIST.value]), + constants.RATE_LIMIT: Resource(constants.RATE_LIMIT, + [Operations.SHOW.value, + Operations.NSX_UPDATE.value]) } # Add supported NSX-V resources in this dictionary