CLI changes for supporting custom language packs

- Added 'solum languagepack build' command.
- Added code to invoke the builder client.

https://review.openstack.org/#/c/103689/11

Change-Id: I0480f074bf409d58a6de1b6e1232f858bd5f80f3
This commit is contained in:
arati.mahimane
2014-07-09 16:47:36 -05:00
parent 44465a10c7
commit ecf7c78b89
4 changed files with 77 additions and 2 deletions

View File

@@ -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)

View File

@@ -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:

View File

@@ -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."""

View File

@@ -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)