Remove case dependancy for user inputs

With the introduction of Lowercase/Uppercase conversion
functions in the utils.py, the following patch removes the
dependancy of the current code on character casing.

utils.convert_to_lowercase is called where the code expects
the input to be in lower case while utils.convert_to_uppercase
will be called where the code expects the input to be in
CAPITAL casing only.

Change-Id: I1c5c3c87f343fc2731469b9a0c38d278f6018a11
This commit is contained in:
reedip 2016-03-01 14:29:24 +09:00 committed by Reedip
parent 64e8c3e21a
commit c33b041c0c
9 changed files with 45 additions and 16 deletions

View File

@ -13,6 +13,7 @@
# under the License.
from neutronclient._i18n import _
from neutronclient.common import utils
from neutronclient.neutron import v2_0 as neutronv20
@ -93,6 +94,7 @@ class CreateMeteringLabelRule(neutronv20.CreateCommand):
parser.add_argument(
'--direction',
default='ingress', choices=['ingress', 'egress'],
type=utils.convert_to_lowercase,
help=_('Direction of traffic, default: ingress.'))
parser.add_argument(
'--excluded',

View File

@ -253,11 +253,13 @@ class CreatePort(neutronV20.CreateCommand, UpdatePortSecGroupMixin,
'| normal | baremetal>',
choices=['direct', 'direct-physical', 'macvtap',
'normal', 'baremetal'],
type=utils.convert_to_lowercase,
help=_('VNIC type for this port.'))
parser.add_argument(
'--vnic_type',
choices=['direct', 'direct-physical', 'macvtap',
'normal', 'baremetal'],
type=utils.convert_to_lowercase,
help=argparse.SUPPRESS)
parser.add_argument(
'--binding-profile',

View File

@ -14,6 +14,7 @@
# under the License.
from neutronclient._i18n import _
from neutronclient.common import utils
from neutronclient.neutron import v2_0 as neutronV20
# key=object_type: value={key=resource, value=cmd_resource}
@ -66,6 +67,7 @@ class CreateRBACPolicy(neutronV20.CreateCommand):
parser.add_argument(
'--type', choices=RBAC_OBJECTS.keys(),
required=True,
type=utils.convert_to_lowercase,
help=_('Type of the object that RBAC policy affects.'))
parser.add_argument(
'--target-tenant',
@ -74,6 +76,7 @@ class CreateRBACPolicy(neutronV20.CreateCommand):
'policy will be enforced.'))
parser.add_argument(
'--action', choices=['access_as_external', 'access_as_shared'],
type=utils.convert_to_lowercase,
required=True,
help=_('Action for the RBAC policy.'))

View File

@ -18,6 +18,7 @@ import argparse
from neutronclient._i18n import _
from neutronclient.common import exceptions
from neutronclient.common import utils
from neutronclient.neutron import v2_0 as neutronV20
@ -314,6 +315,7 @@ class CreateSecurityGroupRule(neutronV20.CreateCommand):
'which the rule is added.'))
parser.add_argument(
'--direction',
type=utils.convert_to_lowercase,
default='ingress', choices=['ingress', 'egress'],
help=_('Direction of traffic: ingress/egress.'))
parser.add_argument(
@ -321,6 +323,7 @@ class CreateSecurityGroupRule(neutronV20.CreateCommand):
help=_('IPv4/IPv6'))
parser.add_argument(
'--protocol',
type=utils.convert_to_lowercase,
help=_('Protocol of packet. Allowed values are '
'[icmp, icmpv6, tcp, udp] and '
'integer representations [0-255].'))

View File

@ -184,10 +184,12 @@ class CreateSubnet(neutronV20.CreateCommand):
help=_('CIDR of subnet to create.'))
parser.add_argument(
'--ipv6-ra-mode',
type=utils.convert_to_lowercase,
choices=['dhcpv6-stateful', 'dhcpv6-stateless', 'slaac'],
help=_('IPv6 RA (Router Advertisement) mode.'))
parser.add_argument(
'--ipv6-address-mode',
type=utils.convert_to_lowercase,
choices=['dhcpv6-stateful', 'dhcpv6-stateless', 'slaac'],
help=_('IPv6 address mode.'))
parser.add_argument(

View File

@ -28,27 +28,31 @@ def add_common_args(parser, is_create=True):
help=_('Description of the IKE policy.'))
parser.add_argument(
'--auth-algorithm',
type=utils.convert_to_lowercase,
default='sha1' if is_create else argparse.SUPPRESS,
help=_('Authentication algorithm in lowercase. '
'Default:sha1'))
help=_('Authentication algorithm, default:sha1.'))
parser.add_argument(
'--encryption-algorithm',
default='aes-128' if is_create else argparse.SUPPRESS,
help=_('Encryption algorithm in lowercase, default:aes-128'))
type=utils.convert_to_lowercase,
help=_('Encryption algorithm, default:aes-128.'))
parser.add_argument(
'--phase1-negotiation-mode',
default='main' if is_create else argparse.SUPPRESS,
choices=['main'],
help=_('IKE Phase1 negotiation mode in lowercase, default:main'))
type=utils.convert_to_lowercase,
help=_('IKE Phase1 negotiation mode, default:main.'))
parser.add_argument(
'--ike-version',
default='v1' if is_create else argparse.SUPPRESS,
choices=['v1', 'v2'],
help=_('IKE version in lowercase, default:v1'))
type=utils.convert_to_lowercase,
help=_('IKE version for the policy, default:v1.'))
parser.add_argument(
'--pfs',
default='group5' if is_create else argparse.SUPPRESS,
help=_('Perfect Forward Secrecy in lowercase, default:group5'))
type=utils.convert_to_lowercase,
help=_('Perfect Forward Secrecy, default:group5.'))
parser.add_argument(
'--lifetime',
metavar="units=UNITS,value=VALUE",
@ -109,7 +113,7 @@ class UpdateIKEPolicy(neutronv20.UpdateCommand):
def add_known_arguments(self, parser):
parser.add_argument(
'--name',
help=_('Updated Name of the IKE policy.'))
help=_('Updated name of the IKE policy.'))
add_common_args(parser, is_create=False)
def args2body(self, parsed_args):

View File

@ -96,7 +96,7 @@ class IPsecSiteConnectionMixin(object):
parser.add_argument(
'--mtu',
default='1500' if is_create else argparse.SUPPRESS,
help=_('MTU size for the connection, default:1500'))
help=_('MTU size for the connection, default:1500.'))
parser.add_argument(
'--initiator',
default='bi-directional' if is_create else argparse.SUPPRESS,

View File

@ -26,19 +26,22 @@ def add_common_args(parser, is_create=True):
parser.add_argument(
'--auth-algorithm',
default='sha1' if is_create else argparse.SUPPRESS,
help=_('Authentication algorithm in lowercase, default:sha1'))
type=utils.convert_to_lowercase,
help=_('Authentication algorithm for IPsec policy, default:sha1.'))
parser.add_argument(
'--description',
help=_('Description of the IPsec policy.'))
parser.add_argument(
'--encryption-algorithm',
default='aes-128' if is_create else argparse.SUPPRESS,
help=_('Encryption algorithm in lowercase, default:aes-128'))
parser.add_argument(
'--encapsulation-mode',
default='tunnel' if is_create else argparse.SUPPRESS,
choices=['tunnel', 'transport'],
help=_('Encapsulation mode in lowercase, default:tunnel'))
type=utils.convert_to_lowercase,
help=_('Encapsulation mode for IPsec policy, default:tunnel.'))
parser.add_argument(
'--encryption-algorithm',
default='aes-128' if is_create else argparse.SUPPRESS,
type=utils.convert_to_lowercase,
help=_('Encryption algorithm for IPsec policy, default:aes-128.'))
parser.add_argument(
'--lifetime',
metavar="units=UNITS,value=VALUE",
@ -47,12 +50,14 @@ def add_common_args(parser, is_create=True):
parser.add_argument(
'--pfs',
default='group5' if is_create else argparse.SUPPRESS,
help=_('Perfect Forward Secrecy in lowercase, default:group5'))
type=utils.convert_to_lowercase,
help=_('Perfect Forward Secrecy for IPsec policy, default:group5.'))
parser.add_argument(
'--transform-protocol',
default='esp' if is_create else argparse.SUPPRESS,
type=utils.convert_to_lowercase,
choices=['esp', 'ah', 'ah-esp'],
help=_('Transform protocol in lowercase, default:esp'))
help=_('Transform protocol for IPsec policy, default:esp.'))
def parse_common_args2body(parsed_args, body):
@ -88,6 +93,7 @@ class CreateIPsecPolicy(neutronv20.CreateCommand):
"""Create an IPsec policy."""
resource = 'ipsecpolicy'
help_resource = 'IPsec policy'
def add_known_arguments(self, parser):
parser.add_argument(

View File

@ -0,0 +1,7 @@
---
other:
- |
This patch provides user the support to use
any form of casing, thus removing the specific
UPPER/lower case inputs required by different
neutron CLIs.