[AU]Fix help message for supported ops on resource

Fixes the case of the operations supported in the help message
of a resource.
Also fixes list of supported ops where we were listing all the ops
when a invalid op was specified instead of just the ops that are
supported *only* by the resource.

$ nsxadmin -r edges
Supported list of operations for the NSX-V resource ['LIST', 'CLEAN']

If user supplies -o LIST, it won't work. since the callback registration
is case sensitive. So to avoice any ambiguity we show the ops as lower
case.

Supported list of operations for the NSX-V resource ['list', clean'']

Change-Id: If41274181baf0f30502b8821169bbc6e4504ba2d
This commit is contained in:
Akash Gangil 2015-12-02 01:26:11 -08:00
parent 4afa13c3c4
commit 06cd0d5bf0

View File

@ -79,13 +79,13 @@ nsxv3_resources = {
# Add supported NSX-V resources in this dictionary # Add supported NSX-V resources in this dictionary
nsxv_resources = { nsxv_resources = {
constants.EDGES: Resource(constants.EDGES, [Operations.LIST.name, constants.EDGES: Resource(constants.EDGES, [Operations.LIST.value,
Operations.CLEAN.name, Operations.CLEAN.value,
Operations.NSX_UPDATE.value]), Operations.NSX_UPDATE.value]),
constants.SPOOFGUARD_POLICY: Resource(constants.SPOOFGUARD_POLICY, constants.SPOOFGUARD_POLICY: Resource(constants.SPOOFGUARD_POLICY,
[Operations.LIST.name]), [Operations.LIST.value]),
constants.DHCP_BINDING: Resource(constants.DHCP_BINDING, constants.DHCP_BINDING: Resource(constants.DHCP_BINDING,
[Operations.LIST.name, [Operations.LIST.value,
Operations.NSX_UPDATE.value]), Operations.NSX_UPDATE.value]),
} }
@ -132,7 +132,6 @@ cli_opts = [cfg.StrOpt('neutron-conf',
', '.join(nsxv_resources_names))), ', '.join(nsxv_resources_names))),
cfg.StrOpt('operation', cfg.StrOpt('operation',
short='o', short='o',
choices=ops,
help='Supported list of operations: {}' help='Supported list of operations: {}'
.format(', '.join(ops))), .format(', '.join(ops))),
cfg.BoolOpt('force', cfg.BoolOpt('force',
@ -184,16 +183,21 @@ def _validate_resource_choice(resource, nsx_plugin):
def _validate_op_choice(choice, nsx_plugin): def _validate_op_choice(choice, nsx_plugin):
if choice is None and nsx_plugin == 'nsxv': if nsx_plugin == 'nsxv':
LOG.error(_LE('Supported list of operations for the NSX-V resource ' supported_resource_ops = \
'%s'), nsxv_resources[cfg.CONF.resource].supported_ops
nsxv_resources[cfg.CONF.resource].supported_ops) if choice not in supported_resource_ops:
exit(1) LOG.error(_LE('Supported list of operations for the NSX-V '
elif choice is None and nsx_plugin == 'nsxv3': 'resource %s'), supported_resource_ops)
LOG.error(_LE('Supported list of operations for the NSX-V3 resource ' sys.exit(1)
'%s'),
nsxv3_resources[cfg.CONF.resource].supported_ops) elif nsx_plugin == 'nsxv3':
sys.exit(1) supported_resource_ops = \
nsxv3_resources[cfg.CONF.resource].supported_ops
if choice not in supported_resource_ops:
LOG.error(_LE('Supported list of operations for the NSX-V3 '
'resource %s'), supported_resource_ops)
sys.exit(1)
def main(argv=sys.argv[1:]): def main(argv=sys.argv[1:]):