Allow environment variables
Allow use environment variables for auth settings in place of options. These are compatible with python-novaclient's environment variables. Fixes bug #1098259 Also add set the service_type and add an option to change it Fixes bug #1089274 Change-Id: I20b5714e19a34d1a29eb33002e32e9dafefe5e9d
This commit is contained in:
@@ -36,25 +36,35 @@ Global Options
|
|||||||
URL to use as an endpoint instead of the one specified by the Service
|
URL to use as an endpoint instead of the one specified by the Service
|
||||||
Catalog
|
Catalog
|
||||||
|
|
||||||
|
.. option:: --service_type <service-type>
|
||||||
|
|
||||||
|
Alternative service type to use for your cloud provider (default is
|
||||||
|
'hpext:lbaas')
|
||||||
|
|
||||||
.. option:: --os_auth_url <auth-url>
|
.. option:: --os_auth_url <auth-url>
|
||||||
|
|
||||||
The OpenStack authentication URL
|
The OpenStack authentication URL. Default is ``OS_AUTH_URL`` or
|
||||||
|
``LIBRA_URL`` environment variables
|
||||||
|
|
||||||
.. option:: --os_username <auth-user-name>
|
.. option:: --os_username <auth-user-name>
|
||||||
|
|
||||||
The user name to use for authentication
|
The user name to use for authentication. Default is ``OS_USERNAME`` or
|
||||||
|
``LIBRA_USERNAME`` environment variables
|
||||||
|
|
||||||
.. option:: --os_password <auth-password>
|
.. option:: --os_password <auth-password>
|
||||||
|
|
||||||
The password to use for authentication
|
The password to use for authentication. Default is ``OS_PASSWORD`` or
|
||||||
|
``LIBRA_PASSWORD`` environment variables
|
||||||
|
|
||||||
.. option:: --os_tenant_name <auth-tenant-name>
|
.. option:: --os_tenant_name <auth-tenant-name>
|
||||||
|
|
||||||
The tenant to authenticate to
|
The tenant to authenticate to. Default is ``OS_TENANT_NAME`` or
|
||||||
|
``LIBRA_PROJECT_ID`` environment variables
|
||||||
|
|
||||||
.. option:: --os_region_name <region-name>
|
.. option:: --os_region_name <region-name>
|
||||||
|
|
||||||
The region the load balancer is located
|
The region the load balancer is located. Default is ``OS_REGION_NAME`` or
|
||||||
|
``LIBRA_REGION_NAME`` environment variables
|
||||||
|
|
||||||
.. _libra_client-commands:
|
.. _libra_client-commands:
|
||||||
|
|
||||||
|
@@ -21,9 +21,7 @@ def main():
|
|||||||
options = ClientOptions()
|
options = ClientOptions()
|
||||||
args = options.run()
|
args = options.run()
|
||||||
|
|
||||||
api = LibraAPI(args.os_username, args.os_password, args.os_tenant_name,
|
api = LibraAPI(args)
|
||||||
args.os_auth_url, args.os_region_name, args.insecure,
|
|
||||||
args.debug, args.bypass_url)
|
|
||||||
|
|
||||||
cmd = args.command.replace('-', '_')
|
cmd = args.command.replace('-', '_')
|
||||||
method = getattr(api, '{cmd}_lb'.format(cmd=cmd))
|
method = getattr(api, '{cmd}_lb'.format(cmd=cmd))
|
||||||
|
@@ -13,6 +13,9 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
from novaclient import utils
|
||||||
|
|
||||||
|
LIBRA_DEFAULT_SERVICE_TYPE = 'hpext:lbaas'
|
||||||
|
|
||||||
|
|
||||||
class ClientOptions(object):
|
class ClientOptions(object):
|
||||||
@@ -24,30 +27,35 @@ class ClientOptions(object):
|
|||||||
'--os_auth_url',
|
'--os_auth_url',
|
||||||
metavar='<auth-url>',
|
metavar='<auth-url>',
|
||||||
required=True,
|
required=True,
|
||||||
|
default=utils.env('OS_AUTH_URL', 'LIBRA_URL'),
|
||||||
help='Authentication URL'
|
help='Authentication URL'
|
||||||
)
|
)
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
'--os_username',
|
'--os_username',
|
||||||
metavar='<auth-user-name>',
|
metavar='<auth-user-name>',
|
||||||
required=True,
|
required=True,
|
||||||
|
default=utils.env('OS_USERNAME', 'LIBRA_USERNAME'),
|
||||||
help='Authentication username'
|
help='Authentication username'
|
||||||
)
|
)
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
'--os_password',
|
'--os_password',
|
||||||
metavar='<auth-password>',
|
metavar='<auth-password>',
|
||||||
required=True,
|
required=True,
|
||||||
|
default=utils.env('OS_PASSWORD', 'LIBRA_PASSWORD'),
|
||||||
help='Authentication password'
|
help='Authentication password'
|
||||||
)
|
)
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
'--os_tenant_name',
|
'--os_tenant_name',
|
||||||
metavar='<auth-tenant-name>',
|
metavar='<auth-tenant-name>',
|
||||||
required=True,
|
required=True,
|
||||||
|
default=utils.env('OS_TENANT_NAME', 'LIBRA_PROJECT_ID'),
|
||||||
help='Authentication tenant'
|
help='Authentication tenant'
|
||||||
)
|
)
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
'--os_region_name',
|
'--os_region_name',
|
||||||
metavar='<region-name>',
|
metavar='<region-name>',
|
||||||
required=True,
|
required=True,
|
||||||
|
default=utils.env('OS_REGION_NAME', 'LIBRAL_REGION_NAME'),
|
||||||
help='Authentication region'
|
help='Authentication region'
|
||||||
)
|
)
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
@@ -64,6 +72,12 @@ class ClientOptions(object):
|
|||||||
'--bypass_url',
|
'--bypass_url',
|
||||||
help='Use this API endpoint instead of the Service Catalog'
|
help='Use this API endpoint instead of the Service Catalog'
|
||||||
)
|
)
|
||||||
|
self.options.add_argument(
|
||||||
|
'--service_type',
|
||||||
|
default=LIBRA_DEFAULT_SERVICE_TYPE,
|
||||||
|
help='Default ' + LIBRA_DEFAULT_SERVICE_TYPE
|
||||||
|
)
|
||||||
|
|
||||||
subparsers = self.options.add_subparsers(
|
subparsers = self.options.add_subparsers(
|
||||||
metavar='<subcommand>', dest='command'
|
metavar='<subcommand>', dest='command'
|
||||||
)
|
)
|
||||||
|
@@ -51,18 +51,17 @@ novaclient.exceptions.from_response = from_response
|
|||||||
|
|
||||||
|
|
||||||
class LibraAPI(object):
|
class LibraAPI(object):
|
||||||
def __init__(self, username, password, tenant, auth_url, region,
|
def __init__(self, args):
|
||||||
insecure, debug, bypass_url):
|
|
||||||
self.nova = client.HTTPClient(
|
self.nova = client.HTTPClient(
|
||||||
username,
|
args.os_username,
|
||||||
password,
|
args.os_password,
|
||||||
tenant,
|
args.os_tenant_name,
|
||||||
auth_url,
|
args.os_auth_url,
|
||||||
region_name=region,
|
region_name=args.os_region_name,
|
||||||
service_type='compute',
|
service_type=args.service_type,
|
||||||
http_log_debug=debug,
|
http_log_debug=args.debug,
|
||||||
insecure=insecure,
|
insecure=args.insecure,
|
||||||
bypass_url=bypass_url
|
bypass_url=args.bypass_url
|
||||||
)
|
)
|
||||||
|
|
||||||
def limits_lb(self, args):
|
def limits_lb(self, args):
|
||||||
|
@@ -30,12 +30,25 @@ class DummyModifyArgs(object):
|
|||||||
self.name = 'a-modified-loadbalancer'
|
self.name = 'a-modified-loadbalancer'
|
||||||
self.algorithm = 'LEAST_CONNECTIONS'
|
self.algorithm = 'LEAST_CONNECTIONS'
|
||||||
|
|
||||||
|
class MockLibraArgs(object):
|
||||||
|
def __init__(self, username, password, tenant, auth_url, region):
|
||||||
|
self.os_username=username
|
||||||
|
self.os_password=password
|
||||||
|
self.os_tenant_name=tenant
|
||||||
|
self.os_auth_url=auth_url
|
||||||
|
self.os_region_name=region
|
||||||
|
self.service_type='compute'
|
||||||
|
self.debug=False
|
||||||
|
self.insecure=False
|
||||||
|
self.bypass_url=None
|
||||||
|
|
||||||
class MockLibraAPI(LibraAPI):
|
class MockLibraAPI(LibraAPI):
|
||||||
""" Used to capture data that would be sent to the API server """
|
""" Used to capture data that would be sent to the API server """
|
||||||
def __init__(self, username, password, tenant, auth_url, region):
|
def __init__(self, username, password, tenant, auth_url, region):
|
||||||
self.postdata = None
|
self.postdata = None
|
||||||
self.putdata = None
|
self.putdata = None
|
||||||
return super(MockLibraAPI, self).__init__(username, password, tenant, auth_url, region, False, False, None)
|
args=MockLibraArgs(username, password, tenant, auth_url, region)
|
||||||
|
return super(MockLibraAPI, self).__init__(args)
|
||||||
def _post(self, url, **kwargs):
|
def _post(self, url, **kwargs):
|
||||||
""" Store the post data and execute as normal """
|
""" Store the post data and execute as normal """
|
||||||
self.postdata = kwargs['body']
|
self.postdata = kwargs['body']
|
||||||
|
Reference in New Issue
Block a user