Skip to content

Commit 0aa3c20

Browse files
author
Dean Troyer
committed
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
1 parent 9ec1cf3 commit 0aa3c20

File tree

7 files changed

+82
-42
lines changed

7 files changed

+82
-42
lines changed

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@ Configuration
5252
=============
5353

5454
The CLI is configured via environment variables and command-line
55-
options as listed in http://wiki.openstack.org/UnifiedCLI/Authentication.
55+
options as listed in https://wiki.openstack.org/wiki/OpenStackClient/Authentication.
5656

5757
The 'password flow' variation is most commonly used::
5858

5959
export OS_AUTH_URL=<url-to-openstack-identity>
60-
export OS_TENANT_NAME=<tenant-name>
60+
export OS_PROJECT_NAME=<project-name>
6161
export OS_USERNAME=<user-name>
6262
export OS_PASSWORD=<password> # (optional)
6363
export OS_USE_KEYRING=true # (optional)
6464

6565
The corresponding command-line options look very similar::
6666

6767
--os-auth-url <url>
68-
--os-tenant-name <tenant-name>
68+
--os-project-name <project-name>
6969
--os-username <user-name>
7070
[--os-password <password>]
7171
[--os-use-keyring]

openstackclient/common/clientmanager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ class ClientManager(object):
4646
image = ClientCache(image_client.make_client)
4747
volume = ClientCache(volume_client.make_client)
4848

49-
def __init__(self, token=None, url=None, auth_url=None, tenant_name=None,
50-
tenant_id=None, username=None, password=None,
49+
def __init__(self, token=None, url=None, auth_url=None, project_name=None,
50+
project_id=None, username=None, password=None,
5151
region_name=None, api_version=None):
5252
self._token = token
5353
self._url = url
5454
self._auth_url = auth_url
55-
self._tenant_name = tenant_name
56-
self._tenant_id = tenant_id
55+
self._project_name = project_name
56+
self._project_id = project_id
5757
self._username = username
5858
self._password = password
5959
self._region_name = region_name

openstackclient/compute/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def make_client(instance):
3636
client = compute_client(
3737
username=instance._username,
3838
api_key=instance._password,
39-
project_id=instance._tenant_name,
39+
project_id=instance._project_name,
4040
auth_url=instance._auth_url,
4141
# FIXME(dhellmann): add constructor argument for this
4242
insecure=False,

openstackclient/identity/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def make_client(instance):
4343
client = identity_client(
4444
username=instance._username,
4545
password=instance._password,
46-
tenant_name=instance._tenant_name,
47-
tenant_id=instance._tenant_id,
46+
tenant_name=instance._project_name,
47+
tenant_id=instance._project_id,
4848
auth_url=instance._auth_url,
4949
region_name=instance._region_name)
5050
return client

openstackclient/shell.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
"""Command-line interface to the OpenStack APIs"""
1717

18+
import argparse
1819
import getpass
1920
import logging
2021
import os
@@ -110,16 +111,30 @@ def build_option_parser(self, description, version):
110111
metavar='<auth-url>',
111112
default=env('OS_AUTH_URL'),
112113
help='Authentication URL (Env: OS_AUTH_URL)')
114+
parser.add_argument(
115+
'--os-project-name',
116+
metavar='<auth-project-name>',
117+
default=env('OS_PROJECT_NAME', default=env('OS_TENANT_NAME')),
118+
help='Authentication project name (Env: OS_PROJECT_NAME)',
119+
)
113120
parser.add_argument(
114121
'--os-tenant-name',
115122
metavar='<auth-tenant-name>',
116-
default=env('OS_TENANT_NAME'),
117-
help='Authentication tenant name (Env: OS_TENANT_NAME)')
123+
dest='os_project_name',
124+
help=argparse.SUPPRESS,
125+
)
126+
parser.add_argument(
127+
'--os-project-id',
128+
metavar='<auth-project-id>',
129+
default=env('OS_PROJECT_ID', default=env('OS_TENANT_ID')),
130+
help='Authentication project ID (Env: OS_PROJECT_ID)',
131+
)
118132
parser.add_argument(
119133
'--os-tenant-id',
120134
metavar='<auth-tenant-id>',
121-
default=env('OS_TENANT_ID'),
122-
help='Authentication tenant ID (Env: OS_TENANT_ID)')
135+
dest='os_project_id',
136+
help=argparse.SUPPRESS,
137+
)
123138
parser.add_argument(
124139
'--os-username',
125140
metavar='<auth-username>',
@@ -247,10 +262,11 @@ def authenticate_user(self):
247262
" either --os-password, or env[OS_PASSWORD], "
248263
" or prompted response")
249264

250-
if not (self.options.os_tenant_id or self.options.os_tenant_name):
265+
if not (self.options.os_project_id
266+
or self.options.os_project_name):
251267
raise exc.CommandError(
252-
"You must provide a tenant_id via"
253-
" either --os-tenant-id or via env[OS_TENANT_ID]")
268+
"You must provide a project id via"
269+
" either --os-project-id or via env[OS_PROJECT_ID]")
254270

255271
if not self.options.os_auth_url:
256272
raise exc.CommandError(
@@ -261,8 +277,8 @@ def authenticate_user(self):
261277
token=self.options.os_token,
262278
url=self.options.os_url,
263279
auth_url=self.options.os_auth_url,
264-
tenant_name=self.options.os_tenant_name,
265-
tenant_id=self.options.os_tenant_id,
280+
project_name=self.options.os_project_name,
281+
project_id=self.options.os_project_id,
266282
username=self.options.os_username,
267283
password=self.options.os_password,
268284
region_name=self.options.os_region_name,

openstackclient/tests/test_shell.py

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
DEFAULT_USERNAME = "username"
2424
DEFAULT_PASSWORD = "password"
25-
DEFAULT_TENANT_ID = "xxxx-yyyy-zzzz"
26-
DEFAULT_TENANT_NAME = "tenant"
25+
DEFAULT_PROJECT_ID = "xxxx-yyyy-zzzz"
26+
DEFAULT_PROJECT_NAME = "project"
2727
DEFAULT_TOKEN = "token"
2828
DEFAULT_REGION_NAME = "ZZ9_Plural_Z_Alpha"
2929
DEFAULT_AUTH_URL = "http://127.0.0.1:5000/v2.0/"
@@ -68,16 +68,16 @@ def tearDown(self):
6868
def _assert_password_auth(self, cmd_options, default_args):
6969
with mock.patch("openstackclient.shell.OpenStackShell.initialize_app",
7070
self.app):
71-
_shell, _cmd = make_shell(), cmd_options + " list tenant"
71+
_shell, _cmd = make_shell(), cmd_options + " list project"
7272
fake_execute(_shell, _cmd)
7373

74-
self.app.assert_called_with(["list", "tenant"])
74+
self.app.assert_called_with(["list", "project"])
7575
self.assertEqual(_shell.options.os_auth_url,
7676
default_args["auth_url"])
77-
self.assertEqual(_shell.options.os_tenant_id,
78-
default_args["tenant_id"])
79-
self.assertEqual(_shell.options.os_tenant_name,
80-
default_args["tenant_name"])
77+
self.assertEqual(_shell.options.os_project_id,
78+
default_args["project_id"])
79+
self.assertEqual(_shell.options.os_project_name,
80+
default_args["project_name"])
8181
self.assertEqual(_shell.options.os_username,
8282
default_args["username"])
8383
self.assertEqual(_shell.options.os_password,
@@ -149,32 +149,56 @@ def test_only_url_flow(self):
149149
flag = "--os-auth-url " + DEFAULT_AUTH_URL
150150
kwargs = {
151151
"auth_url": DEFAULT_AUTH_URL,
152-
"tenant_id": "",
153-
"tenant_name": "",
152+
"project_id": "",
153+
"project_name": "",
154+
"username": "",
155+
"password": "",
156+
"region_name": ""
157+
}
158+
self._assert_password_auth(flag, kwargs)
159+
160+
def test_only_project_id_flow(self):
161+
flag = "--os-project-id " + DEFAULT_PROJECT_ID
162+
kwargs = {
163+
"auth_url": "",
164+
"project_id": DEFAULT_PROJECT_ID,
165+
"project_name": "",
166+
"username": "",
167+
"password": "",
168+
"region_name": ""
169+
}
170+
self._assert_password_auth(flag, kwargs)
171+
172+
def test_only_project_name_flow(self):
173+
flag = "--os-project-name " + DEFAULT_PROJECT_NAME
174+
kwargs = {
175+
"auth_url": "",
176+
"project_id": "",
177+
"project_name": DEFAULT_PROJECT_NAME,
154178
"username": "",
155179
"password": "",
156180
"region_name": ""
157181
}
158182
self._assert_password_auth(flag, kwargs)
159183

160184
def test_only_tenant_id_flow(self):
161-
flag = "--os-tenant-id " + DEFAULT_TENANT_ID
185+
flag = "--os-tenant-id " + DEFAULT_PROJECT_ID
162186
kwargs = {
163187
"auth_url": "",
164-
"tenant_id": DEFAULT_TENANT_ID,
165-
"tenant_name": "",
188+
"project_id": DEFAULT_PROJECT_ID,
189+
"project_name": "",
166190
"username": "",
167191
"password": "",
168192
"region_name": ""
169193
}
170194
self._assert_password_auth(flag, kwargs)
171195

172196
def test_only_tenant_name_flow(self):
173-
flag = "--os-tenant-name " + DEFAULT_TENANT_NAME
197+
flag = "--os-tenant-name " + DEFAULT_PROJECT_NAME
174198
kwargs = {
175199
"auth_url": "",
176-
"tenant_id": "",
177-
"tenant_name": DEFAULT_TENANT_NAME,
200+
"project_id": "",
201+
"project_name": DEFAULT_PROJECT_NAME,
178202
"username": "",
179203
"password": "",
180204
"region_name": ""
@@ -185,8 +209,8 @@ def test_only_username_flow(self):
185209
flag = "--os-username " + DEFAULT_USERNAME
186210
kwargs = {
187211
"auth_url": "",
188-
"tenant_id": "",
189-
"tenant_name": "",
212+
"project_id": "",
213+
"project_name": "",
190214
"username": DEFAULT_USERNAME,
191215
"password": "",
192216
"region_name": ""
@@ -197,8 +221,8 @@ def test_only_password_flow(self):
197221
flag = "--os-password " + DEFAULT_PASSWORD
198222
kwargs = {
199223
"auth_url": "",
200-
"tenant_id": "",
201-
"tenant_name": "",
224+
"project_id": "",
225+
"project_name": "",
202226
"username": "",
203227
"password": DEFAULT_PASSWORD,
204228
"region_name": ""
@@ -209,8 +233,8 @@ def test_only_region_name_flow(self):
209233
flag = "--os-region-name " + DEFAULT_REGION_NAME
210234
kwargs = {
211235
"auth_url": "",
212-
"tenant_id": "",
213-
"tenant_name": "",
236+
"project_id": "",
237+
"project_name": "",
214238
"username": "",
215239
"password": "",
216240
"region_name": DEFAULT_REGION_NAME

openstackclient/volume/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def make_client(instance):
3838
client = volume_client(
3939
username=instance._username,
4040
api_key=instance._password,
41-
project_id=instance._tenant_name,
41+
project_id=instance._project_name,
4242
auth_url=instance._auth_url,
4343
)
4444

0 commit comments

Comments
 (0)