diff --git a/README.rst b/README.rst index 292e05258..8f5b0ab76 100644 --- a/README.rst +++ b/README.rst @@ -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= - export OS_TENANT_NAME= + export OS_PROJECT_NAME= export OS_USERNAME= export OS_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 - --os-tenant-name + --os-project-name --os-username [--os-password ] [--os-use-keyring] diff --git a/openstackclient/common/clientmanager.py b/openstackclient/common/clientmanager.py index a1b838a22..fdeca139e 100644 --- a/openstackclient/common/clientmanager.py +++ b/openstackclient/common/clientmanager.py @@ -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 diff --git a/openstackclient/compute/client.py b/openstackclient/compute/client.py index f7ebfe3e8..9bd40a4fc 100644 --- a/openstackclient/compute/client.py +++ b/openstackclient/compute/client.py @@ -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, diff --git a/openstackclient/identity/client.py b/openstackclient/identity/client.py index 748d16668..ed4882aab 100644 --- a/openstackclient/identity/client.py +++ b/openstackclient/identity/client.py @@ -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 diff --git a/openstackclient/shell.py b/openstackclient/shell.py index dad4a693a..7bc0a44a0 100644 --- a/openstackclient/shell.py +++ b/openstackclient/shell.py @@ -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='', default=env('OS_AUTH_URL'), help='Authentication URL (Env: OS_AUTH_URL)') + parser.add_argument( + '--os-project-name', + metavar='', + 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='', - 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='', + 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='', - 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='', @@ -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, diff --git a/openstackclient/tests/test_shell.py b/openstackclient/tests/test_shell.py index ca87997f6..be9c5d49b 100644 --- a/openstackclient/tests/test_shell.py +++ b/openstackclient/tests/test_shell.py @@ -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 diff --git a/openstackclient/volume/client.py b/openstackclient/volume/client.py index c1acff2fe..92f3b14a4 100644 --- a/openstackclient/volume/client.py +++ b/openstackclient/volume/client.py @@ -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, )