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:
Alessio Ababilov 2013-05-15 16:45:01 +03:00
parent 64e43fde43
commit c9fc9b5b8f
11 changed files with 22 additions and 15 deletions

View File

@ -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."""

View File

@ -29,7 +29,7 @@ class Certificate(base.Resource):
len(self.data))
class CertificateManager(base.ManagerWithFind):
class CertificateManager(base.Manager):
"""
Manage :class:`Certificate` resources.
"""

View File

@ -21,7 +21,7 @@ class Coverage(base.Resource):
return "<Coverage: %s>" % self.name
class CoverageManager(base.ManagerWithFind):
class CoverageManager(base.Manager):
resource_class = Coverage

View File

@ -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):

View File

@ -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):

View File

@ -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

View File

@ -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):

View File

@ -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):

View File

@ -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,

View File

@ -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)

View File

@ -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]