Add 'service list' resource for senlin
This proposes a 'service-list' resource for senlin clustering service. Change-Id: Ib8da9441a99f367a83729ef6871e7ab10845d384 Signed-off-by: Yuanbin.Chen <cybing4@gmail.com>
This commit is contained in:
parent
84d44a8d24
commit
521480199c
|
@ -165,3 +165,11 @@ Helper Operations
|
|||
|
||||
.. automethod:: openstack.cluster.v1._proxy.Proxy.wait_for_delete
|
||||
.. automethod:: openstack.cluster.v1._proxy.Proxy.wait_for_status
|
||||
|
||||
|
||||
Service Operations
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. autoclass:: openstack.cluster.v1._proxy.Proxy
|
||||
|
||||
.. automethod:: openstack.cluster.v1._proxy.Proxy.services
|
||||
|
|
|
@ -22,6 +22,7 @@ from openstack.cluster.v1 import policy_type as _policy_type
|
|||
from openstack.cluster.v1 import profile as _profile
|
||||
from openstack.cluster.v1 import profile_type as _profile_type
|
||||
from openstack.cluster.v1 import receiver as _receiver
|
||||
from openstack.cluster.v1 import service as _service
|
||||
from openstack import proxy2
|
||||
from openstack import resource2
|
||||
from openstack import utils
|
||||
|
@ -1083,3 +1084,11 @@ class Proxy(proxy2.BaseProxy):
|
|||
"""
|
||||
return resource2.wait_for_delete(self._session, resource, interval,
|
||||
wait)
|
||||
|
||||
def services(self, **query):
|
||||
"""Get a generator of service.
|
||||
|
||||
:returns: A generator of objects that are of type
|
||||
:class:`~openstack.cluster.v1.service.Service`
|
||||
"""
|
||||
return self._list(_service.Service, paginated=False, **query)
|
||||
|
|
|
@ -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.
|
||||
|
||||
from openstack.cluster import cluster_service
|
||||
from openstack import resource2 as resource
|
||||
|
||||
|
||||
class Service(resource.Resource):
|
||||
resource_key = 'service'
|
||||
resources_key = 'services'
|
||||
base_path = '/services'
|
||||
service = cluster_service.ClusterService()
|
||||
|
||||
# Capabilities
|
||||
allow_list = True
|
||||
|
||||
# Properties
|
||||
#: Status of service
|
||||
status = resource.Body('status')
|
||||
#: State of service
|
||||
state = resource.Body('state')
|
||||
#: Name of service
|
||||
binary = resource.Body('binary')
|
||||
#: Disabled reason of service
|
||||
disabled_reason = resource.Body('disabled_reason')
|
||||
#: Host where service runs
|
||||
host = resource.Body('host')
|
||||
#: The timestamp the service was last updated.
|
||||
#: *Type: datetime object parsed from ISO 8601 formatted string*
|
||||
updated_at = resource.Body('updated_at')
|
|
@ -26,6 +26,7 @@ from openstack.cluster.v1 import policy_type
|
|||
from openstack.cluster.v1 import profile
|
||||
from openstack.cluster.v1 import profile_type
|
||||
from openstack.cluster.v1 import receiver
|
||||
from openstack.cluster.v1 import service
|
||||
from openstack import proxy2 as proxy_base
|
||||
from openstack.tests.unit import test_proxy_base2
|
||||
|
||||
|
@ -210,6 +211,11 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase):
|
|||
method_args=[mock_cluster, 5],
|
||||
expected_args=[5])
|
||||
|
||||
def test_services(self):
|
||||
self.verify_list(self.proxy.services,
|
||||
service.Service,
|
||||
paginated=False)
|
||||
|
||||
@mock.patch.object(proxy_base.BaseProxy, '_find')
|
||||
def test_cluster_resize(self, mock_find):
|
||||
mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER')
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
# 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
|
||||
import testtools
|
||||
|
||||
from openstack.cluster.v1 import service
|
||||
|
||||
IDENTIFIER = 'IDENTIFIER'
|
||||
EXAMPLE = {
|
||||
'binary': 'senlin-engine',
|
||||
'host': 'host1',
|
||||
'status': 'enabled',
|
||||
'state': 'up',
|
||||
'disabled_reason': None,
|
||||
'updated_at': '2016-10-10T12:46:36.000000',
|
||||
}
|
||||
|
||||
|
||||
class TestService(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestService, self).setUp()
|
||||
self.resp = mock.Mock()
|
||||
self.resp.body = None
|
||||
self.resp.json = mock.Mock(return_value=self.resp.body)
|
||||
self.sess = mock.Mock()
|
||||
self.sess.put = mock.Mock(return_value=self.resp)
|
||||
|
||||
def test_basic(self):
|
||||
sot = service.Service()
|
||||
self.assertEqual('service', sot.resource_key)
|
||||
self.assertEqual('services', sot.resources_key)
|
||||
self.assertEqual('/services', sot.base_path)
|
||||
self.assertEqual('clustering', sot.service.service_type)
|
||||
self.assertTrue(sot.allow_list)
|
||||
|
||||
def test_make_it(self):
|
||||
sot = service.Service(**EXAMPLE)
|
||||
self.assertEqual(EXAMPLE['host'], sot.host)
|
||||
self.assertEqual(EXAMPLE['binary'], sot.binary)
|
||||
self.assertEqual(EXAMPLE['status'], sot.status)
|
||||
self.assertEqual(EXAMPLE['state'], sot.state)
|
||||
self.assertEqual(EXAMPLE['disabled_reason'], sot.disabled_reason)
|
||||
self.assertEqual(EXAMPLE['updated_at'], sot.updated_at)
|
Loading…
Reference in New Issue