do not require NOVA_VERSION in env, default to 1.1
fixes bug 920474. the nova client was not defaulting to version 1.1 unless NOVA_VERSION was set. This makes version 1.1 the default if NOVA_VERSION is not set in the environment. It also makes shell.py usable from a git checkout as in: PYTHONPATH=$PWD python novaclient/shell.py image-list Change-Id: I02b7e060d1c0694639fcb146a7394b92014c140b
This commit is contained in:
parent
94f18f953c
commit
9c6a1ac205
1
AUTHORS
1
AUTHORS
@ -38,3 +38,4 @@ Sandy Walsh <sandy@darksecretsoftware.com>
|
||||
Unmesh Gurjar <unmesh.gurjar@vertex.co.in>
|
||||
William Wolf <throughnothing@gmail.com>
|
||||
Zhongyue Luo <lzyeval@gmail.com>
|
||||
Scott Moser <smoser@ubuntu.com>
|
||||
|
@ -295,14 +295,16 @@ class HTTPClient(httplib2.Http):
|
||||
|
||||
|
||||
def get_client_class(version):
|
||||
version_map = {
|
||||
'1.1': 'novaclient.v1_1.client.Client',
|
||||
'2': 'novaclient.v1_1.client.Client',
|
||||
}
|
||||
try:
|
||||
version = str(version)
|
||||
client_path = {
|
||||
'1.1': 'novaclient.v1_1.client.Client',
|
||||
'2': 'novaclient.v1_1.client.Client',
|
||||
}[version]
|
||||
client_path = version_map[str(version)]
|
||||
except (KeyError, ValueError):
|
||||
raise exceptions.UnsupportedVersion()
|
||||
msg = "Invalid client version '%s'. must be one of: %s" % (
|
||||
(version, ', '.join(version_map.keys())))
|
||||
raise exceptions.UnsupportedVersion(msg)
|
||||
|
||||
return utils.import_class(client_path)
|
||||
|
||||
|
@ -34,16 +34,19 @@ from novaclient.keystone import shell as shell_keystone
|
||||
from novaclient import utils
|
||||
from novaclient.v1_1 import shell as shell_v1_1
|
||||
|
||||
DEFAULT_NOVA_VERSION = "1.1"
|
||||
|
||||
def env(*vars):
|
||||
|
||||
def env(*vars, **kwargs):
|
||||
"""
|
||||
returns the first environment variable set
|
||||
if none are non-empty, defaults to '' or keyword arg default
|
||||
"""
|
||||
for v in vars:
|
||||
value = os.environ.get(v, None)
|
||||
if value:
|
||||
return value
|
||||
return ''
|
||||
return kwargs.get('default', '')
|
||||
|
||||
|
||||
class NovaClientArgumentParser(argparse.ArgumentParser):
|
||||
@ -116,7 +119,7 @@ class OpenStackComputeShell(object):
|
||||
help='Defaults to env[NOVA_ENDPOINT_NAME] or "publicURL".')
|
||||
|
||||
parser.add_argument('--version',
|
||||
default=env('NOVA_VERSION'),
|
||||
default=env('NOVA_VERSION', default=DEFAULT_NOVA_VERSION),
|
||||
help='Accepts 1.1, defaults to env[NOVA_VERSION].')
|
||||
|
||||
parser.add_argument('--insecure',
|
||||
@ -362,3 +365,7 @@ def main():
|
||||
else:
|
||||
print >> sys.stderr, e
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user