diff --git a/solumclient/builder/client.py b/solumclient/builder/client.py index 3b4f796..a6a4ef7 100644 --- a/solumclient/builder/client.py +++ b/solumclient/builder/client.py @@ -34,3 +34,30 @@ def Client(version, **kwargs): endpoint=kwargs.get('endpoint')) http_client = client.HTTPClient(keystone_auth) return client_class(http_client) + + +def get_client(api_version, **kwargs): + """Get an authtenticated client. + + This is based on the credentials in the keyword args. + + :param api_version: the API version to use + :param kwargs: keyword args containing credentials, either: + * os_auth_token: pre-existing token to re-use + * endpoint: solum API endpoint + or: + * os_username: name of user + * os_password: user's password + * os_auth_url: endpoint to authenticate against + * os_tenant_name: name of tenant + """ + cli_kwargs = { + 'username': kwargs.get('os_username'), + 'password': kwargs.get('os_password'), + 'tenant_name': kwargs.get('os_tenant_name'), + 'token': kwargs.get('os_auth_token'), + 'auth_url': kwargs.get('os_auth_url'), + 'endpoint': kwargs.get('solum_url') + } + + return Client(api_version, **cli_kwargs) diff --git a/solumclient/common/cli_utils.py b/solumclient/common/cli_utils.py index 2f0bd6d..7c571b9 100644 --- a/solumclient/common/cli_utils.py +++ b/solumclient/common/cli_utils.py @@ -17,6 +17,7 @@ import os from keystoneclient.openstack.common.apiclient import exceptions as ks_exc +from solumclient.builder import client as builder_client from solumclient import client as solum_client from solumclient.common import exc from solumclient.openstack.common.apiclient import exceptions @@ -104,8 +105,13 @@ class CommandsBase(object): client_args['endpoint'] = client_args['solum_url'] del client_args['solum_url'] - self.client = solum_client.get_client(parsed.solum_api_version, - **client_args) + + if client_args['action'] == 'build': + self.client = builder_client.get_client(parsed.solum_api_version, + **client_args) + else: + self.client = solum_client.get_client(parsed.solum_api_version, + **client_args) if action in self._actions: try: diff --git a/solumclient/solum.py b/solumclient/solum.py index 5ebf808..4978892 100644 --- a/solumclient/solum.py +++ b/solumclient/solum.py @@ -284,6 +284,21 @@ class LanguagePackCommands(cli_utils.CommandsBase): for f in fields]) cliutils.print_dict(data, wrap=72) + def build(self): + """Build a custom language pack.""" + self.parser.add_argument('name', + help="Language pack name.") + self.parser.add_argument('git_url', + help=("Github url of custom " + "language pack repository.")) + args = self.parser.parse_args() + response = self.client.images.create(name=args.name, + source_uri=args.git_url) + fields = ['uuid', 'name'] + data = dict([(f, getattr(response, f, '')) + for f in fields]) + cliutils.print_dict(data, wrap=72) + def main(): """Basically the entry point.""" diff --git a/solumclient/tests/v1/test_languagepack.py b/solumclient/tests/v1/test_languagepack.py index d57448f..e0c6aad 100644 --- a/solumclient/tests/v1/test_languagepack.py +++ b/solumclient/tests/v1/test_languagepack.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from solumclient.builder.v1 import image from solumclient.openstack.common.apiclient import fake_client from solumclient.tests import base from solumclient.v1 import client as sclient @@ -92,6 +93,20 @@ fixtures_create = { } } +image_fixture = { + 'name': 'lp1', + 'source_uri': 'github.com/test' +} + +fixtures_build = { + '/v1/images': { + 'POST': ( + {}, + image_fixture + ), + } +} + class LanguagePackManagerTest(base.TestCase): @@ -128,3 +143,15 @@ class LanguagePackManagerTest(base.TestCase): mgr = languagepack.LanguagePackManager(api_client) languagepack_obj = mgr.get(lp_id='x1') self.assert_lp_object(languagepack_obj) + + def test_build(self): + fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_build) + api_client = sclient.Client(fake_http_client) + mgr = image.ImageManager(api_client) + image_obj = mgr.create(name='lp1', source_uri='github.com/test') + self.assert_image_object(image_obj) + + def assert_image_object(self, image_obj): + self.assertIn('Image', repr(image_obj)) + self.assertEqual(image_fixture['source_uri'], image_obj.source_uri) + self.assertEqual(image_fixture['name'], image_obj.name)