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
|
||||
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>
|
||||
|
||||
The OpenStack authentication URL
|
||||
The OpenStack authentication URL. Default is ``OS_AUTH_URL`` or
|
||||
``LIBRA_URL`` environment variables
|
||||
|
||||
.. 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>
|
||||
|
||||
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>
|
||||
|
||||
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>
|
||||
|
||||
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:
|
||||
|
||||
|
@@ -21,9 +21,7 @@ def main():
|
||||
options = ClientOptions()
|
||||
args = options.run()
|
||||
|
||||
api = LibraAPI(args.os_username, args.os_password, args.os_tenant_name,
|
||||
args.os_auth_url, args.os_region_name, args.insecure,
|
||||
args.debug, args.bypass_url)
|
||||
api = LibraAPI(args)
|
||||
|
||||
cmd = args.command.replace('-', '_')
|
||||
method = getattr(api, '{cmd}_lb'.format(cmd=cmd))
|
||||
|
@@ -13,6 +13,9 @@
|
||||
# under the License.
|
||||
|
||||
import argparse
|
||||
from novaclient import utils
|
||||
|
||||
LIBRA_DEFAULT_SERVICE_TYPE = 'hpext:lbaas'
|
||||
|
||||
|
||||
class ClientOptions(object):
|
||||
@@ -24,30 +27,35 @@ class ClientOptions(object):
|
||||
'--os_auth_url',
|
||||
metavar='<auth-url>',
|
||||
required=True,
|
||||
default=utils.env('OS_AUTH_URL', 'LIBRA_URL'),
|
||||
help='Authentication URL'
|
||||
)
|
||||
self.options.add_argument(
|
||||
'--os_username',
|
||||
metavar='<auth-user-name>',
|
||||
required=True,
|
||||
default=utils.env('OS_USERNAME', 'LIBRA_USERNAME'),
|
||||
help='Authentication username'
|
||||
)
|
||||
self.options.add_argument(
|
||||
'--os_password',
|
||||
metavar='<auth-password>',
|
||||
required=True,
|
||||
default=utils.env('OS_PASSWORD', 'LIBRA_PASSWORD'),
|
||||
help='Authentication password'
|
||||
)
|
||||
self.options.add_argument(
|
||||
'--os_tenant_name',
|
||||
metavar='<auth-tenant-name>',
|
||||
required=True,
|
||||
default=utils.env('OS_TENANT_NAME', 'LIBRA_PROJECT_ID'),
|
||||
help='Authentication tenant'
|
||||
)
|
||||
self.options.add_argument(
|
||||
'--os_region_name',
|
||||
metavar='<region-name>',
|
||||
required=True,
|
||||
default=utils.env('OS_REGION_NAME', 'LIBRAL_REGION_NAME'),
|
||||
help='Authentication region'
|
||||
)
|
||||
self.options.add_argument(
|
||||
@@ -64,6 +72,12 @@ class ClientOptions(object):
|
||||
'--bypass_url',
|
||||
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(
|
||||
metavar='<subcommand>', dest='command'
|
||||
)
|
||||
|
@@ -51,18 +51,17 @@ novaclient.exceptions.from_response = from_response
|
||||
|
||||
|
||||
class LibraAPI(object):
|
||||
def __init__(self, username, password, tenant, auth_url, region,
|
||||
insecure, debug, bypass_url):
|
||||
def __init__(self, args):
|
||||
self.nova = client.HTTPClient(
|
||||
username,
|
||||
password,
|
||||
tenant,
|
||||
auth_url,
|
||||
region_name=region,
|
||||
service_type='compute',
|
||||
http_log_debug=debug,
|
||||
insecure=insecure,
|
||||
bypass_url=bypass_url
|
||||
args.os_username,
|
||||
args.os_password,
|
||||
args.os_tenant_name,
|
||||
args.os_auth_url,
|
||||
region_name=args.os_region_name,
|
||||
service_type=args.service_type,
|
||||
http_log_debug=args.debug,
|
||||
insecure=args.insecure,
|
||||
bypass_url=args.bypass_url
|
||||
)
|
||||
|
||||
def limits_lb(self, args):
|
||||
|
@@ -30,12 +30,25 @@ class DummyModifyArgs(object):
|
||||
self.name = 'a-modified-loadbalancer'
|
||||
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):
|
||||
""" Used to capture data that would be sent to the API server """
|
||||
def __init__(self, username, password, tenant, auth_url, region):
|
||||
self.postdata = 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):
|
||||
""" Store the post data and execute as normal """
|
||||
self.postdata = kwargs['body']
|
||||
|
Reference in New Issue
Block a user