OSC: Add magnum service-list command
Partial-Implements: blueprint deprecate-magnum-client Partial-Implements: blueprint openstackclient-support Change-Id: I37b4ea0a519ac4d7ce47112263232ed1d200b4a2
This commit is contained in:
parent
f501b618fb
commit
fe51e61cdc
39
magnumclient/osc/v1/mservices.py
Normal file
39
magnumclient/osc/v1/mservices.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
|
||||||
|
|
||||||
|
|
||||||
|
def _get_client(obj, parsed_args):
|
||||||
|
obj.log.debug("take_action(%s)" % parsed_args)
|
||||||
|
return obj.app.client_manager.container_infra
|
||||||
|
|
||||||
|
|
||||||
|
class ListService(command.Lister):
|
||||||
|
"""Print a list of Magnum services."""
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__ + ".ListService")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ListService, self).get_parser(prog_name)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
client = _get_client(self, parsed_args)
|
||||||
|
services = client.mservices.list()
|
||||||
|
columns = ('id', 'host', 'binary', 'state', 'disabled',
|
||||||
|
'disabled_reason', 'created_at', 'updated_at')
|
||||||
|
return (columns, (utils.get_item_properties(service, columns)
|
||||||
|
for service in services))
|
@ -47,6 +47,7 @@ class MagnumFakeContainerInfra(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.cluster_templates = FakeBaseModelManager()
|
self.cluster_templates = FakeBaseModelManager()
|
||||||
self.clusters = FakeBaseModelManager()
|
self.clusters = FakeBaseModelManager()
|
||||||
|
self.mservices = FakeBaseModelManager()
|
||||||
|
|
||||||
|
|
||||||
class MagnumFakeClientManager(osc_fakes.FakeClientManager):
|
class MagnumFakeClientManager(osc_fakes.FakeClientManager):
|
||||||
|
45
magnumclient/tests/osc/unit/v1/test_mservices.py
Normal file
45
magnumclient/tests/osc/unit/v1/test_mservices.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# 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 magnumclient.osc.v1 import mservices
|
||||||
|
from magnumclient.tests.osc.unit.v1 import fakes
|
||||||
|
|
||||||
|
|
||||||
|
class TestServiceList(fakes.TestMagnumClientOSCV1):
|
||||||
|
columns = ('id', 'host', 'binary', 'state', 'disabled',
|
||||||
|
'disabled_reason', 'created_at', 'updated_at')
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestServiceList, self).setUp()
|
||||||
|
self.mservices_mock = self.app.client_manager.container_infra.mservices
|
||||||
|
self.mservices_mock.list = mock.Mock()
|
||||||
|
fake_service = mock.Mock(
|
||||||
|
Binary='magnum-conductor',
|
||||||
|
Host='Host1',
|
||||||
|
Status='enabled',
|
||||||
|
State='up',
|
||||||
|
Updated_at=None,
|
||||||
|
Disabled_Reason=None,
|
||||||
|
)
|
||||||
|
fake_service.name = 'test_service'
|
||||||
|
self.mservices_mock.list.return_value = [fake_service]
|
||||||
|
|
||||||
|
# Get the command object to test
|
||||||
|
self.cmd = mservices.ListService(self.app, None)
|
||||||
|
|
||||||
|
def test_service_list(self):
|
||||||
|
arglist = []
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
self.mservices_mock.list.assert_called_with()
|
||||||
|
self.assertEqual(self.columns, columns)
|
@ -43,6 +43,8 @@ openstack.container_infra.v1 =
|
|||||||
coe_cluster_update = magnumclient.osc.v1.clusters:UpdateCluster
|
coe_cluster_update = magnumclient.osc.v1.clusters:UpdateCluster
|
||||||
coe_cluster_config = magnumclient.osc.v1.clusters:ConfigCluster
|
coe_cluster_config = magnumclient.osc.v1.clusters:ConfigCluster
|
||||||
|
|
||||||
|
coe_service_list = magnumclient.osc.v1.mservices:ListService
|
||||||
|
|
||||||
[build_sphinx]
|
[build_sphinx]
|
||||||
source-dir = doc/source
|
source-dir = doc/source
|
||||||
build-dir = doc/build
|
build-dir = doc/build
|
||||||
|
Loading…
x
Reference in New Issue
Block a user