diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-07-03 16:59:22 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2012-07-03 16:59:22 +0000 |
commit | a1194d29de8959744ff57bc472a1ae6ef72cf3e1 (patch) | |
tree | 92f7fcfc2cab41ff1fd3c555625c03d18219441d | |
parent | ea3f85f026f25460f47f2f0d5974daa104c15fcc (diff) | |
parent | 1fa29109c2194102b4c79fa7fd7328843af6998e (diff) | |
download | python-keystoneclient-a1194d29de8959744ff57bc472a1ae6ef72cf3e1.tar.gz |
Merge "Change CLI options to use dashes"
-rw-r--r-- | README.rst | 37 | ||||
-rw-r--r-- | doc/source/shell.rst | 4 | ||||
-rw-r--r-- | keystoneclient/shell.py | 36 | ||||
-rwxr-xr-x | keystoneclient/v2_0/shell.py | 55 | ||||
-rw-r--r-- | tests/test_shell.py | 104 |
5 files changed, 188 insertions, 48 deletions
@@ -42,14 +42,14 @@ Installing this package gets you a shell command, ``keystone``, that you can use to interact with Keystone's Identity API. You'll need to provide your OpenStack tenant, username and password. You can -do this with the ``--os_tenant_name``, ``--os_username`` and ``--os_password`` +do this with the ``--os-tenant-name``, ``--os-username`` and ``--os-password`` params, but it's easier to just set them as environment variables:: export OS_TENANT_NAME=project export OS_USERNAME=user export OS_PASSWORD=pass -You will also need to define the authentication url with ``--os_auth_url`` and the +You will also need to define the authentication url with ``--os-auth-url`` and the version of the API with ``--identity_api_version``. Or set them as an environment variables as well:: @@ -73,12 +73,13 @@ can specify the one you want with ``--region_name`` (or You'll find complete documentation on the shell by running ``keystone help``:: - usage: keystone [--os_username OS_USERNAME] [--os_password OS_PASSWORD] - [--os_tenant_name OS_TENANT_NAME] - [--os_tenant_id OS_TENANT_ID] [--os_auth_url OS_AUTH_URL] - [--os_region_name OS_REGION_NAME] - [--identity_api_version IDENTITY_API_VERSION] [--token TOKEN] - [--endpoint ENDPOINT] + usage: keystone [--os-username <auth-user-name>] + [--os-password <auth-password>] + [--os-tenant-name <auth-tenant-name>] + [--os-tenant-id <tenant-id>] [--os-auth-url <auth-url>] + [--os-region-name <region-name>] + [--os-identity-api-version <identity-api-version>] + [--token <service-token>] [--endpoint <service-endpoint>] <subcommand> ... Command-line interface to the OpenStack Identity API. @@ -128,21 +129,23 @@ You'll find complete documentation on the shell by running subcommands. Optional arguments: - --os_username OS_USERNAME + --os-username <auth-user-name> Defaults to env[OS_USERNAME] - --os_password OS_PASSWORD + --os-password <auth-password> Defaults to env[OS_PASSWORD] - --os_tenant_name OS_TENANT_NAME + --os-tenant-name <auth-tenant-name> Defaults to env[OS_TENANT_NAME] - --os_tenant_id OS_TENANT_ID + --os-tenant-id <tenant-id> Defaults to env[OS_TENANT_ID] - --os_auth_url OS_AUTH_URL + --os-auth-url <auth-url> Defaults to env[OS_AUTH_URL] - --os_region_name OS_REGION_NAME + --os-region-name <region-name> Defaults to env[OS_REGION_NAME] - --identity_api_version IDENTITY_API_VERSION + --os-identity-api-version <identity-api-version> Defaults to env[OS_IDENTITY_API_VERSION] or 2.0 - --token TOKEN Defaults to env[SERVICE_TOKEN] - --endpoint ENDPOINT Defaults to env[SERVICE_ENDPOINT] + --token <service-token> + Defaults to env[SERVICE_TOKEN] + --endpoint <service-endpoint> + Defaults to env[SERVICE_ENDPOINT] See "keystone help COMMAND" for help on a specific command. diff --git a/doc/source/shell.rst b/doc/source/shell.rst index c44d6b3..f86af72 100644 --- a/doc/source/shell.rst +++ b/doc/source/shell.rst @@ -12,8 +12,8 @@ First, you'll need an OpenStack Keystone account. You get this by using the `keystone-manage` command in OpenStack Keystone. You'll need to provide :program:`keystone` with your OpenStack username and -password. You can do this with the :option:`--os_username`, :option:`--os_password`. -You can optionally specify a :option:`--os_tenant_id` or :option:`--os_tenant_name`, +password. You can do this with the :option:`--os-username`, :option:`--os-password`. +You can optionally specify a :option:`--os-tenant-id` or :option:`--os-tenant-name`, to scope your token to a specific tenant. If you don't specify a tenant, you will be scoped to your default tenant if you have one. Instead of using options, it is easier to just set them as environment variables: diff --git a/keystoneclient/shell.py b/keystoneclient/shell.py index aece369..4c4c5eb 100644 --- a/keystoneclient/shell.py +++ b/keystoneclient/shell.py @@ -66,42 +66,56 @@ class OpenStackIdentityShell(object): action='store_true', help=argparse.SUPPRESS) - parser.add_argument('--os_username', + parser.add_argument('--os-username', metavar='<auth-user-name>', default=env('OS_USERNAME'), help='Defaults to env[OS_USERNAME]') + parser.add_argument('--os_username', + help=argparse.SUPPRESS) - parser.add_argument('--os_password', + parser.add_argument('--os-password', metavar='<auth-password>', default=env('OS_PASSWORD'), help='Defaults to env[OS_PASSWORD]') + parser.add_argument('--os_password', + help=argparse.SUPPRESS) - parser.add_argument('--os_tenant_name', + parser.add_argument('--os-tenant-name', metavar='<auth-tenant-name>', default=env('OS_TENANT_NAME'), help='Defaults to env[OS_TENANT_NAME]') + parser.add_argument('--os_tenant_name', + help=argparse.SUPPRESS) - parser.add_argument('--os_tenant_id', + parser.add_argument('--os-tenant-id', metavar='<tenant-id>', default=env('OS_TENANT_ID'), help='Defaults to env[OS_TENANT_ID]') + parser.add_argument('--os_tenant_id', + help=argparse.SUPPRESS) - parser.add_argument('--os_auth_url', + parser.add_argument('--os-auth-url', metavar='<auth-url>', default=env('OS_AUTH_URL'), help='Defaults to env[OS_AUTH_URL]') + parser.add_argument('--os_auth_url', + help=argparse.SUPPRESS) - parser.add_argument('--os_region_name', + parser.add_argument('--os-region-name', metavar='<region-name>', default=env('OS_REGION_NAME'), help='Defaults to env[OS_REGION_NAME]') + parser.add_argument('--os_region_name', + help=argparse.SUPPRESS) - parser.add_argument('--os_identity_api_version', + parser.add_argument('--os-identity-api-version', metavar='<identity-api-version>', default=env('OS_IDENTITY_API_VERSION', 'KEYSTONE_VERSION'), help='Defaults to env[OS_IDENTITY_API_VERSION]' ' or 2.0') + parser.add_argument('--os_identity_api_version', + help=argparse.SUPPRESS) parser.add_argument('--token', metavar='<service-token>', @@ -195,7 +209,7 @@ class OpenStackIdentityShell(object): ' either a service token, ' '--token or env[SERVICE_TOKEN], \n' ' or credentials, ' - '--os_username or env[OS_USERNAME].') + '--os-username or env[OS_USERNAME].') # if it looks like the user wants to provide a service token # but is missing something @@ -219,16 +233,16 @@ class OpenStackIdentityShell(object): if not args.os_username: raise exc.CommandError( 'Expecting a username provided via either ' - '--os_username or env[OS_USERNAME]') + '--os-username or env[OS_USERNAME]') if not args.os_password: raise exc.CommandError( 'Expecting a password provided via either ' - '--os_password or env[OS_PASSWORD]') + '--os-password or env[OS_PASSWORD]') if not args.os_auth_url: raise exc.CommandError( - 'Expecting an auth URL via either --os_auth_url or ' + 'Expecting an auth URL via either --os-auth-url or ' 'env[OS_AUTH_URL]') if utils.isunauthenticated(args.func): diff --git a/keystoneclient/v2_0/shell.py b/keystoneclient/v2_0/shell.py index 437f034..23c0d34 100755 --- a/keystoneclient/v2_0/shell.py +++ b/keystoneclient/v2_0/shell.py @@ -15,14 +15,17 @@ # License for the specific language governing permissions and limitations # under the License. +import argparse + from keystoneclient.v2_0 import client from keystoneclient import utils CLIENT_CLASS = client.Client -@utils.arg('--tenant_id', metavar='<tenant-id>', +@utils.arg('--tenant-id', metavar='<tenant-id>', help='Tenant ID; lists all users if not specified') +@utils.arg('--tenant_id', help=argparse.SUPPRESS) def do_user_list(kc, args): """List users""" users = kc.users.list(tenant_id=args.tenant_id) @@ -38,8 +41,9 @@ def do_user_get(kc, args): @utils.arg('--name', metavar='<user-name>', required=True, help='New user name (must be unique)') -@utils.arg('--tenant_id', metavar='<tenant-id>', +@utils.arg('--tenant-id', metavar='<tenant-id>', help='New user default tenant') +@utils.arg('--tenant_id', help=argparse.SUPPRESS) @utils.arg('--pass', metavar='<pass>', dest='passwd', help='New user password') @utils.arg('--email', metavar='<email>', @@ -215,27 +219,35 @@ def do_role_delete(kc, args): # TODO(jakedahn): refactor this to allow role, user, and tenant names. -@utils.arg('--user_id', metavar='<user-id>', required=True, help='User ID') -@utils.arg('--role_id', metavar='<role-id>', required=True, help='Role ID') -@utils.arg('--tenant_id', metavar='<tenant-id>', help='Tenant ID') +@utils.arg('--user-id', '--user_id', metavar='<user-id>', required=True, + help='User ID') +@utils.arg('--role-id', '--role_id', metavar='<role-id>', required=True, + help='Role ID') +@utils.arg('--tenant-id', metavar='<tenant-id>', help='Tenant ID') +@utils.arg('--tenant_id', help=argparse.SUPPRESS) def do_user_role_add(kc, args): """Add role to user""" kc.roles.add_user_role(args.user_id, args.role_id, args.tenant_id) # TODO(jakedahn): refactor this to allow role, user, and tenant names. -@utils.arg('--user_id', metavar='<user-id>', required=True, help='User ID') -@utils.arg('--role_id', metavar='<role-id>', required=True, help='Role ID') -@utils.arg('--tenant_id', metavar='<tenant-id>', help='Tenant ID') +@utils.arg('--user-id', '--user_id', metavar='<user-id>', required=True, + help='User ID') +@utils.arg('--role-id', '--role_id', metavar='<role-id>', required=True, + help='Role ID') +@utils.arg('--tenant-id', metavar='<tenant-id>', help='Tenant ID') +@utils.arg('--tenant_id', help=argparse.SUPPRESS) def do_user_role_remove(kc, args): """Remove role from user""" kc.roles.remove_user_role(args.user_id, args.role_id, args.tenant_id) -@utils.arg('--user_id', metavar='<user-id>', +@utils.arg('--user-id', metavar='<user-id>', help='List roles granted to a user') -@utils.arg('--tenant_id', metavar='<tenant-id>', +@utils.arg('--user_id', help=argparse.SUPPRESS) +@utils.arg('--tenant-id', metavar='<tenant-id>', help='List roles granted on a tenant') +@utils.arg('--tenant_id', help=argparse.SUPPRESS) def do_user_role_list(kc, args): """List roles granted to a user""" if not args.tenant_id: @@ -254,8 +266,10 @@ def do_user_role_list(kc, args): utils.print_list(roles, ['id', 'name', 'user_id', 'tenant_id']) -@utils.arg('--user_id', metavar='<user-id>', help='User ID') -@utils.arg('--tenant_id', metavar='<tenant-id>', help='Tenant ID') +@utils.arg('--user-id', metavar='<user-id>', help='User ID') +@utils.arg('--user_id', help=argparse.SUPPRESS) +@utils.arg('--tenant-id', metavar='<tenant-id>', help='Tenant ID') +@utils.arg('--tenant_id', help=argparse.SUPPRESS) def do_ec2_credentials_create(kc, args): """Create EC2-compatibile credentials for user per tenant""" if not args.tenant_id: @@ -268,7 +282,8 @@ def do_ec2_credentials_create(kc, args): utils.print_dict(credentials._info) -@utils.arg('--user_id', metavar='<user-id>', help='User ID') +@utils.arg('--user-id', metavar='<user-id>', help='User ID') +@utils.arg('--user_id', help=argparse.SUPPRESS) @utils.arg('--access', metavar='<access-key>', required=True, help='Access Key') def do_ec2_credentials_get(kc, args): @@ -281,7 +296,8 @@ def do_ec2_credentials_get(kc, args): utils.print_dict(cred._info) -@utils.arg('--user_id', metavar='<user-id>', help='User ID') +@utils.arg('--user-id', metavar='<user-id>', help='User ID') +@utils.arg('--user_id', help=argparse.SUPPRESS) def do_ec2_credentials_list(kc, args): """List EC2-compatibile credentials for a user""" if not args.user_id: @@ -298,7 +314,8 @@ def do_ec2_credentials_list(kc, args): utils.print_list(credentials, ['tenant', 'access', 'secret']) -@utils.arg('--user_id', metavar='<user-id>', help='User ID') +@utils.arg('--user-id', metavar='<user-id>', help='User ID') +@utils.arg('--user_id', help=argparse.SUPPRESS) @utils.arg('--access', metavar='<access-key>', required=True, help='Access Key') def do_ec2_credentials_delete(kc, args): @@ -327,8 +344,10 @@ def do_catalog(kc, args): @utils.arg('--service', metavar='<service-type>', required=True, help='Service type to select') -@utils.arg('--endpoint_type', metavar='<endpoint-type>', default='publicURL', +@utils.arg('--endpoint-type', metavar='<endpoint-type>', default='publicURL', help='Endpoint type to select') +@utils.arg('--endpoint_type', default='publicURL', + help=argparse.SUPPRESS) @utils.arg('--attr', metavar='<service-attribute>', help='Service attribute to match for selection') @utils.arg('--value', metavar='<value>', @@ -359,8 +378,8 @@ def do_endpoint_list(kc, args): @utils.arg('--region', metavar='<endpoint-region>', help='Endpoint region', default='regionOne') -@utils.arg('--service_id', metavar='<service-id>', required=True, - help='ID of service associated with Endpoint') +@utils.arg('--service-id', '--service_id', metavar='<service-id>', + required=True, help='ID of service associated with Endpoint') @utils.arg('--publicurl', metavar='<public-url>', help='Public URL endpoint') @utils.arg('--adminurl', metavar='<admin-url>', diff --git a/tests/test_shell.py b/tests/test_shell.py index 1195c3d..116e380 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -60,6 +60,8 @@ class ShellTest(utils.TestCase): expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID, DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '') self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + + # Old_style options shell('--os_auth_url http://0.0.0.0:5000/ --os_password xyzpdq ' '--os_tenant_id 1234 --os_tenant_name fred ' '--os_username barney ' @@ -73,6 +75,20 @@ class ShellTest(utils.TestCase): 'fred', 'barney', '2.0') self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + # New-style options + shell('--os-auth-url http://1.1.1.1:5000/ --os-password xyzpdq ' + '--os-tenant-id 4321 --os-tenant-name wilma ' + '--os-username betty ' + '--os-identity-api-version 2.0 user-list') + assert do_tenant_mock.called + ((a, b), c) = do_tenant_mock.call_args + actual = (b.os_auth_url, b.os_password, b.os_tenant_id, + b.os_tenant_name, b.os_username, + b.os_identity_api_version) + expect = ('http://1.1.1.1:5000/', 'xyzpdq', '4321', + 'wilma', 'betty', '2.0') + self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + def test_shell_user_create_args(self): """Test user-create args""" do_uc_mock = mock.MagicMock() @@ -82,6 +98,7 @@ class ShellTest(utils.TestCase): with mock.patch('keystoneclient.v2_0.shell.do_user_create', do_uc_mock): + # Old_style options # Test case with one --tenant_id args present: ec2 creds shell('user-create --name=FOO ' '--pass=secrete --tenant_id=barrr --enabled=true') @@ -97,6 +114,23 @@ class ShellTest(utils.TestCase): expect = ('barrr', 'FOO', 'secrete', 'true') self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + # New-style options + # Test case with one --tenant-id args present: ec2 creds + shell('user-create --name=foo ' + '--pass=secrete --tenant-id=BARRR --enabled=true') + assert do_uc_mock.called + ((a, b), c) = do_uc_mock.call_args + actual = (b.os_auth_url, b.os_password, b.os_tenant_id, + b.os_tenant_name, b.os_username, + b.os_identity_api_version) + expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID, + DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '') + self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + actual = (b.tenant_id, b.name, b.passwd, b.enabled) + expect = ('BARRR', 'foo', 'secrete', 'true') + self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + + # Old_style options # Test case with --os_tenant_id and --tenant_id args present shell('--os_tenant_id=os-tenant user-create --name=FOO ' '--pass=secrete --tenant_id=barrr --enabled=true') @@ -112,6 +146,22 @@ class ShellTest(utils.TestCase): expect = ('barrr', 'FOO', 'secrete', 'true') self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + # New-style options + # Test case with --os-tenant-id and --tenant-id args present + shell('--os-tenant-id=ostenant user-create --name=foo ' + '--pass=secrete --tenant-id=BARRR --enabled=true') + assert do_uc_mock.called + ((a, b), c) = do_uc_mock.call_args + actual = (b.os_auth_url, b.os_password, b.os_tenant_id, + b.os_tenant_name, b.os_username, + b.os_identity_api_version) + expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, 'ostenant', + DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '') + self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + actual = (b.tenant_id, b.name, b.passwd, b.enabled) + expect = ('BARRR', 'foo', 'secrete', 'true') + self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + def test_do_tenant_create(self): do_tenant_mock = mock.MagicMock() with mock.patch('keystoneclient.v2_0.shell.do_tenant_create', @@ -140,6 +190,7 @@ class ShellTest(utils.TestCase): with mock.patch('keystoneclient.v2_0.shell.do_ec2_credentials_create', do_ec2_mock): + # Old_style options # Test case with one --tenant_id args present: ec2 creds shell('ec2-credentials-create ' '--tenant_id=ec2-tenant --user_id=ec2-user') @@ -155,6 +206,23 @@ class ShellTest(utils.TestCase): expect = ('ec2-tenant', 'ec2-user') self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + # New-style options + # Test case with one --tenant-id args present: ec2 creds + shell('ec2-credentials-create ' + '--tenant-id=dash-tenant --user-id=dash-user') + assert do_ec2_mock.called + ((a, b), c) = do_ec2_mock.call_args + actual = (b.os_auth_url, b.os_password, b.os_tenant_id, + b.os_tenant_name, b.os_username, + b.os_identity_api_version) + expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID, + DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '') + self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + actual = (b.tenant_id, b.user_id) + expect = ('dash-tenant', 'dash-user') + self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + + # Old_style options # Test case with two --tenant_id args present shell('--os_tenant_id=os-tenant ec2-credentials-create ' '--tenant_id=ec2-tenant --user_id=ec2-user') @@ -170,6 +238,22 @@ class ShellTest(utils.TestCase): expect = ('ec2-tenant', 'ec2-user') self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + # New-style options + # Test case with two --tenant-id args present + shell('--os-tenant-id=ostenant ec2-credentials-create ' + '--tenant-id=dash-tenant --user-id=dash-user') + assert do_ec2_mock.called + ((a, b), c) = do_ec2_mock.call_args + actual = (b.os_auth_url, b.os_password, b.os_tenant_id, + b.os_tenant_name, b.os_username, + b.os_identity_api_version) + expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, 'ostenant', + DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '') + self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + actual = (b.tenant_id, b.user_id) + expect = ('dash-tenant', 'dash-user') + self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + def test_do_ec2_get(self): do_shell_mock = mock.MagicMock() @@ -201,6 +285,7 @@ class ShellTest(utils.TestCase): with mock.patch('keystoneclient.v2_0.shell.do_endpoint_create', do_shell_mock): + # Old_style options # Test create args shell('endpoint-create ' '--service_id=2 --publicurl=http://example.com:1234/go ' @@ -218,3 +303,22 @@ class ShellTest(utils.TestCase): 'http://example.com:1234/go', 'http://example.com:9876/adm') self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + + # New-style options + # Test create args + shell('endpoint-create ' + '--service-id=3 --publicurl=http://example.com:4321/go ' + '--adminurl=http://example.com:9876/adm') + assert do_shell_mock.called + ((a, b), c) = do_shell_mock.call_args + actual = (b.os_auth_url, b.os_password, b.os_tenant_id, + b.os_tenant_name, b.os_username, + b.os_identity_api_version) + expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID, + DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '') + self.assertTrue(all([x == y for x, y in zip(actual, expect)])) + actual = (b.service_id, b.publicurl, b.adminurl) + expect = ('3', + 'http://example.com:4321/go', + 'http://example.com:9876/adm') + self.assertTrue(all([x == y for x, y in zip(actual, expect)])) |