Merge "Remove tenant round 1 - global options"
This commit is contained in:
commit
cd0f34b2d6
README.rst
openstackclient
@ -52,12 +52,12 @@ Configuration
|
|||||||
=============
|
=============
|
||||||
|
|
||||||
The CLI is configured via environment variables and command-line
|
The CLI is configured via environment variables and command-line
|
||||||
options as listed in http://wiki.openstack.org/UnifiedCLI/Authentication.
|
options as listed in https://wiki.openstack.org/wiki/OpenStackClient/Authentication.
|
||||||
|
|
||||||
The 'password flow' variation is most commonly used::
|
The 'password flow' variation is most commonly used::
|
||||||
|
|
||||||
export OS_AUTH_URL=<url-to-openstack-identity>
|
export OS_AUTH_URL=<url-to-openstack-identity>
|
||||||
export OS_TENANT_NAME=<tenant-name>
|
export OS_PROJECT_NAME=<project-name>
|
||||||
export OS_USERNAME=<user-name>
|
export OS_USERNAME=<user-name>
|
||||||
export OS_PASSWORD=<password> # (optional)
|
export OS_PASSWORD=<password> # (optional)
|
||||||
export OS_USE_KEYRING=true # (optional)
|
export OS_USE_KEYRING=true # (optional)
|
||||||
@ -65,7 +65,7 @@ The 'password flow' variation is most commonly used::
|
|||||||
The corresponding command-line options look very similar::
|
The corresponding command-line options look very similar::
|
||||||
|
|
||||||
--os-auth-url <url>
|
--os-auth-url <url>
|
||||||
--os-tenant-name <tenant-name>
|
--os-project-name <project-name>
|
||||||
--os-username <user-name>
|
--os-username <user-name>
|
||||||
[--os-password <password>]
|
[--os-password <password>]
|
||||||
[--os-use-keyring]
|
[--os-use-keyring]
|
||||||
|
@ -46,14 +46,14 @@ class ClientManager(object):
|
|||||||
image = ClientCache(image_client.make_client)
|
image = ClientCache(image_client.make_client)
|
||||||
volume = ClientCache(volume_client.make_client)
|
volume = ClientCache(volume_client.make_client)
|
||||||
|
|
||||||
def __init__(self, token=None, url=None, auth_url=None, tenant_name=None,
|
def __init__(self, token=None, url=None, auth_url=None, project_name=None,
|
||||||
tenant_id=None, username=None, password=None,
|
project_id=None, username=None, password=None,
|
||||||
region_name=None, api_version=None):
|
region_name=None, api_version=None):
|
||||||
self._token = token
|
self._token = token
|
||||||
self._url = url
|
self._url = url
|
||||||
self._auth_url = auth_url
|
self._auth_url = auth_url
|
||||||
self._tenant_name = tenant_name
|
self._project_name = project_name
|
||||||
self._tenant_id = tenant_id
|
self._project_id = project_id
|
||||||
self._username = username
|
self._username = username
|
||||||
self._password = password
|
self._password = password
|
||||||
self._region_name = region_name
|
self._region_name = region_name
|
||||||
|
@ -36,7 +36,7 @@ def make_client(instance):
|
|||||||
client = compute_client(
|
client = compute_client(
|
||||||
username=instance._username,
|
username=instance._username,
|
||||||
api_key=instance._password,
|
api_key=instance._password,
|
||||||
project_id=instance._tenant_name,
|
project_id=instance._project_name,
|
||||||
auth_url=instance._auth_url,
|
auth_url=instance._auth_url,
|
||||||
# FIXME(dhellmann): add constructor argument for this
|
# FIXME(dhellmann): add constructor argument for this
|
||||||
insecure=False,
|
insecure=False,
|
||||||
|
@ -44,8 +44,8 @@ def make_client(instance):
|
|||||||
client = identity_client(
|
client = identity_client(
|
||||||
username=instance._username,
|
username=instance._username,
|
||||||
password=instance._password,
|
password=instance._password,
|
||||||
tenant_name=instance._tenant_name,
|
tenant_name=instance._project_name,
|
||||||
tenant_id=instance._tenant_id,
|
tenant_id=instance._project_id,
|
||||||
auth_url=instance._auth_url,
|
auth_url=instance._auth_url,
|
||||||
region_name=instance._region_name)
|
region_name=instance._region_name)
|
||||||
return client
|
return client
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
"""Command-line interface to the OpenStack APIs"""
|
"""Command-line interface to the OpenStack APIs"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
import getpass
|
import getpass
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -110,16 +111,30 @@ class OpenStackShell(app.App):
|
|||||||
metavar='<auth-url>',
|
metavar='<auth-url>',
|
||||||
default=env('OS_AUTH_URL'),
|
default=env('OS_AUTH_URL'),
|
||||||
help='Authentication URL (Env: OS_AUTH_URL)')
|
help='Authentication URL (Env: OS_AUTH_URL)')
|
||||||
|
parser.add_argument(
|
||||||
|
'--os-project-name',
|
||||||
|
metavar='<auth-project-name>',
|
||||||
|
default=env('OS_PROJECT_NAME', default=env('OS_TENANT_NAME')),
|
||||||
|
help='Authentication project name (Env: OS_PROJECT_NAME)',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--os-tenant-name',
|
'--os-tenant-name',
|
||||||
metavar='<auth-tenant-name>',
|
metavar='<auth-tenant-name>',
|
||||||
default=env('OS_TENANT_NAME'),
|
dest='os_project_name',
|
||||||
help='Authentication tenant name (Env: OS_TENANT_NAME)')
|
help=argparse.SUPPRESS,
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--os-project-id',
|
||||||
|
metavar='<auth-project-id>',
|
||||||
|
default=env('OS_PROJECT_ID', default=env('OS_TENANT_ID')),
|
||||||
|
help='Authentication project ID (Env: OS_PROJECT_ID)',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--os-tenant-id',
|
'--os-tenant-id',
|
||||||
metavar='<auth-tenant-id>',
|
metavar='<auth-tenant-id>',
|
||||||
default=env('OS_TENANT_ID'),
|
dest='os_project_id',
|
||||||
help='Authentication tenant ID (Env: OS_TENANT_ID)')
|
help=argparse.SUPPRESS,
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--os-username',
|
'--os-username',
|
||||||
metavar='<auth-username>',
|
metavar='<auth-username>',
|
||||||
@ -247,10 +262,11 @@ class OpenStackShell(app.App):
|
|||||||
" either --os-password, or env[OS_PASSWORD], "
|
" either --os-password, or env[OS_PASSWORD], "
|
||||||
" or prompted response")
|
" or prompted response")
|
||||||
|
|
||||||
if not (self.options.os_tenant_id or self.options.os_tenant_name):
|
if not (self.options.os_project_id
|
||||||
|
or self.options.os_project_name):
|
||||||
raise exc.CommandError(
|
raise exc.CommandError(
|
||||||
"You must provide a tenant_id via"
|
"You must provide a project id via"
|
||||||
" either --os-tenant-id or via env[OS_TENANT_ID]")
|
" either --os-project-id or via env[OS_PROJECT_ID]")
|
||||||
|
|
||||||
if not self.options.os_auth_url:
|
if not self.options.os_auth_url:
|
||||||
raise exc.CommandError(
|
raise exc.CommandError(
|
||||||
@ -261,8 +277,8 @@ class OpenStackShell(app.App):
|
|||||||
token=self.options.os_token,
|
token=self.options.os_token,
|
||||||
url=self.options.os_url,
|
url=self.options.os_url,
|
||||||
auth_url=self.options.os_auth_url,
|
auth_url=self.options.os_auth_url,
|
||||||
tenant_name=self.options.os_tenant_name,
|
project_name=self.options.os_project_name,
|
||||||
tenant_id=self.options.os_tenant_id,
|
project_id=self.options.os_project_id,
|
||||||
username=self.options.os_username,
|
username=self.options.os_username,
|
||||||
password=self.options.os_password,
|
password=self.options.os_password,
|
||||||
region_name=self.options.os_region_name,
|
region_name=self.options.os_region_name,
|
||||||
|
@ -22,8 +22,8 @@ from openstackclient.tests import utils
|
|||||||
|
|
||||||
DEFAULT_USERNAME = "username"
|
DEFAULT_USERNAME = "username"
|
||||||
DEFAULT_PASSWORD = "password"
|
DEFAULT_PASSWORD = "password"
|
||||||
DEFAULT_TENANT_ID = "xxxx-yyyy-zzzz"
|
DEFAULT_PROJECT_ID = "xxxx-yyyy-zzzz"
|
||||||
DEFAULT_TENANT_NAME = "tenant"
|
DEFAULT_PROJECT_NAME = "project"
|
||||||
DEFAULT_TOKEN = "token"
|
DEFAULT_TOKEN = "token"
|
||||||
DEFAULT_REGION_NAME = "ZZ9_Plural_Z_Alpha"
|
DEFAULT_REGION_NAME = "ZZ9_Plural_Z_Alpha"
|
||||||
DEFAULT_AUTH_URL = "http://127.0.0.1:5000/v2.0/"
|
DEFAULT_AUTH_URL = "http://127.0.0.1:5000/v2.0/"
|
||||||
@ -68,16 +68,16 @@ class TestShell(utils.TestCase):
|
|||||||
def _assert_password_auth(self, cmd_options, default_args):
|
def _assert_password_auth(self, cmd_options, default_args):
|
||||||
with mock.patch("openstackclient.shell.OpenStackShell.initialize_app",
|
with mock.patch("openstackclient.shell.OpenStackShell.initialize_app",
|
||||||
self.app):
|
self.app):
|
||||||
_shell, _cmd = make_shell(), cmd_options + " list tenant"
|
_shell, _cmd = make_shell(), cmd_options + " list project"
|
||||||
fake_execute(_shell, _cmd)
|
fake_execute(_shell, _cmd)
|
||||||
|
|
||||||
self.app.assert_called_with(["list", "tenant"])
|
self.app.assert_called_with(["list", "project"])
|
||||||
self.assertEqual(_shell.options.os_auth_url,
|
self.assertEqual(_shell.options.os_auth_url,
|
||||||
default_args["auth_url"])
|
default_args["auth_url"])
|
||||||
self.assertEqual(_shell.options.os_tenant_id,
|
self.assertEqual(_shell.options.os_project_id,
|
||||||
default_args["tenant_id"])
|
default_args["project_id"])
|
||||||
self.assertEqual(_shell.options.os_tenant_name,
|
self.assertEqual(_shell.options.os_project_name,
|
||||||
default_args["tenant_name"])
|
default_args["project_name"])
|
||||||
self.assertEqual(_shell.options.os_username,
|
self.assertEqual(_shell.options.os_username,
|
||||||
default_args["username"])
|
default_args["username"])
|
||||||
self.assertEqual(_shell.options.os_password,
|
self.assertEqual(_shell.options.os_password,
|
||||||
@ -149,8 +149,32 @@ class TestShellPasswordAuth(TestShell):
|
|||||||
flag = "--os-auth-url " + DEFAULT_AUTH_URL
|
flag = "--os-auth-url " + DEFAULT_AUTH_URL
|
||||||
kwargs = {
|
kwargs = {
|
||||||
"auth_url": DEFAULT_AUTH_URL,
|
"auth_url": DEFAULT_AUTH_URL,
|
||||||
"tenant_id": "",
|
"project_id": "",
|
||||||
"tenant_name": "",
|
"project_name": "",
|
||||||
|
"username": "",
|
||||||
|
"password": "",
|
||||||
|
"region_name": ""
|
||||||
|
}
|
||||||
|
self._assert_password_auth(flag, kwargs)
|
||||||
|
|
||||||
|
def test_only_project_id_flow(self):
|
||||||
|
flag = "--os-project-id " + DEFAULT_PROJECT_ID
|
||||||
|
kwargs = {
|
||||||
|
"auth_url": "",
|
||||||
|
"project_id": DEFAULT_PROJECT_ID,
|
||||||
|
"project_name": "",
|
||||||
|
"username": "",
|
||||||
|
"password": "",
|
||||||
|
"region_name": ""
|
||||||
|
}
|
||||||
|
self._assert_password_auth(flag, kwargs)
|
||||||
|
|
||||||
|
def test_only_project_name_flow(self):
|
||||||
|
flag = "--os-project-name " + DEFAULT_PROJECT_NAME
|
||||||
|
kwargs = {
|
||||||
|
"auth_url": "",
|
||||||
|
"project_id": "",
|
||||||
|
"project_name": DEFAULT_PROJECT_NAME,
|
||||||
"username": "",
|
"username": "",
|
||||||
"password": "",
|
"password": "",
|
||||||
"region_name": ""
|
"region_name": ""
|
||||||
@ -158,11 +182,11 @@ class TestShellPasswordAuth(TestShell):
|
|||||||
self._assert_password_auth(flag, kwargs)
|
self._assert_password_auth(flag, kwargs)
|
||||||
|
|
||||||
def test_only_tenant_id_flow(self):
|
def test_only_tenant_id_flow(self):
|
||||||
flag = "--os-tenant-id " + DEFAULT_TENANT_ID
|
flag = "--os-tenant-id " + DEFAULT_PROJECT_ID
|
||||||
kwargs = {
|
kwargs = {
|
||||||
"auth_url": "",
|
"auth_url": "",
|
||||||
"tenant_id": DEFAULT_TENANT_ID,
|
"project_id": DEFAULT_PROJECT_ID,
|
||||||
"tenant_name": "",
|
"project_name": "",
|
||||||
"username": "",
|
"username": "",
|
||||||
"password": "",
|
"password": "",
|
||||||
"region_name": ""
|
"region_name": ""
|
||||||
@ -170,11 +194,11 @@ class TestShellPasswordAuth(TestShell):
|
|||||||
self._assert_password_auth(flag, kwargs)
|
self._assert_password_auth(flag, kwargs)
|
||||||
|
|
||||||
def test_only_tenant_name_flow(self):
|
def test_only_tenant_name_flow(self):
|
||||||
flag = "--os-tenant-name " + DEFAULT_TENANT_NAME
|
flag = "--os-tenant-name " + DEFAULT_PROJECT_NAME
|
||||||
kwargs = {
|
kwargs = {
|
||||||
"auth_url": "",
|
"auth_url": "",
|
||||||
"tenant_id": "",
|
"project_id": "",
|
||||||
"tenant_name": DEFAULT_TENANT_NAME,
|
"project_name": DEFAULT_PROJECT_NAME,
|
||||||
"username": "",
|
"username": "",
|
||||||
"password": "",
|
"password": "",
|
||||||
"region_name": ""
|
"region_name": ""
|
||||||
@ -185,8 +209,8 @@ class TestShellPasswordAuth(TestShell):
|
|||||||
flag = "--os-username " + DEFAULT_USERNAME
|
flag = "--os-username " + DEFAULT_USERNAME
|
||||||
kwargs = {
|
kwargs = {
|
||||||
"auth_url": "",
|
"auth_url": "",
|
||||||
"tenant_id": "",
|
"project_id": "",
|
||||||
"tenant_name": "",
|
"project_name": "",
|
||||||
"username": DEFAULT_USERNAME,
|
"username": DEFAULT_USERNAME,
|
||||||
"password": "",
|
"password": "",
|
||||||
"region_name": ""
|
"region_name": ""
|
||||||
@ -197,8 +221,8 @@ class TestShellPasswordAuth(TestShell):
|
|||||||
flag = "--os-password " + DEFAULT_PASSWORD
|
flag = "--os-password " + DEFAULT_PASSWORD
|
||||||
kwargs = {
|
kwargs = {
|
||||||
"auth_url": "",
|
"auth_url": "",
|
||||||
"tenant_id": "",
|
"project_id": "",
|
||||||
"tenant_name": "",
|
"project_name": "",
|
||||||
"username": "",
|
"username": "",
|
||||||
"password": DEFAULT_PASSWORD,
|
"password": DEFAULT_PASSWORD,
|
||||||
"region_name": ""
|
"region_name": ""
|
||||||
@ -209,8 +233,8 @@ class TestShellPasswordAuth(TestShell):
|
|||||||
flag = "--os-region-name " + DEFAULT_REGION_NAME
|
flag = "--os-region-name " + DEFAULT_REGION_NAME
|
||||||
kwargs = {
|
kwargs = {
|
||||||
"auth_url": "",
|
"auth_url": "",
|
||||||
"tenant_id": "",
|
"project_id": "",
|
||||||
"tenant_name": "",
|
"project_name": "",
|
||||||
"username": "",
|
"username": "",
|
||||||
"password": "",
|
"password": "",
|
||||||
"region_name": DEFAULT_REGION_NAME
|
"region_name": DEFAULT_REGION_NAME
|
||||||
|
@ -38,7 +38,7 @@ def make_client(instance):
|
|||||||
client = volume_client(
|
client = volume_client(
|
||||||
username=instance._username,
|
username=instance._username,
|
||||||
api_key=instance._password,
|
api_key=instance._password,
|
||||||
project_id=instance._tenant_name,
|
project_id=instance._project_name,
|
||||||
auth_url=instance._auth_url,
|
auth_url=instance._auth_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user