diff --git a/doc/source/conf.py b/doc/source/conf.py index b8b1e5d..f321bc2 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -71,8 +71,6 @@ def gen_ref(ver, title, names): "pkg": pkg, "name": name}) gen_ref("", "Client Reference", ["client", "exc"]) -gen_ref("v1", "Version 1 API Reference", - ["client", "overcloud_roles", "overclouds"]) # -- General configuration ---------------------------------------------------- diff --git a/tuskarclient/client.py b/tuskarclient/client.py index 37c881a..0a403ee 100644 --- a/tuskarclient/client.py +++ b/tuskarclient/client.py @@ -111,7 +111,7 @@ def get_client(api_version, **kwargs): """Get an authtenticated client, based on the credentials in the keyword args. - :param api_version: the API version to use ('1' or '2') + :param api_version: the API version to use (only '2' is valid) :param kwargs: keyword args containing credentials, either: * os_auth_token: pre-existing token to re-use * tuskar_url: tuskar API endpoint diff --git a/tuskarclient/tests/integration/test_help_command.py b/tuskarclient/tests/integration/test_help_command.py index ac86ee8..3502717 100644 --- a/tuskarclient/tests/integration/test_help_command.py +++ b/tuskarclient/tests/integration/test_help_command.py @@ -51,263 +51,14 @@ tests = [ 'err_string': '', 'return_code': 0, }, - { - 'commands': ['help -r'], - 'test_identifiers': ['test_help_dash_r'], - 'out_string': '', - 'err_includes': [ - 'error: unrecognized arguments: -r', - ], - 'return_code': 2, - }, - # Overcloud Role - Create - { - 'commands': ['overcloud-role-create -h', - 'overcloud-role-create --help', - 'help overcloud-role-create'], - 'test_identifiers': ['test_overcloud_role_create_dash_h', - 'test_overcloud_role_create_dashdash_help', - 'test_help_overcloud_role_create'], - 'out_includes': [ - '-d , --description ', - '-i , --image-name ', - '-f , --flavor-id ' - ], - 'out_excludes': [ - '-i , --id ', - 'overcloud-role-list', - 'overcloud-create', - '--os-username OS_USERNAME', - 'Display help for ', - ], - 'err_string': '', - 'return_code': 0, - }, - # Overcloud Role - Delete - { - 'commands': ['overcloud-role-delete -h', - 'overcloud-role-delete --help', - 'help overcloud-role-delete'], - 'test_identifiers': ['test_overcloud_role_delete_dash_h', - 'test_overcloud_role_delete_dashdash_help', - 'test_help_overcloud_role_delete'], - 'out_includes': [ - ' ID or name of the Overcloud Role to delete.', - ], - 'out_excludes': [ - 'overcloud-role-list', - 'overcloud-delete', - '--os-username OS_USERNAME', - 'Display help for ', - '-d , --description ', - '-i , --image-name ', - '-f , --flavor-id ' - ], - 'err_string': '', - 'return_code': 0, - }, - # Overcloud Role - List - { - 'commands': ['overcloud-role-list -h', - 'overcloud-role-list --help', - 'help overcloud-role-list'], - 'test_identifiers': ['test_overcloud_role_list_dash_h', - 'test_overcloud_role_list_dashdash_help', - 'test_help_overcloud_role_list'], - 'out_includes': [ - ], - 'out_excludes': [ - 'overcloud-role-delete', - 'overcloud-list', - '--os-username OS_USERNAME', - 'Display help for ', - '-n , --name ', - '-d , --description ', - '-i , --image-name ', - '-f , --flavor-id ' - ], - 'err_string': '', - 'return_code': 0, - }, - # Overcloud Role - Show - { - 'commands': ['overcloud-role-show -h', - 'overcloud-role-show --help', - 'help overcloud-role-show'], - 'test_identifiers': ['test_overcloud_role_show_dash_h', - 'test_overcloud_role_show_dashdash_help', - 'test_help_overcloud_role_show'], - 'out_includes': [ - ' ID or name of the Overcloud Role to show.', - ], - 'out_excludes': [ - 'overcloud-role-list', - 'overcloud-show', - '--os-username OS_USERNAME', - 'Display help for ', - ], - 'err_string': '', - 'return_code': 0, - }, - # Overcloud Role - Update - { - 'commands': ['overcloud-role-update -h', - 'overcloud-role-update --help', - 'help overcloud-role-update'], - 'test_identifiers': ['test_overcloud_role_update_dash_h', - 'test_overcloud_role_update_dashdash_help', - 'test_help_overcloud_role_update'], - 'out_includes': [ - '-n , --name ', - '-d , --description ', - '-i , --image-name ', - '-f , --flavor-id ' - ], - 'out_excludes': [ - 'overcloud-role-list', - 'overcloud-update', - '--os-username OS_USERNAME', - 'Display help for ', - ], - 'err_string': '', - 'return_code': 0, - }, - # Overcloud - Create - { - 'commands': ['overcloud-create -h', - 'overcloud-create --help', - 'help overcloud-create'], - 'test_identifiers': ['test_overcloud_create_dash_h', - 'test_overcloud_create_dashdash_help', - 'test_help_overcloud_create'], - 'out_includes': [ - ], - 'out_excludes': [ - '-i , --id ', - 'overcloud-list', - 'overcloud-role-create', - '--os-username OS_USERNAME', - 'Display help for ', - ], - 'err_string': '', - 'return_code': 0, - }, - # Overcloud - Delete - { - 'commands': ['overcloud-delete -h', - 'overcloud-delete --help', - 'help overcloud-delete'], - 'test_identifiers': ['test_overcloud_delete_dash_h', - 'test_overcloud_delete_dashdash_help', - 'test_help_overcloud_delete'], - 'out_includes': [ - ' ID or name of the Overcloud to delete.', - ], - 'out_excludes': [ - 'overcloud-list', - 'overcloud-role-delete', - '--os-username OS_USERNAME', - 'Display help for ', - '-d , --description ', - '-i , --image-name ', - '-f , --flavor-id ' - ], - 'err_string': '', - 'return_code': 0, - }, - # Overcloud - List - { - 'commands': ['overcloud-list -h', - 'overcloud-list --help', - 'help overcloud-list'], - 'test_identifiers': ['test_overcloud_list_dash_h', - 'test_overcloud_list_dashdash_help', - 'test_help_overcloud_list'], - 'out_includes': [ - ], - 'out_excludes': [ - 'overcloud-delete', - 'overcloud-role-list', - '--os-username OS_USERNAME', - 'Display help for ', - '-n , --name ', - '-d , --description ', - '-i , --image-name ', - '-f , --flavor-id ' - ], - 'err_string': '', - 'return_code': 0, - }, - # Overcloud - Show - { - 'commands': ['overcloud-show -h', - 'overcloud-show --help', - 'help overcloud-show'], - 'test_identifiers': ['test_overcloud_show_dash_h', - 'test_overcloud_show_dashdash_help', - 'test_help_overcloud_show'], - 'out_includes': [ - ' ID or name of the Overcloud to show.', - ], - 'out_excludes': [ - 'overcloud-list', - 'overcloud-role-show', - '--os-username OS_USERNAME', - 'Display help for ', - ], - 'err_string': '', - 'return_code': 0, - }, - # Overcloud - Update - { - 'commands': ['overcloud-update -h', - 'overcloud-update --help', - 'help overcloud-update'], - 'test_identifiers': ['test_overcloud_update_dash_h', - 'test_overcloud_update_dashdash_help', - 'test_help_overcloud_update'], - 'out_includes': [ - '-n , --name ' - ], - 'out_excludes': [ - 'overcloud-list', - 'overcloud-role-update', - '--os-username OS_USERNAME', - 'Display help for ', - ], - 'err_string': '', - 'return_code': 0, - }, - # Overcloud - show template parameters - { - 'commands': ['overcloud-show-template-parameters -h', - 'overcloud-show-template-parameters --help', - 'help overcloud-show-template-parameters'], - 'test_identifiers': [ - 'test_overcloud_show_template_parameters_dash_h', - 'test_overcloud_show_template_parameters_dashdash_help', - 'test_help_overcloud_show_template_parameters' - ], - 'out_includes': [ - 'Show the template parameters stored in the Tuskar API.' - ], - 'out_excludes': [ - '-n , --name ' - 'overcloud-list', - 'overcloud-role-template-parameters', - '--os-username OS_USERNAME', - 'Display help for ', - ], - 'err_string': '', - 'return_code': 0, - } + ] def create_test_method(command, expected_values): def test_command_method(self): self.assertThat( - self.run_tuskar("--tuskar-api-version 1 %s" % command), + self.run_tuskar("--tuskar-api-version 2 %s" % command), tutils.CommandOutputMatches( out_str=expected_values.get('out_string'), out_inc=expected_values.get('out_includes'), diff --git a/tuskarclient/tests/test_client.py b/tuskarclient/tests/test_client.py index a172879..d76b1d3 100644 --- a/tuskarclient/tests/test_client.py +++ b/tuskarclient/tests/test_client.py @@ -81,7 +81,7 @@ class ClientGetClientWithTokenTest(tutils.TestCase): @mock.patch.object(client, 'Client') def test_it_filters_kwargs(self, mocked_client): mocked_client.return_value = 'mocked client' - api_version = 1 + api_version = 2 endpoint = 'http://tuskar.api:1234' token = 'token' @@ -114,7 +114,7 @@ class ClientGetClientWithTokenTest(tutils.TestCase): **client_args) def test_it_returns_none_without_token(self): - api_version = 1 + api_version = 2 endpoint = 'http://tuskar.api:1234' self.assertEqual( client._get_client_with_token(api_version, @@ -122,7 +122,7 @@ class ClientGetClientWithTokenTest(tutils.TestCase): None) def test_it_returns_none_without_endpoint(self): - api_version = 1 + api_version = 2 token = 'token' self.assertEqual( client._get_client_with_token(api_version, @@ -147,7 +147,7 @@ class ClientGetClientWithCredentialsTest(tutils.TestCase): } def test_it_returns_none_without_username(self): - api_version = 1 + api_version = 2 kwargs = self.kwargs.copy() del kwargs['os_username'] self.assertEqual( @@ -155,7 +155,7 @@ class ClientGetClientWithCredentialsTest(tutils.TestCase): None) def test_it_returns_none_without_password(self): - api_version = 1 + api_version = 2 kwargs = self.kwargs.copy() del kwargs['os_password'] self.assertEqual( @@ -163,7 +163,7 @@ class ClientGetClientWithCredentialsTest(tutils.TestCase): None) def test_it_returns_none_without_auth_url(self): - api_version = 1 + api_version = 2 kwargs = self.kwargs.copy() del kwargs['os_auth_url'] self.assertEqual( @@ -171,7 +171,7 @@ class ClientGetClientWithCredentialsTest(tutils.TestCase): None) def test_it_returns_none_without_tenant_id_and_tenant_name(self): - api_version = 1 + api_version = 2 kwargs = self.kwargs.copy() del kwargs['os_tenant_id'] del kwargs['os_tenant_name'] @@ -184,7 +184,7 @@ class ClientGetClientWithCredentialsTest(tutils.TestCase): def test_it_calls_get_token_and_endpoint(self, mocked_get_token_and_endpoint, mocked_get_client_with_token): - api_version = 1 + api_version = 2 kwargs = self.kwargs.copy() mocked_get_token_and_endpoint.return_value = ('token', 'endpoint') mocked_get_client_with_token.return_value = 'mocked client' @@ -296,7 +296,7 @@ class ClientGetClientTest(tutils.TestCase): 'other_key': 'other_value', 'any_other_key': 'any_other_value', } - self.api_version = 1 + self.api_version = 2 @mock.patch.object(client, '_get_client_with_token') @mock.patch.object(client, '_get_client_with_credentials') @@ -349,7 +349,7 @@ class ClientClientTest(tutils.TestCase): @mock.patch.object(client.utils, 'import_versioned_module') def test_it_works(self, mocked_import_versioned_module): - api_version = 1 + api_version = 2 args = ['argument', 'parameter'] kwargs = { 'other_key': 'other_value', diff --git a/tuskarclient/tests/test_shell.py b/tuskarclient/tests/test_shell.py index 0fa1aa1..549fbf7 100644 --- a/tuskarclient/tests/test_shell.py +++ b/tuskarclient/tests/test_shell.py @@ -57,14 +57,14 @@ class ShellTest(tutils.TestCase): args.tuskar_url = 'tuskar' ensure(args) # doesn't raise - def test_parser_v1(self): - v1_commands = [ + def test_parser_v2(self): + v2_commands = [ ] - parser, subparsers = self.s._parser(1) + parser, subparsers = self.s._parser(2) tuskar_help = parser.format_help() for arg in map(lambda a: a.replace('_', '-'), self.args_attributes): self.assertIn(arg, tuskar_help) - for command in v1_commands: + for command in v2_commands: self.assertIn(command, tuskar_help) diff --git a/tuskarclient/tests/v1/__init__.py b/tuskarclient/tests/v1/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tuskarclient/tests/v1/test_client.py b/tuskarclient/tests/v1/test_client.py deleted file mode 100644 index ed5909f..0000000 --- a/tuskarclient/tests/v1/test_client.py +++ /dev/null @@ -1,28 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tuskarclient.tests import utils as tutils -from tuskarclient.v1 import client - - -class ClientTest(tutils.TestCase): - - def setUp(self): - super(ClientTest, self).setUp() - self.endpoint = "http://fakeurl:1234" - self.client = client.Client(self.endpoint) - - def test_managers_present(self): - self.assertThat(self.client, tutils.HasManager('OvercloudRoleManager', - 'overcloud_roles')) - self.assertThat(self.client, tutils.HasManager('OvercloudManager', - 'overclouds')) diff --git a/tuskarclient/tests/v1/test_overcloud_roles.py b/tuskarclient/tests/v1/test_overcloud_roles.py deleted file mode 100644 index fd6830d..0000000 --- a/tuskarclient/tests/v1/test_overcloud_roles.py +++ /dev/null @@ -1,80 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock - -import tuskarclient.tests.utils as tutils -from tuskarclient.v1 import overcloud_roles - - -class OvercloudRoleManagerTest(tutils.TestCase): - - def setUp(self): - """Create a mock API object and bind to the OvercloudManager manager. - """ - super(OvercloudRoleManagerTest, self).setUp() - self.api = mock.Mock() - self.rcm = overcloud_roles.OvercloudRoleManager(self.api) - - def test_get(self): - """Test a standard GET operation to read/retrieve the Overcloud Role. - """ - self.rcm._get = mock.Mock(return_value='fake_overcloud_role') - - self.assertEqual(self.rcm.get(42), 'fake_overcloud_role') - self.rcm._get.assert_called_once_with('/v1/overcloud_roles/42') - - def test_get_404(self): - """Test a 404 response to a standard GET.""" - self.rcm._get = mock.Mock(return_value=None) - - self.assertEqual(self.rcm.get('fake_overcloud_role'), None) - self.rcm._get.assert_called_once_with( - '/v1/overcloud_roles/fake_overcloud_role') - - def test_list(self): - """Test retrieving a list of Overcloud Roles via GET.""" - self.rcm._list = mock.Mock(return_value=['fake_overcloud_role']) - - self.assertEqual(self.rcm.list(), ['fake_overcloud_role']) - self.rcm._list.assert_called_once_with('/v1/overcloud_roles') - - def test_create(self): - """Test creating a new Overcloud Role via POST.""" - self.rcm._create = mock.Mock(return_value=['fake_overcloud_role']) - - self.assertEqual( - self.rcm.create(dummy='dummy overcloud role data'), - ['fake_overcloud_role']) - - self.rcm._create.assert_called_once_with( - '/v1/overcloud_roles', - {'dummy': 'dummy overcloud role data'}) - - def test_update(self): - """Test updating a Overcloud Role via PUT.""" - self.rcm._update = mock.Mock(return_value=['fake_overcloud_role']) - - self.assertEqual( - self.rcm.update(42, dummy='dummy overcloud role data'), - ['fake_overcloud_role']) - - self.rcm._update.assert_called_once_with( - '/v1/overcloud_roles/42', - {'dummy': 'dummy overcloud role data'}) - - def test_delete(self): - """Test deleting/removing a Overcloud Role via DELETE.""" - self.rcm._delete = mock.Mock(return_value=None) - - self.assertEqual(self.rcm.delete(42), None) - self.rcm._delete.assert_called_once_with('/v1/overcloud_roles/42') diff --git a/tuskarclient/tests/v1/test_overcloud_roles_shell.py b/tuskarclient/tests/v1/test_overcloud_roles_shell.py deleted file mode 100644 index 50979fb..0000000 --- a/tuskarclient/tests/v1/test_overcloud_roles_shell.py +++ /dev/null @@ -1,126 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -import six - -import tuskarclient.tests.utils as tutils -from tuskarclient.v1 import overcloud_roles_shell - - -def empty_args(): - args = mock.Mock(spec=[]) - for attr in ['id', 'name', 'subnet', 'capacities', 'slots', - 'resource_class']: - setattr(args, attr, None) - return args - - -def mock_overcloud(): - overcloud = mock.Mock() - overcloud.id = '5' - overcloud.name = 'Testing Overcloud Role' - return overcloud - - -class OvercloudRoleShellTest(tutils.TestCase): - - def setUp(self): - super(OvercloudRoleShellTest, self).setUp() - self.outfile = six.StringIO() - self.tuskar = mock.MagicMock() - self.shell = overcloud_roles_shell - - @mock.patch('tuskarclient.common.utils.find_resource') - @mock.patch('tuskarclient.v1.overcloud_roles_shell.print_role_detail') - def test_overcloud_role_show(self, mock_print_detail, mock_find_resource): - mock_find_resource.return_value = mock_overcloud() - args = empty_args() - args.role = '5' - - self.shell.do_overcloud_role_show(self.tuskar, args, - outfile=self.outfile) - mock_find_resource.assert_called_with(self.tuskar.overcloud_roles, '5') - mock_print_detail.assert_called_with(mock_find_resource.return_value, - outfile=self.outfile) - - @mock.patch('tuskarclient.common.formatting.print_list') - def test_overcloud_role_list(self, mock_print_list): - args = empty_args() - - self.shell.do_overcloud_role_list(self.tuskar, args, - outfile=self.outfile) - # testing the other arguments would be just copy-paste - mock_print_list.assert_called_with( - self.tuskar.overcloud_roles.list.return_value, mock.ANY, - outfile=self.outfile - ) - - @mock.patch('tuskarclient.common.utils.find_resource') - @mock.patch('tuskarclient.v1.overcloud_roles_shell.print_role_detail') - def test_overcloud_role_create(self, mock_print, mock_find_resource): - mock_find_resource.return_value = mock_overcloud() - args = empty_args() - args.name = 'My Overcloud Role' - args.description = 'This is an Overcloud Role.' - args.image_name = 'image' - args.flavor_id = '1' - - self.shell.do_overcloud_role_create(self.tuskar, args, - outfile=self.outfile) - self.tuskar.overcloud_roles.create.assert_called_with( - name='My Overcloud Role', - flavor_id='1', - description='This is an Overcloud Role.', - image_name='image' - ) - mock_print.assert_called_with( - self.tuskar.overcloud_roles.create.return_value, - outfile=self.outfile - ) - - @mock.patch('tuskarclient.common.utils.find_resource') - @mock.patch('tuskarclient.v1.overcloud_roles_shell.print_role_detail') - def test_overcloud_role_update(self, mock_print, mock_find_resource): - mock_find_resource.return_value = mock_overcloud() - args = empty_args() - args.role = '5' - args.name = 'My Overcloud Role' - args.description = 'This is an Overcloud Role.' - args.image_name = 'image' - args.flavor_id = '1' - - self.shell.do_overcloud_role_update(self.tuskar, args, - outfile=self.outfile) - self.tuskar.overcloud_roles.update.assert_called_with( - '5', - name='My Overcloud Role', - flavor_id='1', - description='This is an Overcloud Role.', - image_name='image' - ) - mock_print.assert_called_with( - self.tuskar.overcloud_roles.update.return_value, - outfile=self.outfile - ) - - @mock.patch('tuskarclient.common.utils.find_resource') - def test_overcloud_role_delete(self, mock_find_resource): - mock_find_resource.return_value = mock_overcloud() - args = empty_args() - args.role = '5' - - self.shell.do_overcloud_role_delete(self.tuskar, args, - outfile=self.outfile) - self.tuskar.overcloud_roles.delete.assert_called_with('5') - self.assertEqual('Deleted Overcloud Role "Testing Overcloud Role".\n', - self.outfile.getvalue()) diff --git a/tuskarclient/tests/v1/test_overclouds.py b/tuskarclient/tests/v1/test_overclouds.py deleted file mode 100644 index a8eb050..0000000 --- a/tuskarclient/tests/v1/test_overclouds.py +++ /dev/null @@ -1,85 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock - -import tuskarclient.tests.utils as tutils -from tuskarclient.v1 import overclouds - - -class OvercloudManagerTest(tutils.TestCase): - - def setUp(self): - """Create a mock API object and bind to the OvercloudManager manager. - """ - super(OvercloudManagerTest, self).setUp() - self.api = mock.Mock() - self.om = overclouds.OvercloudManager(self.api) - - def test_get(self): - """Test a standard GET operation to read/retrieve the overcloud.""" - self.om._get = mock.Mock(return_value='fake_overcloud') - - self.assertEqual(self.om.get('fake_overcloud'), 'fake_overcloud') - self.om._get.assert_called_with('/v1/overclouds/fake_overcloud') - - def test_get_404(self): - """Test a 404 response to a standard GET.""" - self.om._get = mock.Mock(return_value=None) - - self.assertEqual(self.om.get('fake_overcloud'), None) - self.om._get.assert_called_with('/v1/overclouds/fake_overcloud') - - def test_list(self): - """Test retrieving a list of overclouds via GET.""" - self.om._list = mock.Mock(return_value=['fake_overcloud']) - - self.assertEqual(self.om.list(), ['fake_overcloud']) - self.om._list.assert_called_with('/v1/overclouds') - - def test_create(self): - """Test creating a new overcloud via POST.""" - self.om._create = mock.Mock(return_value=['fake_overcloud']) - - self.assertEqual( - self.om.create(dummy='dummy overcloud data'), - ['fake_overcloud']) - - self.om._create.assert_called_with( - '/v1/overclouds', - {'dummy': 'dummy overcloud data'}) - - def test_update(self): - """Test updating an overcloud via POST.""" - self.om._update = mock.Mock(return_value=['fake_overcloud']) - - self.assertEqual( - self.om.update(42, dummy='dummy overcloud data'), - ['fake_overcloud']) - - self.om._update.assert_called_with( - '/v1/overclouds/42', - {'dummy': 'dummy overcloud data'}) - - def test_delete(self): - """Test deleting/removing an overcloud via DELETE.""" - self.om._delete = mock.Mock(return_value=None) - - self.assertEqual(self.om.delete(42), None) - self.om._delete.assert_called_with('/v1/overclouds/42') - - def test_template_parameters(self): - """Test getting the template parameters via GET.""" - self.om._get = mock.Mock(return_value={}) - - self.assertEqual(self.om.template_parameters(), {}) - self.om._get.assert_called_with('/v1/overclouds/template_parameters') diff --git a/tuskarclient/tests/v1/test_overclouds_shell.py b/tuskarclient/tests/v1/test_overclouds_shell.py deleted file mode 100644 index 6e57ac0..0000000 --- a/tuskarclient/tests/v1/test_overclouds_shell.py +++ /dev/null @@ -1,271 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -import six - -from tuskarclient.openstack.common.apiclient import exceptions -import tuskarclient.tests.utils as tutils -from tuskarclient.v1 import overcloud_roles -from tuskarclient.v1 import overclouds_shell - - -def empty_args(): - args = mock.Mock(spec=[]) - for attr in ['id', 'name', 'subnet', 'capacities', 'slots', - 'resource_class']: - setattr(args, attr, None) - return args - - -def mock_overcloud(): - overcloud = mock.Mock() - overcloud.id = '5' - overcloud.name = 'My Overcloud' - return overcloud - - -class BaseOvercloudShellTest(tutils.TestCase): - - def setUp(self): - super(BaseOvercloudShellTest, self).setUp() - self.outfile = six.StringIO() - self.tuskar = mock.MagicMock() - self.shell = overclouds_shell - - -class OvercloudShellTest(BaseOvercloudShellTest): - - @mock.patch('tuskarclient.common.utils.find_resource') - @mock.patch('tuskarclient.v1.overclouds_shell.print_overcloud_detail') - def test_overcloud_show(self, mock_print_detail, mock_find_resource): - mock_find_resource.return_value = mock_overcloud() - args = empty_args() - args.overcloud = '5' - - self.shell.do_overcloud_show(self.tuskar, args, outfile=self.outfile) - mock_find_resource.assert_called_with(self.tuskar.overclouds, '5') - mock_print_detail.assert_called_with(mock_find_resource.return_value, - outfile=self.outfile) - - @mock.patch('tuskarclient.common.formatting.print_list') - def test_overcloud_list(self, mock_print_list): - args = empty_args() - - self.shell.do_overcloud_list(self.tuskar, args, outfile=self.outfile) - # testing the other arguments would be just copy-paste - mock_print_list.assert_called_with( - self.tuskar.overclouds.list.return_value, mock.ANY, mock.ANY, - outfile=self.outfile - ) - - @mock.patch('tuskarclient.v1.overclouds_shell.print_overcloud_detail') - def test_overcloud_create(self, mock_print_detail): - args = empty_args() - args.name = 'my_overcloud' - args.attributes = None - args.roles = None - - self.shell.do_overcloud_create(self.tuskar, args, outfile=self.outfile) - self.tuskar.overclouds.create.assert_called_with( - name='my_overcloud', - counts=[], - attributes={} - ) - mock_print_detail.assert_called_with( - self.tuskar.overclouds.create.return_value, outfile=self.outfile) - - @mock.patch('tuskarclient.common.utils.find_resource') - @mock.patch('tuskarclient.v1.overclouds_shell.print_overcloud_detail') - def test_overcloud_update(self, mock_print_detail, mock_find_resource): - mock_find_resource.return_value = mock_overcloud() - args = empty_args() - args.overcloud = '5' - args.name = 'my_overcloud' - args.attributes = None - args.roles = None - - self.shell.do_overcloud_update(self.tuskar, args, outfile=self.outfile) - self.tuskar.overclouds.update.assert_called_with( - '5', - name='my_overcloud', - attributes={}, - counts=[] - ) - mock_print_detail.assert_called_with( - self.tuskar.overclouds.update.return_value, outfile=self.outfile) - - @mock.patch('tuskarclient.common.utils.find_resource') - def test_overcloud_delete(self, mock_find_resource): - mock_find_resource.return_value = mock_overcloud() - args = empty_args() - args.overcloud = '5' - - self.shell.do_overcloud_delete(self.tuskar, args, outfile=self.outfile) - self.tuskar.overclouds.delete.assert_called_with('5') - self.assertEqual('Deleted Overcloud "My Overcloud".\n', - self.outfile.getvalue()) - - -class OvercloudAttributeShellTest(BaseOvercloudShellTest): - - def setUp(self): - super(OvercloudAttributeShellTest, self).setUp() - - self.args = empty_args() - self.args.name = 'my_overcloud' - self.args.roles = None - self.create = self.shell.do_overcloud_create - - @mock.patch('tuskarclient.v1.overclouds_shell.print_overcloud_detail') - def test_create_attributes(self, mock_print_detail): - self.args.attributes = ['val1=10', 'val2=20', 'val3=30'] - - self.create(self.tuskar, self.args, outfile=self.outfile) - self.tuskar.overclouds.create.assert_called_with( - name='my_overcloud', - counts=[], - attributes={ - 'val1': '10', - 'val2': '20', - 'val3': '30', - } - ) - mock_print_detail.assert_called_with( - self.tuskar.overclouds.create.return_value, outfile=self.outfile) - - @mock.patch('tuskarclient.v1.overclouds_shell.print_overcloud_detail') - def test_create_attributes_duplicate(self, mock_print_detail): - self.args.attributes = ['val1=10', 'val1=20'] - - self.assertRaises( - exceptions.ValidationError, - self.create, - self.tuskar, self.args, outfile=self.outfile) - - self.tuskar.overclouds.create.assert_not_called() - - @mock.patch('tuskarclient.v1.overclouds_shell.print_overcloud_detail') - def test_create_attributes_invalid(self, mock_print_detail): - self.args.attributes = ['val1=10', 'val120'] - - self.assertRaises( - exceptions.CommandError, - self.create, - self.tuskar, self.args, outfile=self.outfile) - - self.tuskar.overclouds.create.assert_not_called() - - @mock.patch('tuskarclient.v1.overclouds_shell.print_overcloud_detail') - def test_create_attributes_multiple_equals(self, mock_print_detail): - self.args.attributes = ['val1=10', 'val2=2=0'] - - self.create(self.tuskar, self.args, outfile=self.outfile) - self.tuskar.overclouds.create.assert_called_with( - name='my_overcloud', - counts=[], - attributes={ - 'val1': '10', - 'val2': '2=0', - } - ) - mock_print_detail.assert_called_with( - self.tuskar.overclouds.create.return_value, outfile=self.outfile) - - -class OvercloudRoleShellTest(BaseOvercloudShellTest): - - def setUp(self): - super(OvercloudRoleShellTest, self).setUp() - - self.args = empty_args() - self.args.name = 'my_overcloud' - self.args.attributes = None - self.create = self.shell.do_overcloud_create - - @mock.patch('tuskarclient.v1.overclouds_shell.print_overcloud_detail') - def test_create_roles(self, mock_print_detail): - self.args.roles = ['foo=10'] - self.tuskar.overcloud_roles.list.return_value = [ - overcloud_roles.OvercloudRole(None, {'name': 'foo', 'id': 1}) - ] - - self.create(self.tuskar, self.args, outfile=self.outfile) - self.tuskar.overclouds.create.assert_called_with( - name='my_overcloud', - attributes={}, - counts=[ - {'overcloud_role_id': 1, 'num_nodes': 10}, - ] - ) - mock_print_detail.assert_called_with( - self.tuskar.overclouds.create.return_value, outfile=self.outfile) - - @mock.patch('tuskarclient.v1.overclouds_shell.print_overcloud_detail') - def test_create_roles_duplicate(self, mock_print_detail): - self.args.roles = ['foo=10', 'foo=20'] - self.tuskar.overcloud_roles.list.return_value = [ - overcloud_roles.OvercloudRole(None, {'name': 'foo', 'id': 1}) - ] - - self.assertRaises( - exceptions.ValidationError, - self.create, - self.tuskar, self.args, outfile=self.outfile) - - self.tuskar.overclouds.create.assert_not_called() - - @mock.patch('tuskarclient.v1.overclouds_shell.print_overcloud_detail') - def test_create_roles_invalid_structure(self, mock_print_detail): - self.args.roles = ['foo=10', '120'] - self.tuskar.overcloud_roles.list.return_value = [ - overcloud_roles.OvercloudRole(None, {'name': 'foo', 'id': 1}) - ] - - self.assertRaises( - exceptions.CommandError, - self.create, - self.tuskar, self.args, outfile=self.outfile) - - self.tuskar.overclouds.create.assert_not_called() - - @mock.patch('tuskarclient.v1.overclouds_shell.print_overcloud_detail') - def test_create_roles_multiple_equals(self, mock_print_detail): - self.args.roles = ['foo=foo=0'] - self.tuskar.overcloud_roles.list.return_value = [ - overcloud_roles.OvercloudRole(None, {'name': 'foo', 'id': 1}) - ] - - self.assertRaises( - ValueError, - self.create, - self.tuskar, self.args, outfile=self.outfile) - - self.tuskar.overclouds.create.assert_not_called() - - @mock.patch('tuskarclient.v1.overclouds_shell.print_overcloud_detail') - def test_create_roles_with_id(self, mock_print_detail): - self.args.roles = ['12345=10'] - self.tuskar.overcloud_roles.list.return_value = [ - overcloud_roles.OvercloudRole(None, {'name': 'foo', 'id': 1}) - ] - - self.create(self.tuskar, self.args, outfile=self.outfile) - self.tuskar.overclouds.create.assert_called_with( - name='my_overcloud', - attributes={}, - counts=[ - {'overcloud_role_id': '12345', 'num_nodes': 10}, - ] - ) - mock_print_detail.assert_called_with( - self.tuskar.overclouds.create.return_value, outfile=self.outfile) diff --git a/tuskarclient/v1/__init__.py b/tuskarclient/v1/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tuskarclient/v1/client.py b/tuskarclient/v1/client.py deleted file mode 100644 index 9c5f83f..0000000 --- a/tuskarclient/v1/client.py +++ /dev/null @@ -1,30 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tuskarclient.common import http -from tuskarclient.v1 import overcloud_roles -from tuskarclient.v1 import overclouds - - -class Client(object): - """Client for the Tuskar v1 HTTP API. - - :param string endpoint: Endpoint URL for the tuskar service. - :param string token: Keystone authentication token. - :param integer timeout: Timeout for client http requests. (optional) - """ - - def __init__(self, *args, **kwargs): - self.http_client = http.HTTPClient(*args, **kwargs) - self.overcloud_roles = overcloud_roles.OvercloudRoleManager( - self.http_client) - self.overclouds = overclouds.OvercloudManager(self.http_client) diff --git a/tuskarclient/v1/overcloud_roles.py b/tuskarclient/v1/overcloud_roles.py deleted file mode 100644 index a1b97b6..0000000 --- a/tuskarclient/v1/overcloud_roles.py +++ /dev/null @@ -1,95 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tuskarclient.common import base -from tuskarclient.openstack.common.apiclient import base as common_base - - -class OvercloudRole(common_base.Resource): - """Represents an instance of an Overcloud Role in the Tuskar API. - - :param manager: Manager object - :param info: dictionary representing the resource attributes - :param loaded: prevent lazy-loading if set to True - """ - - -class OvercloudRoleManager(base.Manager): - """OvercloudRoleManager interacts with the Tuskar API and provides CRUD - operations for the overcloud role type. - """ - - #: The class used to represent an overcloud role instance - resource_class = OvercloudRole - - @staticmethod - def _path(overcloud_role_id=None): - - if overcloud_role_id: - return '/v1/overcloud_roles/%s' % overcloud_role_id - - return '/v1/overcloud_roles' - - def list(self): - """Get a list of the existing Overcloud Roles - - :return: A list of Overcloud Roles or an empty list if none exist. - :rtype: [tuskarclient.v1.overcloud_roles.OvercloudRole] or [] - """ - return self._list(self._path()) - - def get(self, overcloud_role_id): - """Get the Overcloud Role by its ID. - - :param id: id of the Overcloud Role. - :type id: string - - :return: A Overcloud Role instance or None if its not found. - :rtype: tuskarclient.v1.overcloud_roles.OvercloudRole or None - """ - return self._get(self._single_path(overcloud_role_id)) - - def create(self, **fields): - """Create a new Overcloud Role. - - :param fields: A set of key/value pairs representing a OvercloudRole - :type fields: string - - :return: A Overcloud Role instance or None if its not found. - :rtype: tuskarclient.v1.overcloud_roles.OvercloudRole - """ - return self._create(self._path(), fields) - - def update(self, overcloud_role_id, **fields): - """Update an existing Overcloud Role. - - :param overcloud_role_id: id of the Overcloud Role. - :type overcloud_role_id: string - - :param fields: A set of key/value pairs representing a OvercloudRole - :type fields: string - - :return: An OvercloudRole instance or None if its not found. - :rtype: tuskarclient.v1.overcloud_roles.OvercloudRole or None - """ - return self._update(self._single_path(overcloud_role_id), fields) - - def delete(self, overcloud_role_id): - """Delete a Overcloud Role. - - :param id: id of the Overcloud Role. - :type id: string - - :return: None - :rtype: None - """ - return self._delete(self._single_path(overcloud_role_id)) diff --git a/tuskarclient/v1/overcloud_roles_shell.py b/tuskarclient/v1/overcloud_roles_shell.py deleted file mode 100644 index 459d13b..0000000 --- a/tuskarclient/v1/overcloud_roles_shell.py +++ /dev/null @@ -1,98 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from __future__ import print_function - -import sys - -import tuskarclient.common.formatting as fmt -from tuskarclient.common import utils - - -@utils.arg('role', metavar="", - help="ID or name of the Overcloud Role to show.") -def do_overcloud_role_show(tuskar, args, outfile=sys.stdout): - """Show an individual Overcloud Role by its ID or name.""" - overcloud_role = utils.find_resource(tuskar.overcloud_roles, args.role) - print_role_detail(overcloud_role, outfile=outfile) - - -def do_overcloud_role_list(tuskar, args, outfile=sys.stdout): - """Show a list of the Overcloud Roles.""" - overcloud_roles = tuskar.overcloud_roles.list() - fields = ['id', 'name', 'image_name', 'flavor_id'] - fmt.print_list(overcloud_roles, fields, outfile=outfile) - - -@utils.arg('name', help="Name of the Overcloud Role to create.") -@utils.arg('-d', '--description', metavar="", - help='User-readable text describing the overcloud.') -@utils.arg('-i', '--image-name', metavar="", - help='Name of the image in Glance to be used for this Role.') -@utils.arg('-f', '--flavor-id', metavar="", - help='UUID of the flavor of node this role should be deployed on.') -def do_overcloud_role_create(tuskar, args, outfile=sys.stdout): - """Create a new Overcloud Role.""" - overcloud_role_dict = create_overcloud_role_dict(args) - overcloud_role = tuskar.overcloud_roles.create(**overcloud_role_dict) - print_role_detail(overcloud_role, outfile=outfile) - - -@utils.arg('role', metavar="", - help="ID or name of the Overcloud Role to update.") -@utils.arg('-n', '--name', metavar="", - help='Name of the Overcloud Role to update.') -@utils.arg('-d', '--description', metavar="", - help='User-readable text describing the overcloud.') -@utils.arg('-i', '--image-name', metavar="", - help='Name of the image in Glance to be used for this Role.') -@utils.arg('-f', '--flavor-id', metavar="", - help='UUID of the flavor of node this role should be deployed on.') -def do_overcloud_role_update(tuskar, args, outfile=sys.stdout): - """Update an existing Overcloud Role by its ID or name.""" - overcloud_role = utils.find_resource(tuskar.overcloud_roles, args.role) - overcloud_role_dict = create_overcloud_role_dict(args) - updated_overcloud_role = tuskar.overcloud_roles.update( - overcloud_role.id, - **overcloud_role_dict - ) - print_role_detail(updated_overcloud_role, outfile=outfile) - - -@utils.arg('role', metavar="", - help="ID or name of the Overcloud Role to delete.") -def do_overcloud_role_delete(tuskar, args, outfile=sys.stdout): - """Delete an Overcloud Role by its ID or name.""" - overcloud_role = utils.find_resource(tuskar.overcloud_roles, args.role) - tuskar.overcloud_roles.delete(overcloud_role.id) - print(u'Deleted Overcloud Role "%s".' % overcloud_role.name, file=outfile) - - -def create_overcloud_role_dict(args): - """Marshal command line arguments to an API request dict.""" - overcloud_role_dict = {} - simple_fields = ['name', 'description', 'image_name', 'flavor_id'] - for field_name in simple_fields: - field_value = vars(args)[field_name] - if field_value is not None: - overcloud_role_dict[field_name] = field_value - - utils.marshal_association(args, overcloud_role_dict, 'resource_class') - - return overcloud_role_dict - - -def print_role_detail(overcloud_role, outfile=sys.stdout): - """Print detailed Overcloud Role information (overcloud-role-show etc.).""" - - overcloud_role_dict = overcloud_role.to_dict() - fmt.print_dict(overcloud_role_dict, outfile=outfile) diff --git a/tuskarclient/v1/overclouds.py b/tuskarclient/v1/overclouds.py deleted file mode 100644 index d0a38d1..0000000 --- a/tuskarclient/v1/overclouds.py +++ /dev/null @@ -1,103 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tuskarclient.common import base -from tuskarclient.openstack.common.apiclient import base as common_base - - -class Overcloud(common_base.Resource): - """Represents an instance of a Overcloud in the Tuskar API. - - :param manager: Manager object - :param info: dictionary representing resource attributes - :param loaded: prevent lazy-loading if set to True - """ - - -class OvercloudManager(base.Manager): - """OvercloudManager interacts with the Tuskar API and provides CRUD - operations for the Overcloud type. - """ - - #: The class used to represent an Overcloud instance - resource_class = Overcloud - - @staticmethod - def _path(overcloud_id=None): - - if overcloud_id: - return '/v1/overclouds/%s' % overcloud_id - - return '/v1/overclouds' - - def list(self): - """Get a list of the existing Overclouds - - :return: A list of overclounds or an empty list if none are found. - :rtype: [tuskarclient.v1.overclouds.Overcloud] or [] - """ - return self._list(self._path()) - - def get(self, overcloud_id): - """Get the Overcloud by its ID. - - :param overcloud_id: id of the Overcloud. - :type overcloud_id: string - - :return: A Overcloud instance or None if its not found. - :rtype: tuskarclient.v1.overclouds.Overcloud or None - """ - return self._get(self._single_path(overcloud_id)) - - def create(self, **fields): - """Create a new Overcloud. - - :param fields: A set of key/value pairs representing a Overcloud. - :type fields: string - - :return: A Overcloud instance or None if its not found. - :rtype: tuskarclient.v1.overclouds.Overcloud - """ - return self._create(self._path(), fields) - - def update(self, overcloud_id, **fields): - """Update an existing Overcloud. - - :param overcloud_id: id of the Overcloud. - :type overcloud_id: string - - :param fields: A set of key/value pairs representing the Overcloud. - :type fields: string - - :return: A Overcloud instance or None if its not found. - :rtype: tuskarclient.v1.overclouds.Overcloud or None - """ - return self._update(self._single_path(overcloud_id), fields) - - def delete(self, overcloud_id): - """Delete an Overcloud. - - :param overcloud_id: id of the Overcloud. - :type overcloud_id: string - - :return: None - :rtype: None - """ - return self._delete(self._single_path(overcloud_id)) - - def template_parameters(self): - """Get the template parameters from the Tuskar API. - - :return: Dictionary containing template parameters - :rtype: dict - """ - return self._get("{0}/template_parameters".format(self._path())) diff --git a/tuskarclient/v1/overclouds_shell.py b/tuskarclient/v1/overclouds_shell.py deleted file mode 100644 index 72a3a2b..0000000 --- a/tuskarclient/v1/overclouds_shell.py +++ /dev/null @@ -1,138 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from __future__ import print_function - -import sys - -import tuskarclient.common.formatting as fmt -from tuskarclient.common import utils - - -@utils.arg('overcloud', metavar="", - help="ID or name of the Overcloud to show.") -def do_overcloud_show(tuskar, args, outfile=sys.stdout): - """Show an individual Overcloud by its ID or name.""" - overcloud = utils.find_resource(tuskar.overclouds, args.overcloud) - print_overcloud_detail(overcloud, outfile=outfile) - - -def do_overcloud_list(tuskar, args, outfile=sys.stdout): - """Show a list of the Overclouds.""" - overclouds = tuskar.overclouds.list() - fields = ['id', 'name', 'description', 'stack_id', 'attributes', 'counts'] - - formatters = { - 'attributes': fmt.attributes_formatter, - 'counts': fmt.counts_formatter, - } - - fmt.print_list(overclouds, fields, formatters, outfile=outfile) - - -@utils.arg('name', help="Name of the Overcloud to create.") -@utils.arg('-d', '--description', metavar="", - help='User-readable text describing the overcloud.') -@utils.arg('-s', '--stack-id', metavar="", - help='UID of the stack in Heat.') -@utils.arg('-A', '--attribute', dest='attributes', metavar='', - help='This can be specified multiple times.', - action='append') -@utils.arg('-R', '--role-count', dest='roles', - metavar='', - help='This can be specified multiple times.', - action='append') -def do_overcloud_create(tuskar, args, outfile=sys.stdout): - """Create a new Overcloud.""" - overcloud_roles = tuskar.overcloud_roles.list() - overcloud_dict = create_overcloud_dict(args, overcloud_roles) - overcloud = tuskar.overclouds.create(**overcloud_dict) - print_overcloud_detail(overcloud, outfile=outfile) - - -@utils.arg('overcloud', metavar="", - help="ID or name of the Overcloud to update.") -@utils.arg('-n', '--name', metavar="", - help='Name of the Overcloud Role to update.') -@utils.arg('-d', '--description', metavar="", - help='User-readable text describing the overcloud.') -@utils.arg('-s', '--stack-id', metavar="", - help='UID of the stack in Heat.') -@utils.arg('-A', '--attribute', dest='attributes', metavar='', - help='This can be specified multiple times.', - action='append') -@utils.arg('-R', '--role-count', dest='roles', - metavar='', - help='This can be specified multiple times.', - action='append') -def do_overcloud_update(tuskar, args, outfile=sys.stdout): - """Update an existing Overcloud by its ID or name.""" - overcloud = utils.find_resource(tuskar.overclouds, args.overcloud) - overcloud_roles = tuskar.overcloud_roles.list() - overcloud_dict = create_overcloud_dict(args, overcloud_roles) - updated_overcloud = tuskar.overclouds.update(overcloud.id, - **overcloud_dict) - print_overcloud_detail(updated_overcloud, outfile=outfile) - - -@utils.arg('overcloud', metavar="", - help="ID or name of the Overcloud to delete.") -def do_overcloud_delete(tuskar, args, outfile=sys.stdout): - """Delete an Overcloud by its ID or name.""" - overcloud = utils.find_resource(tuskar.overclouds, args.overcloud) - tuskar.overclouds.delete(overcloud.id) - print(u'Deleted Overcloud "%s".' % overcloud.name, file=outfile) - - -def do_overcloud_show_template_parameters(tuskar, args, outfile=sys.stdout): - """Show the template parameters stored in the Tuskar API.""" - template_parameters = tuskar.overclouds.template_parameters() - formatters = { - '*': fmt.attributes_formatter - } - template_parameters_dict = template_parameters.to_dict() - fmt.print_dict(template_parameters_dict, formatters, outfile=outfile) - - -def create_overcloud_dict(args, roles): - """Marshal command line arguments to an API request dict. - - :param roles: list of OvercloudRole instances retrieved from the tuskar - client - :type roles: list of OvercloudRole - """ - overcloud_dict = {} - simple_fields = ['name', 'description'] - for field_name in simple_fields: - field_value = vars(args).get(field_name) - if field_value is not None: - overcloud_dict[field_name] = field_value - - overcloud_dict['attributes'] = utils.format_attributes(args.attributes) - - role_name_ids = dict((r.to_dict()['name'], r.to_dict()['id']) - for r in roles) - overcloud_dict['counts'] = utils.format_roles(args.roles, role_name_ids) - - utils.marshal_association(args, overcloud_dict, 'resource_class') - return overcloud_dict - - -def print_overcloud_detail(overcloud, outfile=sys.stdout): - """Print detailed overcloud information (for overcloud-show etc.).""" - - formatters = { - 'attributes': fmt.attributes_formatter, - 'counts': fmt.counts_formatter, - } - overcloud_dict = overcloud.to_dict() - fmt.print_dict(overcloud_dict, formatters, outfile=outfile) diff --git a/tuskarclient/v1/shell.py b/tuskarclient/v1/shell.py deleted file mode 100644 index 5665d62..0000000 --- a/tuskarclient/v1/shell.py +++ /dev/null @@ -1,32 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tuskarclient.common import utils -from tuskarclient.v1 import overcloud_roles_shell -from tuskarclient.v1 import overclouds_shell - -COMMAND_MODULES = [ - overcloud_roles_shell, - overclouds_shell -] - - -def enhance_parser(parser, subparsers): - """Take a basic (nonversioned) parser and enhance it with - commands and options specific for this version of API. - - :param parser: top level parser - :param subparsers: top level parser's subparsers collection - where subcommands will go - """ - for command_module in COMMAND_MODULES: - utils.define_commands_from_module(subparsers, command_module) diff --git a/tuskarclient/v2/plans.py b/tuskarclient/v2/plans.py index fd8236e..61ff270 100644 --- a/tuskarclient/v2/plans.py +++ b/tuskarclient/v2/plans.py @@ -93,7 +93,7 @@ class PlanManager(base.Manager): :type fields: string :return: A Plan instance or None if its not found. - :rtype: tuskarclient.v1.plans.Plan + :rtype: tuskarclient.v2.plans.Plan """ return self._create(self._path(), fields)