Add service API support in client side

$ mistral service-list
+---------------+----------------+
| Name          | Type           |
+---------------+----------------+
| mistral_29703 | engine_group   |
| mistral_29703 | api_group      |
| mistral_29703 | executor_group |
+---------------+----------------+

Change-Id: I9be8c74c3fbab7782a9056a70075e7963e9b78f4
Implements: blueprint mistral-service-cli-support
This commit is contained in:
LingxianKong
2015-08-14 11:48:51 +08:00
parent 71b5d2c230
commit 18bb3c6439
7 changed files with 154 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ from mistralclient.api.v2 import actions
from mistralclient.api.v2 import cron_triggers from mistralclient.api.v2 import cron_triggers
from mistralclient.api.v2 import environments from mistralclient.api.v2 import environments
from mistralclient.api.v2 import executions from mistralclient.api.v2 import executions
from mistralclient.api.v2 import services
from mistralclient.api.v2 import tasks from mistralclient.api.v2 import tasks
from mistralclient.api.v2 import workbooks from mistralclient.api.v2 import workbooks
from mistralclient.api.v2 import workflows from mistralclient.api.v2 import workflows
@@ -58,6 +59,7 @@ class Client(object):
self.cron_triggers = cron_triggers.CronTriggerManager(self) self.cron_triggers = cron_triggers.CronTriggerManager(self)
self.environments = environments.EnvironmentManager(self) self.environments = environments.EnvironmentManager(self)
self.action_executions = action_executions.ActionExecutionManager(self) self.action_executions = action_executions.ActionExecutionManager(self)
self.services = services.ServiceManager(self)
def authenticate(self, mistral_url=None, username=None, api_key=None, def authenticate(self, mistral_url=None, username=None, api_key=None,
project_name=None, auth_url=None, project_id=None, project_name=None, auth_url=None, project_id=None,

View File

@@ -0,0 +1,26 @@
# Copyright 2015 Huawei Technologies Co., Ltd.
#
# 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 mistralclient.api import base
class Service(base.Resource):
resource_name = 'Service'
class ServiceManager(base.ResourceManager):
resource_class = Service
def list(self):
return self._list('/services', response_key='services')

View File

@@ -0,0 +1,42 @@
# Copyright 2015 Huawei Technologies Co., Ltd.
#
# 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 logging
from mistralclient.api.v2 import services
from mistralclient.commands.v2 import base
LOG = logging.getLogger(__name__)
def format_list(service=None):
columns = ('Name', 'Type')
if service:
data = (service.name, service.type)
else:
data = (tuple('<none>' for _ in range(len(columns))),)
return columns, data
class List(base.MistralLister):
"""List all services."""
def _get_format_function(self):
return format_list
def _get_resources(self, parsed_args):
return services.ServiceManager(self.app.client).list()

View File

@@ -25,6 +25,7 @@ import mistralclient.commands.v2.actions
import mistralclient.commands.v2.cron_triggers import mistralclient.commands.v2.cron_triggers
import mistralclient.commands.v2.environments import mistralclient.commands.v2.environments
import mistralclient.commands.v2.executions import mistralclient.commands.v2.executions
import mistralclient.commands.v2.services
import mistralclient.commands.v2.tasks import mistralclient.commands.v2.tasks
import mistralclient.commands.v2.workbooks import mistralclient.commands.v2.workbooks
import mistralclient.commands.v2.workflows import mistralclient.commands.v2.workflows
@@ -364,7 +365,8 @@ class MistralShell(app.App):
'cron-trigger-create': 'cron-trigger-create':
mistralclient.commands.v2.cron_triggers.Create, mistralclient.commands.v2.cron_triggers.Create,
'cron-trigger-delete': 'cron-trigger-delete':
mistralclient.commands.v2.cron_triggers.Delete mistralclient.commands.v2.cron_triggers.Delete,
'service-list': mistralclient.commands.v2.services.List
} }

View File

@@ -29,3 +29,4 @@ class BaseClientV2Test(base.BaseClientTest):
self.workflows = self._client.workflows self.workflows = self._client.workflows
self.environments = self._client.environments self.environments = self._client.environments
self.action_executions = self._client.action_executions self.action_executions = self._client.action_executions
self.services = self._client.services

View File

@@ -0,0 +1,38 @@
# Copyright 2015 Huawei Technologies Co., Ltd.
#
# 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
from mistralclient.api.v2 import services
from mistralclient.commands.v2 import services as service_cmd
from mistralclient.tests.unit import base
SERVICE_DICT = {
'name': 'service_name',
'type': 'service_type',
}
SERVICE = services.Service(mock, SERVICE_DICT)
class TestCLIServicesV2(base.BaseCommandTest):
@mock.patch('mistralclient.api.v2.services.ServiceManager.list')
def test_list(self, mock):
mock.return_value = (SERVICE,)
expected = (SERVICE_DICT['name'], SERVICE_DICT['type'],)
result = self.call(service_cmd.List)
self.assertListEqual([expected], result[1])

View File

@@ -0,0 +1,42 @@
# Copyright 2015 Huawei Technologies Co., Ltd.
#
# 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 mistralclient.api.v2 import services
from mistralclient.tests.unit.v2 import base
SERVICE = {
'name': 'service_name',
'type': 'service_type',
}
URL_TEMPLATE = '/services'
class TestServicesV2(base.BaseClientV2Test):
def test_list(self):
mock = self.mock_http_get(content={'services': [SERVICE]})
service_list = self.services.list()
self.assertEqual(1, len(service_list))
srv = service_list[0]
self.assertDictEqual(
services.Service(self.services, SERVICE).to_dict(),
srv.to_dict()
)
mock.assert_called_once_with(URL_TEMPLATE)