diff options
Diffstat (limited to 'openstackclient/network')
| -rw-r--r-- | openstackclient/network/v2/network.py | 30 | ||||
| -rw-r--r-- | openstackclient/network/v2/network_qos_rule.py | 32 |
2 files changed, 34 insertions, 28 deletions
diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py index e3737895..33decd82 100644 --- a/openstackclient/network/v2/network.py +++ b/openstackclient/network/v2/network.py @@ -129,11 +129,6 @@ def _get_attrs_network(client_manager, parsed_args): attrs['qos_policy_id'] = _qos_policy.id if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy: attrs['qos_policy_id'] = None - # Update VLAN Transparency for networks - if parsed_args.transparent_vlan: - attrs['vlan_transparent'] = True - if parsed_args.no_transparent_vlan: - attrs['vlan_transparent'] = False return attrs @@ -172,16 +167,6 @@ def _add_additional_network_options(parser): help=_("VLAN ID for VLAN networks or Tunnel ID for " "GENEVE/GRE/VXLAN networks")) - vlan_transparent_grp = parser.add_mutually_exclusive_group() - vlan_transparent_grp.add_argument( - '--transparent-vlan', - action='store_true', - help=_("Make the network VLAN transparent")) - vlan_transparent_grp.add_argument( - '--no-transparent-vlan', - action='store_true', - help=_("Do not make the network VLAN transparent")) - # TODO(sindhu): Use the SDK resource mapped attribute names once the # OSC minimum requirements include SDK 1.0. @@ -284,6 +269,16 @@ class CreateNetwork(common.NetworkAndComputeShowOne): metavar='<qos-policy>', help=_("QoS policy to attach to this network (name or ID)") ) + vlan_transparent_grp = parser.add_mutually_exclusive_group() + vlan_transparent_grp.add_argument( + '--transparent-vlan', + action='store_true', + help=_("Make the network VLAN transparent")) + vlan_transparent_grp.add_argument( + '--no-transparent-vlan', + action='store_true', + help=_("Do not make the network VLAN transparent")) + _add_additional_network_options(parser) return parser @@ -298,6 +293,11 @@ class CreateNetwork(common.NetworkAndComputeShowOne): def take_action_network(self, client, parsed_args): attrs = _get_attrs_network(self.app.client_manager, parsed_args) + if parsed_args.transparent_vlan: + attrs['vlan_transparent'] = True + if parsed_args.no_transparent_vlan: + attrs['vlan_transparent'] = False + obj = client.create_network(**attrs) display_columns, columns = _get_columns_network(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) diff --git a/openstackclient/network/v2/network_qos_rule.py b/openstackclient/network/v2/network_qos_rule.py index baed0424..f50e58b3 100644 --- a/openstackclient/network/v2/network_qos_rule.py +++ b/openstackclient/network/v2/network_qos_rule.py @@ -14,7 +14,6 @@ # under the License. import itertools -import six from osc_lib.command import command from osc_lib import exceptions @@ -27,10 +26,14 @@ from openstackclient.network import sdk_utils RULE_TYPE_BANDWIDTH_LIMIT = 'bandwidth-limit' RULE_TYPE_DSCP_MARKING = 'dscp-marking' RULE_TYPE_MINIMUM_BANDWIDTH = 'minimum-bandwidth' -REQUIRED_PARAMETERS = { - RULE_TYPE_MINIMUM_BANDWIDTH: ['min_kbps', 'direction'], - RULE_TYPE_DSCP_MARKING: ['dscp_mark'], - RULE_TYPE_BANDWIDTH_LIMIT: ['max_kbps', 'max_burst_kbps']} +MANDATORY_PARAMETERS = { + RULE_TYPE_MINIMUM_BANDWIDTH: {'min_kbps', 'direction'}, + RULE_TYPE_DSCP_MARKING: {'dscp_mark'}, + RULE_TYPE_BANDWIDTH_LIMIT: {'max_kbps', 'max_burst_kbps'}} +OPTIONAL_PARAMETERS = { + RULE_TYPE_MINIMUM_BANDWIDTH: set(), + RULE_TYPE_DSCP_MARKING: set(), + RULE_TYPE_BANDWIDTH_LIMIT: {'direction'}} DIRECTION_EGRESS = 'egress' DIRECTION_INGRESS = 'ingress' DSCP_VALID_MARKS = [0, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, @@ -51,17 +54,20 @@ def _get_columns(item): def _check_type_parameters(attrs, type, is_create): - req_params = REQUIRED_PARAMETERS[type] - notreq_params = list(itertools.chain( - *[v for k, v in six.iteritems(REQUIRED_PARAMETERS) if k != type])) + req_params = MANDATORY_PARAMETERS[type] + opt_params = OPTIONAL_PARAMETERS[type] + type_params = req_params | opt_params + notreq_params = set(itertools.chain( + *[v for k, v in MANDATORY_PARAMETERS.items() if k != type])) + notreq_params -= type_params if is_create and None in map(attrs.get, req_params): msg = (_('"Create" rule command for type "%(rule_type)s" requires ' - 'arguments %(args)s') % {'rule_type': type, - 'args': ", ".join(req_params)}) + 'arguments %(args)s') % + {'rule_type': type, 'args': ", ".join(sorted(req_params))}) raise exceptions.CommandError(msg) - if set(six.iterkeys(attrs)) & set(notreq_params): + if set(attrs.keys()) & notreq_params: msg = (_('Rule type "%(rule_type)s" only requires arguments %(args)s') - % {'rule_type': type, 'args': ", ".join(req_params)}) + % {'rule_type': type, 'args': ", ".join(sorted(type_params))}) raise exceptions.CommandError(msg) @@ -183,7 +189,7 @@ class CreateNetworkQosRule(command.ShowOne): RULE_TYPE_DSCP_MARKING, RULE_TYPE_BANDWIDTH_LIMIT], help=(_('QoS rule type (%s)') % - ", ".join(six.iterkeys(REQUIRED_PARAMETERS))) + ", ".join(MANDATORY_PARAMETERS.keys())) ) _add_rule_arguments(parser) return parser |
