diff options
| author | Cao Shufeng <caosf.fnst@cn.fujitsu.com> | 2016-07-10 19:08:06 +0800 |
|---|---|---|
| committer | Nate Potter <nathaniel.potter@intel.com> | 2016-08-16 16:16:13 +0000 |
| commit | b76f5944130e29ee1bf3095c966a393c489c05e6 (patch) | |
| tree | d6a7dd02b4cb683a558f14849c904d6adf67ad3e /cinderclient/exceptions.py | |
| parent | 0daa4aa0238f3399e166af8833ef1d2816f361fd (diff) | |
| download | python-cinderclient-b76f5944130e29ee1bf3095c966a393c489c05e6.tar.gz | |
Add "start_version" and "end_version" support to argparse
Now, "cinder help subcommand" can not show whether an argument
is supported for a specific microversion.
With this change, developers only need to add a start_version or
end_version in the utils.arg wrap, cinderclient will support
the microversion for that arguement.
@utils.arg(
'--foo',
start_version='3.1')
@utils.arg(
'--bar',
start_version='3.2',
end_version='3.5')
def do_some_action():
......
In previous example, an exception will be raised for such command:
$ cinder --os-volume-api-version 3.6 --bar some-ation
And only "--foo" will show up for such help command:
$ cinder --os-volume-api-version 3.1 help some-ation
Change-Id: I74137486992846bbf9fdff53c009851db2356eef
Partial-Bug: #1600567
Co-Authored-By: Nate Potter <nathaniel.potter@intel.com>
Diffstat (limited to 'cinderclient/exceptions.py')
| -rw-r--r-- | cinderclient/exceptions.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/cinderclient/exceptions.py b/cinderclient/exceptions.py index 72366c3..6d9e707 100644 --- a/cinderclient/exceptions.py +++ b/cinderclient/exceptions.py @@ -28,6 +28,34 @@ class UnsupportedVersion(Exception): pass +class UnsupportedAttribute(AttributeError): + """Indicates that the user is trying to transmit the argument to a method, + which is not supported by selected version. + """ + + def __init__(self, argument_name, start_version, end_version): + if not start_version.is_null() and not end_version.is_null(): + self.message = ( + "'%(name)s' argument is only allowed for microversions " + "%(start)s - %(end)s." % {"name": argument_name, + "start": start_version.get_string(), + "end": end_version.get_string()}) + elif not start_version.is_null(): + self.message = ( + "'%(name)s' argument is only allowed since microversion " + "%(start)s." % {"name": argument_name, + "start": start_version.get_string()}) + + elif not end_version.is_null(): + self.message = ( + "'%(name)s' argument is not allowed after microversion " + "%(end)s." % {"name": argument_name, + "end": end_version.get_string()}) + + def __str__(self): + return self.message + + class InvalidAPIVersion(Exception): pass |
