Add os-client-config support for examples
Add the --os-cloud option to the examples so developers can use OCC for examples. Change-Id: Ieaa7568c83a7c3c87bd3524e078a35da23ffde92
This commit is contained in:
@@ -171,6 +171,14 @@ def option_parser():
|
|||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description='A demonstration framework')
|
description='A demonstration framework')
|
||||||
# Global arguments
|
# Global arguments
|
||||||
|
parser.add_argument(
|
||||||
|
'--os-cloud',
|
||||||
|
dest='cloud',
|
||||||
|
metavar='<cloud>',
|
||||||
|
default=env('OS_CLOUD', default=None),
|
||||||
|
help=('Cloud configuration from ' +
|
||||||
|
'https://pypi.python.org/pypi/os-client-config (Env: OS_CLOUD)')
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--os-auth-plugin',
|
'--os-auth-plugin',
|
||||||
dest='auth_plugin',
|
dest='auth_plugin',
|
||||||
|
@@ -21,25 +21,17 @@ For example:
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import os_client_config
|
||||||
|
|
||||||
from examples import common
|
from examples import common
|
||||||
from openstack import connection
|
from openstack import connection
|
||||||
|
|
||||||
|
|
||||||
def make_connection(opts):
|
def make_connection(opts):
|
||||||
args = {
|
occ = os_client_config.OpenStackConfig()
|
||||||
'auth_plugin': opts.auth_plugin,
|
cloud = occ.get_one_cloud(opts.cloud, opts)
|
||||||
'auth_url': opts.auth_url,
|
auth = cloud.config['auth']
|
||||||
'project_name': opts.project_name,
|
conn = connection.Connection(preference=opts.user_preferences, **auth)
|
||||||
'domain_name': opts.domain_name,
|
|
||||||
'project_domain_name': opts.project_domain_name,
|
|
||||||
'user_domain_name': opts.user_domain_name,
|
|
||||||
'username': opts.username,
|
|
||||||
'password': opts.password,
|
|
||||||
'trust_id': opts.trust_id,
|
|
||||||
'verify': opts.verify,
|
|
||||||
'token': opts.token,
|
|
||||||
}
|
|
||||||
conn = connection.Connection(preference=opts.user_preferences, **args)
|
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user