From c9fc9b5b8ff12218e26a71e0660f774bb3546eb3 Mon Sep 17 00:00:00 2001 From: Alessio Ababilov Date: Wed, 15 May 2013 16:45:01 +0300 Subject: [PATCH] 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 --- novaclient/base.py | 11 ++++++++--- novaclient/v1_1/certs.py | 2 +- novaclient/v1_1/coverage_ext.py | 2 +- novaclient/v1_1/fixed_ips.py | 2 +- novaclient/v1_1/floating_ip_dns.py | 4 ++-- novaclient/v1_1/hosts.py | 4 +++- novaclient/v1_1/quota_classes.py | 2 +- novaclient/v1_1/quotas.py | 2 +- novaclient/v1_1/security_group_rules.py | 2 +- novaclient/v1_1/shell.py | 2 +- tests/v1_1/test_hosts.py | 4 ++-- 11 files changed, 22 insertions(+), 15 deletions(-) diff --git a/novaclient/base.py b/novaclient/base.py index 26ca3f833..c97c104c4 100644 --- a/novaclient/base.py +++ b/novaclient/base.py @@ -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.""" diff --git a/novaclient/v1_1/certs.py b/novaclient/v1_1/certs.py index 28ff34e3f..b33d52134 100644 --- a/novaclient/v1_1/certs.py +++ b/novaclient/v1_1/certs.py @@ -29,7 +29,7 @@ class Certificate(base.Resource): len(self.data)) -class CertificateManager(base.ManagerWithFind): +class CertificateManager(base.Manager): """ Manage :class:`Certificate` resources. """ diff --git a/novaclient/v1_1/coverage_ext.py b/novaclient/v1_1/coverage_ext.py index 0eb91ee9e..92fc5a880 100644 --- a/novaclient/v1_1/coverage_ext.py +++ b/novaclient/v1_1/coverage_ext.py @@ -21,7 +21,7 @@ class Coverage(base.Resource): return "" % self.name -class CoverageManager(base.ManagerWithFind): +class CoverageManager(base.Manager): resource_class = Coverage diff --git a/novaclient/v1_1/fixed_ips.py b/novaclient/v1_1/fixed_ips.py index 8f9d46c62..fd8f3917a 100644 --- a/novaclient/v1_1/fixed_ips.py +++ b/novaclient/v1_1/fixed_ips.py @@ -27,7 +27,7 @@ class FixedIP(base.Resource): return "" % self.address -class FixedIPsManager(base.ManagerWithFind): +class FixedIPsManager(base.Manager): resource_class = FixedIP def get(self, fixed_ip): diff --git a/novaclient/v1_1/floating_ip_dns.py b/novaclient/v1_1/floating_ip_dns.py index 1c00bdeb1..e45a174e1 100644 --- a/novaclient/v1_1/floating_ip_dns.py +++ b/novaclient/v1_1/floating_ip_dns.py @@ -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): diff --git a/novaclient/v1_1/hosts.py b/novaclient/v1_1/hosts.py index cc1a48afe..8ea563780 100644 --- a/novaclient/v1_1/hosts.py +++ b/novaclient/v1_1/hosts.py @@ -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 diff --git a/novaclient/v1_1/quota_classes.py b/novaclient/v1_1/quota_classes.py index 874b50630..0b669bc2c 100644 --- a/novaclient/v1_1/quota_classes.py +++ b/novaclient/v1_1/quota_classes.py @@ -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): diff --git a/novaclient/v1_1/quotas.py b/novaclient/v1_1/quotas.py index c5ef0dfd7..c510b11ce 100644 --- a/novaclient/v1_1/quotas.py +++ b/novaclient/v1_1/quotas.py @@ -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): diff --git a/novaclient/v1_1/security_group_rules.py b/novaclient/v1_1/security_group_rules.py index 3e23a2873..cdd456a2c 100644 --- a/novaclient/v1_1/security_group_rules.py +++ b/novaclient/v1_1/security_group_rules.py @@ -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, diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index 9daea3f90..8936889ce 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -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) diff --git a/tests/v1_1/test_hosts.py b/tests/v1_1/test_hosts.py index b41108f8d..15bb3cb01 100644 --- a/tests/v1_1/test_hosts.py +++ b/tests/v1_1/test_hosts.py @@ -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]