From 5ff2cfd042de7afc4323a3b306ff5be1882fba46 Mon Sep 17 00:00:00 2001 From: Ha Van Tu Date: Thu, 12 Jan 2017 09:57:53 +0700 Subject: Add "qos-policy" option to "port create" & "port set" This patch adds "qos-policy" option to "port create" command, and "qos-policy", "no-qos-policy" options to "port set" command and "qos-policy" option to "port unset". Change-Id: I78072e1ff0dd30a2e23a0fb833ce6ab5cf246016 Co-Authored-By: Nguyen Phuong An Co-Authored-By: Rodolfo Alonso Hernandez Partial-Bug: #1612136 Partially-Implements: blueprint network-commands-options --- openstackclient/network/v2/port.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'openstackclient/network') diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index 9d598fab..3a32916b 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -155,6 +155,13 @@ def _get_attrs(client_manager, parsed_args): if parsed_args.enable_port_security: attrs['port_security_enabled'] = True + if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy: + attrs['qos_policy_id'] = None + + if parsed_args.qos_policy: + attrs['qos_policy_id'] = client_manager.network.find_qos_policy( + parsed_args.qos_policy, ignore_missing=False).id + return attrs @@ -337,7 +344,7 @@ class CreatePort(command.ShowOne): help=_("Name of this port") ) # TODO(singhj): Add support for extended options: - # qos,dhcp + # dhcp secgroups = parser.add_mutually_exclusive_group() secgroups.add_argument( '--security-group', @@ -353,6 +360,11 @@ class CreatePort(command.ShowOne): action='store_true', help=_("Associate no security groups with this port") ) + parser.add_argument( + '--qos-policy', + metavar='', + help=_("Attach QoS policy to this port (name or ID)") + ) port_security = parser.add_mutually_exclusive_group() port_security.add_argument( '--enable-port-security', @@ -403,6 +415,9 @@ class CreatePort(command.ShowOne): attrs['allowed_address_pairs'] = ( _convert_address_pairs(parsed_args)) + if parsed_args.qos_policy: + attrs['qos_policy_id'] = client.find_qos_policy( + parsed_args.qos_policy, ignore_missing=False).id obj = client.create_port(**attrs) display_columns, columns = _get_columns(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) @@ -619,6 +634,11 @@ class SetPort(command.Command): "Specify both --binding-profile and --no-binding-profile " "to overwrite the current binding:profile information.") ) + parser.add_argument( + '--qos-policy', + metavar='', + help=_("Attach QoS policy to this port (name or ID)") + ) parser.add_argument( 'port', metavar="", @@ -675,8 +695,8 @@ class SetPort(command.Command): client = self.app.client_manager.network _prepare_fixed_ips(self.app.client_manager, parsed_args) - attrs = _get_attrs(self.app.client_manager, parsed_args) obj = client.find_port(parsed_args.port, ignore_missing=False) + attrs = _get_attrs(self.app.client_manager, parsed_args) if parsed_args.no_binding_profile: attrs['binding:profile'] = {} @@ -794,6 +814,12 @@ class UnsetPort(command.Command): "[,mac-address=] (repeat option to set " "multiple allowed-address pairs)") ) + parser.add_argument( + '--qos-policy', + action='store_true', + default=False, + help=_("Remove the QoS policy attached to the port") + ) return parser @@ -843,6 +869,8 @@ class UnsetPort(command.Command): msg = _("Port does not contain allowed-address-pair %s") % addr raise exceptions.CommandError(msg) attrs['allowed_address_pairs'] = tmp_addr_pairs + if parsed_args.qos_policy: + attrs['qos_policy_id'] = None if attrs: client.update_port(obj, **attrs) -- cgit v1.2.1