Make ManagerWithFind abstract and fix its descendants
ManagerWithFind requires list() method in its descendants. Make it abstract and fix its improper descendants that do not implement list() (SecurityGroupRuleManager and many others). Fixes: bug #1180393 Change-Id: Ic8b466a57554018092c31c6d6b3ea62f181d7000
This commit is contained in:
parent
64e43fde43
commit
c9fc9b5b8f
@ -19,6 +19,7 @@
|
||||
Base utilities to build API operation managers and objects on top of.
|
||||
"""
|
||||
|
||||
import abc
|
||||
import contextlib
|
||||
import hashlib
|
||||
import os
|
||||
@ -167,6 +168,13 @@ class ManagerWithFind(Manager):
|
||||
"""
|
||||
Like a `Manager`, but with additional `find()`/`findall()` methods.
|
||||
"""
|
||||
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
||||
@abc.abstractmethod
|
||||
def list(self):
|
||||
pass
|
||||
|
||||
def find(self, **kwargs):
|
||||
"""
|
||||
Find a single item with attributes matching ``**kwargs``.
|
||||
@ -204,9 +212,6 @@ class ManagerWithFind(Manager):
|
||||
|
||||
return found
|
||||
|
||||
def list(self):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class BootingManagerWithFind(ManagerWithFind):
|
||||
"""Like a `ManagerWithFind`, but has the ability to boot servers."""
|
||||
|
@ -29,7 +29,7 @@ class Certificate(base.Resource):
|
||||
len(self.data))
|
||||
|
||||
|
||||
class CertificateManager(base.ManagerWithFind):
|
||||
class CertificateManager(base.Manager):
|
||||
"""
|
||||
Manage :class:`Certificate` resources.
|
||||
"""
|
||||
|
@ -21,7 +21,7 @@ class Coverage(base.Resource):
|
||||
return "<Coverage: %s>" % self.name
|
||||
|
||||
|
||||
class CoverageManager(base.ManagerWithFind):
|
||||
class CoverageManager(base.Manager):
|
||||
|
||||
resource_class = Coverage
|
||||
|
||||
|
@ -27,7 +27,7 @@ class FixedIP(base.Resource):
|
||||
return "<FixedIP: %s>" % self.address
|
||||
|
||||
|
||||
class FixedIPsManager(base.ManagerWithFind):
|
||||
class FixedIPsManager(base.Manager):
|
||||
resource_class = FixedIP
|
||||
|
||||
def get(self, fixed_ip):
|
||||
|
@ -47,7 +47,7 @@ class FloatingIPDNSDomain(base.Resource):
|
||||
return None
|
||||
|
||||
|
||||
class FloatingIPDNSDomainManager(base.ManagerWithFind):
|
||||
class FloatingIPDNSDomainManager(base.Manager):
|
||||
resource_class = FloatingIPDNSDomain
|
||||
|
||||
def domains(self):
|
||||
@ -90,7 +90,7 @@ class FloatingIPDNSEntry(base.Resource):
|
||||
return self.manager.get(self.domain, self.name)
|
||||
|
||||
|
||||
class FloatingIPDNSEntryManager(base.ManagerWithFind):
|
||||
class FloatingIPDNSEntryManager(base.Manager):
|
||||
resource_class = FloatingIPDNSEntry
|
||||
|
||||
def get(self, domain, name):
|
||||
|
@ -62,8 +62,10 @@ class HostManager(base.ManagerWithFind):
|
||||
url = '/os-hosts/%s/action' % host
|
||||
return self.api.client.post(url, body=body)
|
||||
|
||||
def list_all(self, zone=None):
|
||||
def list(self, zone=None):
|
||||
url = '/os-hosts'
|
||||
if zone:
|
||||
url = '/os-hosts?zone=%s' % zone
|
||||
return self._list(url, "hosts")
|
||||
|
||||
list_all = list
|
||||
|
@ -28,7 +28,7 @@ class QuotaClassSet(base.Resource):
|
||||
return self.manager.update(self.class_name, *args, **kwargs)
|
||||
|
||||
|
||||
class QuotaClassSetManager(base.ManagerWithFind):
|
||||
class QuotaClassSetManager(base.Manager):
|
||||
resource_class = QuotaClassSet
|
||||
|
||||
def get(self, class_name):
|
||||
|
@ -28,7 +28,7 @@ class QuotaSet(base.Resource):
|
||||
return self.manager.update(self.tenant_id, *args, **kwargs)
|
||||
|
||||
|
||||
class QuotaSetManager(base.ManagerWithFind):
|
||||
class QuotaSetManager(base.Manager):
|
||||
resource_class = QuotaSet
|
||||
|
||||
def get(self, tenant_id):
|
||||
|
@ -28,7 +28,7 @@ class SecurityGroupRule(base.Resource):
|
||||
self.manager.delete(self)
|
||||
|
||||
|
||||
class SecurityGroupRuleManager(base.ManagerWithFind):
|
||||
class SecurityGroupRuleManager(base.Manager):
|
||||
resource_class = SecurityGroupRule
|
||||
|
||||
def create(self, parent_group_id, ip_protocol=None, from_port=None,
|
||||
|
@ -2503,7 +2503,7 @@ def do_host_describe(cs, args):
|
||||
def do_host_list(cs, args):
|
||||
"""List all hosts by service"""
|
||||
columns = ["host_name", "service", "zone"]
|
||||
result = cs.hosts.list_all(args.zone)
|
||||
result = cs.hosts.list(args.zone)
|
||||
utils.print_list(result, columns)
|
||||
|
||||
|
||||
|
@ -14,13 +14,13 @@ class HostsTest(utils.TestCase):
|
||||
[self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
|
||||
|
||||
def test_list_host(self):
|
||||
hs = cs.hosts.list_all()
|
||||
hs = cs.hosts.list()
|
||||
cs.assert_called('GET', '/os-hosts')
|
||||
[self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
|
||||
[self.assertEqual(h.zone, 'nova1') for h in hs]
|
||||
|
||||
def test_list_host_with_zone(self):
|
||||
hs = cs.hosts.list_all('nova')
|
||||
hs = cs.hosts.list('nova')
|
||||
cs.assert_called('GET', '/os-hosts?zone=nova')
|
||||
[self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
|
||||
[self.assertEqual(h.zone, 'nova') for h in hs]
|
||||
|
Loading…
x
Reference in New Issue
Block a user