Add services list
This patch add senlinclient support display senlin service status Change-Id: I8ea92d425d0a0ce5913abafba5d66fdf3d09b80f Signed-off-by: Yuanbin.Chen <cybing4@gmail.com>
This commit is contained in:
parent
42dff83ce4
commit
c75cad3d68
43
senlinclient/tests/unit/v1/test_service.py
Normal file
43
senlinclient/tests/unit/v1/test_service.py
Normal file
@ -0,0 +1,43 @@
|
||||
# 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 senlinclient.tests.unit.v1 import fakes
|
||||
from senlinclient.v1 import service as osc_service
|
||||
|
||||
|
||||
class TestServiceList(fakes.TestClusteringv1):
|
||||
columns = ['Binary', 'Host', 'Status', 'State', 'Updated_at',
|
||||
'Disabled Reason']
|
||||
|
||||
def setUp(self):
|
||||
super(TestServiceList, self).setUp()
|
||||
self.mock_client = self.app.client_manager.clustering
|
||||
self.cmd = osc_service.Service(self.app, None)
|
||||
fake_service = mock.Mock(
|
||||
Binary='senlin-engine',
|
||||
Host='Host1',
|
||||
Status='enabled',
|
||||
State='up',
|
||||
Updated_at=None,
|
||||
Disabled_Reason=None,
|
||||
)
|
||||
fake_service.name = 'test_service'
|
||||
fake_service.to_dict = mock.Mock(return_value={})
|
||||
self.mock_client.get_service = mock.Mock(return_value=[fake_service])
|
||||
|
||||
def test_service(self):
|
||||
arglist = []
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.mock_client.get_service.assert_called_with()
|
||||
self.assertEqual(self.columns, columns)
|
@ -1716,3 +1716,16 @@ class ShellTest(testtools.TestCase):
|
||||
service, args)
|
||||
msg = _('Action not found: fake_id')
|
||||
self.assertEqual(msg, six.text_type(ex))
|
||||
|
||||
@mock.patch.object(utils, 'print_list')
|
||||
def test_do_service_list(self, mock_print):
|
||||
service = mock.Mock()
|
||||
fields = ['Binary', 'Host', 'Status', 'State', 'Updated_at',
|
||||
'Disabled Reason']
|
||||
|
||||
result = mock.Mock()
|
||||
service.services.return_value = result
|
||||
formatters = {}
|
||||
sh.do_service_list(service)
|
||||
mock_print.assert_called_once_with(result, fields,
|
||||
formatters=formatters)
|
||||
|
@ -433,3 +433,11 @@ class Client(object):
|
||||
http://developer.openstack.org/api-ref-clustering-v1.html#showAction
|
||||
"""
|
||||
return self.service.get_action(action)
|
||||
|
||||
def get_service(self, **queries):
|
||||
"""List service
|
||||
|
||||
Doc link:
|
||||
http://developer.openstack.org/api-ref-clustering-v1.html#showAction
|
||||
"""
|
||||
return self.service.services(**queries)
|
||||
|
39
senlinclient/v1/service.py
Normal file
39
senlinclient/v1/service.py
Normal file
@ -0,0 +1,39 @@
|
||||
# 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 osc_lib.command import command
|
||||
from osc_lib import utils
|
||||
|
||||
|
||||
class Service(command.ShowOne):
|
||||
"""Retrieve build information."""
|
||||
|
||||
log = logging.getLogger(__name__ + ".Service")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(Service, self).get_parser(prog_name)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
|
||||
senlin_client = self.app.client_manager.clustering
|
||||
queries = {}
|
||||
result = senlin_client.get_service(**queries)
|
||||
|
||||
formatters = {}
|
||||
columns = ['Binary', 'Host', 'Status', 'State', 'Updated_at',
|
||||
'Disabled Reason']
|
||||
return columns, utils.get_dict_properties(result, columns,
|
||||
formatters=formatters)
|
@ -1680,3 +1680,16 @@ def do_action_show(service, args):
|
||||
}
|
||||
|
||||
utils.print_dict(action.to_dict(), formatters=formatters)
|
||||
|
||||
|
||||
def do_service_list(service, args=None):
|
||||
"""Show a list of all running services."""
|
||||
show_deprecated('senlin service-list',
|
||||
'openstack cluster service list')
|
||||
fields = ['Binary', 'Host', 'Status', 'State', 'Updated_at',
|
||||
'Disabled Reason']
|
||||
queries = {}
|
||||
result = service.services(**queries)
|
||||
|
||||
formatters = {}
|
||||
utils.print_list(result, fields, formatters=formatters)
|
||||
|
@ -83,6 +83,7 @@ openstack.clustering.v1 =
|
||||
cluster_update = senlinclient.v1.cluster:UpdateCluster
|
||||
cluster_collect = senlinclient.v1.cluster:ClusterCollect
|
||||
cluster_run = senlinclient.v1.cluster:ClusterRun
|
||||
cluster_service = senlinclient.v1.cluster.service.Service
|
||||
|
||||
[global]
|
||||
setup-hooks =
|
||||
|
Loading…
x
Reference in New Issue
Block a user