Remove tenant round 1 - global options

Change the global auth options to use 'project', leave the original
tenant options in place but silent for compatability with the existing
project CLI auth options.  This is the only compatibility for tenant
usage in this changeover.

Change-Id: I3cce6e552f18822cc9f445ec5f301b0f5d9003f8
This commit is contained in:
Dean Troyer 2013-07-29 11:11:11 -05:00
parent 9ec1cf385e
commit 0aa3c206a3
7 changed files with 82 additions and 42 deletions

View File

@ -52,12 +52,12 @@ Configuration
=============
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::
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_PASSWORD=<password> # (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::
--os-auth-url <url>
--os-tenant-name <tenant-name>
--os-project-name <project-name>
--os-username <user-name>
[--os-password <password>]
[--os-use-keyring]

View File

@ -46,14 +46,14 @@ class ClientManager(object):
image = ClientCache(image_client.make_client)
volume = ClientCache(volume_client.make_client)
def __init__(self, token=None, url=None, auth_url=None, tenant_name=None,
tenant_id=None, username=None, password=None,
def __init__(self, token=None, url=None, auth_url=None, project_name=None,
project_id=None, username=None, password=None,
region_name=None, api_version=None):
self._token = token
self._url = url
self._auth_url = auth_url
self._tenant_name = tenant_name
self._tenant_id = tenant_id
self._project_name = project_name
self._project_id = project_id
self._username = username
self._password = password
self._region_name = region_name

View File

@ -36,7 +36,7 @@ def make_client(instance):
client = compute_client(
username=instance._username,
api_key=instance._password,
project_id=instance._tenant_name,
project_id=instance._project_name,
auth_url=instance._auth_url,
# FIXME(dhellmann): add constructor argument for this
insecure=False,

View File

@ -43,8 +43,8 @@ def make_client(instance):
client = identity_client(
username=instance._username,
password=instance._password,
tenant_name=instance._tenant_name,
tenant_id=instance._tenant_id,
tenant_name=instance._project_name,
tenant_id=instance._project_id,
auth_url=instance._auth_url,
region_name=instance._region_name)
return client

View File

@ -15,6 +15,7 @@
"""Command-line interface to the OpenStack APIs"""
import argparse
import getpass
import logging
import os
@ -110,16 +111,30 @@ class OpenStackShell(app.App):
metavar='<auth-url>',
default=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(
'--os-tenant-name',
metavar='<auth-tenant-name>',
default=env('OS_TENANT_NAME'),
help='Authentication tenant name (Env: OS_TENANT_NAME)')
dest='os_project_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(
'--os-tenant-id',
metavar='<auth-tenant-id>',
default=env('OS_TENANT_ID'),
help='Authentication tenant ID (Env: OS_TENANT_ID)')
dest='os_project_id',
help=argparse.SUPPRESS,
)
parser.add_argument(
'--os-username',
metavar='<auth-username>',
@ -247,10 +262,11 @@ class OpenStackShell(app.App):
" either --os-password, or env[OS_PASSWORD], "
" 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(
"You must provide a tenant_id via"
" either --os-tenant-id or via env[OS_TENANT_ID]")
"You must provide a project id via"
" either --os-project-id or via env[OS_PROJECT_ID]")
if not self.options.os_auth_url:
raise exc.CommandError(
@ -261,8 +277,8 @@ class OpenStackShell(app.App):
token=self.options.os_token,
url=self.options.os_url,
auth_url=self.options.os_auth_url,
tenant_name=self.options.os_tenant_name,
tenant_id=self.options.os_tenant_id,
project_name=self.options.os_project_name,
project_id=self.options.os_project_id,
username=self.options.os_username,
password=self.options.os_password,
region_name=self.options.os_region_name,

View File

@ -22,8 +22,8 @@ from openstackclient.tests import utils
DEFAULT_USERNAME = "username"
DEFAULT_PASSWORD = "password"
DEFAULT_TENANT_ID = "xxxx-yyyy-zzzz"
DEFAULT_TENANT_NAME = "tenant"
DEFAULT_PROJECT_ID = "xxxx-yyyy-zzzz"
DEFAULT_PROJECT_NAME = "project"
DEFAULT_TOKEN = "token"
DEFAULT_REGION_NAME = "ZZ9_Plural_Z_Alpha"
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):
with mock.patch("openstackclient.shell.OpenStackShell.initialize_app",
self.app):
_shell, _cmd = make_shell(), cmd_options + " list tenant"
_shell, _cmd = make_shell(), cmd_options + " list project"
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,
default_args["auth_url"])
self.assertEqual(_shell.options.os_tenant_id,
default_args["tenant_id"])
self.assertEqual(_shell.options.os_tenant_name,
default_args["tenant_name"])
self.assertEqual(_shell.options.os_project_id,
default_args["project_id"])
self.assertEqual(_shell.options.os_project_name,
default_args["project_name"])
self.assertEqual(_shell.options.os_username,
default_args["username"])
self.assertEqual(_shell.options.os_password,
@ -149,8 +149,32 @@ class TestShellPasswordAuth(TestShell):
flag = "--os-auth-url " + DEFAULT_AUTH_URL
kwargs = {
"auth_url": DEFAULT_AUTH_URL,
"tenant_id": "",
"tenant_name": "",
"project_id": "",
"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": "",
"password": "",
"region_name": ""
@ -158,11 +182,11 @@ class TestShellPasswordAuth(TestShell):
self._assert_password_auth(flag, kwargs)
def test_only_tenant_id_flow(self):
flag = "--os-tenant-id " + DEFAULT_TENANT_ID
flag = "--os-tenant-id " + DEFAULT_PROJECT_ID
kwargs = {
"auth_url": "",
"tenant_id": DEFAULT_TENANT_ID,
"tenant_name": "",
"project_id": DEFAULT_PROJECT_ID,
"project_name": "",
"username": "",
"password": "",
"region_name": ""
@ -170,11 +194,11 @@ class TestShellPasswordAuth(TestShell):
self._assert_password_auth(flag, kwargs)
def test_only_tenant_name_flow(self):
flag = "--os-tenant-name " + DEFAULT_TENANT_NAME
flag = "--os-tenant-name " + DEFAULT_PROJECT_NAME
kwargs = {
"auth_url": "",
"tenant_id": "",
"tenant_name": DEFAULT_TENANT_NAME,
"project_id": "",
"project_name": DEFAULT_PROJECT_NAME,
"username": "",
"password": "",
"region_name": ""
@ -185,8 +209,8 @@ class TestShellPasswordAuth(TestShell):
flag = "--os-username " + DEFAULT_USERNAME
kwargs = {
"auth_url": "",
"tenant_id": "",
"tenant_name": "",
"project_id": "",
"project_name": "",
"username": DEFAULT_USERNAME,
"password": "",
"region_name": ""
@ -197,8 +221,8 @@ class TestShellPasswordAuth(TestShell):
flag = "--os-password " + DEFAULT_PASSWORD
kwargs = {
"auth_url": "",
"tenant_id": "",
"tenant_name": "",
"project_id": "",
"project_name": "",
"username": "",
"password": DEFAULT_PASSWORD,
"region_name": ""
@ -209,8 +233,8 @@ class TestShellPasswordAuth(TestShell):
flag = "--os-region-name " + DEFAULT_REGION_NAME
kwargs = {
"auth_url": "",
"tenant_id": "",
"tenant_name": "",
"project_id": "",
"project_name": "",
"username": "",
"password": "",
"region_name": DEFAULT_REGION_NAME

View File

@ -38,7 +38,7 @@ def make_client(instance):
client = volume_client(
username=instance._username,
api_key=instance._password,
project_id=instance._tenant_name,
project_id=instance._project_name,
auth_url=instance._auth_url,
)