summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Ababilov <aababilov@griddynamics.com>2013-05-15 16:45:01 +0300
committerAlessio Ababilov <aababilov@griddynamics.com>2013-05-15 21:47:05 +0300
commitc9fc9b5b8ff12218e26a71e0660f774bb3546eb3 (patch)
treea6e4fc2fcc4a1cffb0be19d3398449aaa5a77037
parent64e43fde43e478af8dc95ccc0904dfca0d0dbe0c (diff)
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
Notes
Notes (review): Verified+2: Jenkins Approved+1: Johannes Erdfelt <johannes@erdfelt.com> Code-Review+2: Johannes Erdfelt <johannes@erdfelt.com> Code-Review+2: Kevin L. Mitchell <kevin.mitchell@rackspace.com> Submitted-by: Jenkins Submitted-at: Mon, 20 May 2013 17:16:08 +0000 Reviewed-on: https://review.openstack.org/29241 Project: openstack/python-novaclient Branch: refs/heads/master
-rw-r--r--novaclient/base.py11
-rw-r--r--novaclient/v1_1/certs.py2
-rw-r--r--novaclient/v1_1/coverage_ext.py2
-rw-r--r--novaclient/v1_1/fixed_ips.py2
-rw-r--r--novaclient/v1_1/floating_ip_dns.py4
-rw-r--r--novaclient/v1_1/hosts.py4
-rw-r--r--novaclient/v1_1/quota_classes.py2
-rw-r--r--novaclient/v1_1/quotas.py2
-rw-r--r--novaclient/v1_1/security_group_rules.py2
-rw-r--r--novaclient/v1_1/shell.py2
-rw-r--r--tests/v1_1/test_hosts.py4
11 files changed, 22 insertions, 15 deletions
diff --git a/novaclient/base.py b/novaclient/base.py
index 26ca3f8..c97c104 100644
--- a/novaclient/base.py
+++ b/novaclient/base.py
@@ -19,6 +19,7 @@
19Base utilities to build API operation managers and objects on top of. 19Base utilities to build API operation managers and objects on top of.
20""" 20"""
21 21
22import abc
22import contextlib 23import contextlib
23import hashlib 24import hashlib
24import os 25import os
@@ -167,6 +168,13 @@ class ManagerWithFind(Manager):
167 """ 168 """
168 Like a `Manager`, but with additional `find()`/`findall()` methods. 169 Like a `Manager`, but with additional `find()`/`findall()` methods.
169 """ 170 """
171
172 __metaclass__ = abc.ABCMeta
173
174 @abc.abstractmethod
175 def list(self):
176 pass
177
170 def find(self, **kwargs): 178 def find(self, **kwargs):
171 """ 179 """
172 Find a single item with attributes matching ``**kwargs``. 180 Find a single item with attributes matching ``**kwargs``.
@@ -204,9 +212,6 @@ class ManagerWithFind(Manager):
204 212
205 return found 213 return found
206 214
207 def list(self):
208 raise NotImplementedError
209
210 215
211class BootingManagerWithFind(ManagerWithFind): 216class BootingManagerWithFind(ManagerWithFind):
212 """Like a `ManagerWithFind`, but has the ability to boot servers.""" 217 """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 28ff34e..b33d521 100644
--- a/novaclient/v1_1/certs.py
+++ b/novaclient/v1_1/certs.py
@@ -29,7 +29,7 @@ class Certificate(base.Resource):
29 len(self.data)) 29 len(self.data))
30 30
31 31
32class CertificateManager(base.ManagerWithFind): 32class CertificateManager(base.Manager):
33 """ 33 """
34 Manage :class:`Certificate` resources. 34 Manage :class:`Certificate` resources.
35 """ 35 """
diff --git a/novaclient/v1_1/coverage_ext.py b/novaclient/v1_1/coverage_ext.py
index 0eb91ee..92fc5a8 100644
--- a/novaclient/v1_1/coverage_ext.py
+++ b/novaclient/v1_1/coverage_ext.py
@@ -21,7 +21,7 @@ class Coverage(base.Resource):
21 return "<Coverage: %s>" % self.name 21 return "<Coverage: %s>" % self.name
22 22
23 23
24class CoverageManager(base.ManagerWithFind): 24class CoverageManager(base.Manager):
25 25
26 resource_class = Coverage 26 resource_class = Coverage
27 27
diff --git a/novaclient/v1_1/fixed_ips.py b/novaclient/v1_1/fixed_ips.py
index 8f9d46c..fd8f391 100644
--- a/novaclient/v1_1/fixed_ips.py
+++ b/novaclient/v1_1/fixed_ips.py
@@ -27,7 +27,7 @@ class FixedIP(base.Resource):
27 return "<FixedIP: %s>" % self.address 27 return "<FixedIP: %s>" % self.address
28 28
29 29
30class FixedIPsManager(base.ManagerWithFind): 30class FixedIPsManager(base.Manager):
31 resource_class = FixedIP 31 resource_class = FixedIP
32 32
33 def get(self, fixed_ip): 33 def get(self, fixed_ip):
diff --git a/novaclient/v1_1/floating_ip_dns.py b/novaclient/v1_1/floating_ip_dns.py
index 1c00bde..e45a174 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):
47 return None 47 return None
48 48
49 49
50class FloatingIPDNSDomainManager(base.ManagerWithFind): 50class FloatingIPDNSDomainManager(base.Manager):
51 resource_class = FloatingIPDNSDomain 51 resource_class = FloatingIPDNSDomain
52 52
53 def domains(self): 53 def domains(self):
@@ -90,7 +90,7 @@ class FloatingIPDNSEntry(base.Resource):
90 return self.manager.get(self.domain, self.name) 90 return self.manager.get(self.domain, self.name)
91 91
92 92
93class FloatingIPDNSEntryManager(base.ManagerWithFind): 93class FloatingIPDNSEntryManager(base.Manager):
94 resource_class = FloatingIPDNSEntry 94 resource_class = FloatingIPDNSEntry
95 95
96 def get(self, domain, name): 96 def get(self, domain, name):
diff --git a/novaclient/v1_1/hosts.py b/novaclient/v1_1/hosts.py
index cc1a48a..8ea5637 100644
--- a/novaclient/v1_1/hosts.py
+++ b/novaclient/v1_1/hosts.py
@@ -62,8 +62,10 @@ class HostManager(base.ManagerWithFind):
62 url = '/os-hosts/%s/action' % host 62 url = '/os-hosts/%s/action' % host
63 return self.api.client.post(url, body=body) 63 return self.api.client.post(url, body=body)
64 64
65 def list_all(self, zone=None): 65 def list(self, zone=None):
66 url = '/os-hosts' 66 url = '/os-hosts'
67 if zone: 67 if zone:
68 url = '/os-hosts?zone=%s' % zone 68 url = '/os-hosts?zone=%s' % zone
69 return self._list(url, "hosts") 69 return self._list(url, "hosts")
70
71 list_all = list
diff --git a/novaclient/v1_1/quota_classes.py b/novaclient/v1_1/quota_classes.py
index 874b506..0b669bc 100644
--- a/novaclient/v1_1/quota_classes.py
+++ b/novaclient/v1_1/quota_classes.py
@@ -28,7 +28,7 @@ class QuotaClassSet(base.Resource):
28 return self.manager.update(self.class_name, *args, **kwargs) 28 return self.manager.update(self.class_name, *args, **kwargs)
29 29
30 30
31class QuotaClassSetManager(base.ManagerWithFind): 31class QuotaClassSetManager(base.Manager):
32 resource_class = QuotaClassSet 32 resource_class = QuotaClassSet
33 33
34 def get(self, class_name): 34 def get(self, class_name):
diff --git a/novaclient/v1_1/quotas.py b/novaclient/v1_1/quotas.py
index c5ef0df..c510b11 100644
--- a/novaclient/v1_1/quotas.py
+++ b/novaclient/v1_1/quotas.py
@@ -28,7 +28,7 @@ class QuotaSet(base.Resource):
28 return self.manager.update(self.tenant_id, *args, **kwargs) 28 return self.manager.update(self.tenant_id, *args, **kwargs)
29 29
30 30
31class QuotaSetManager(base.ManagerWithFind): 31class QuotaSetManager(base.Manager):
32 resource_class = QuotaSet 32 resource_class = QuotaSet
33 33
34 def get(self, tenant_id): 34 def get(self, tenant_id):
diff --git a/novaclient/v1_1/security_group_rules.py b/novaclient/v1_1/security_group_rules.py
index 3e23a28..cdd456a 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):
28 self.manager.delete(self) 28 self.manager.delete(self)
29 29
30 30
31class SecurityGroupRuleManager(base.ManagerWithFind): 31class SecurityGroupRuleManager(base.Manager):
32 resource_class = SecurityGroupRule 32 resource_class = SecurityGroupRule
33 33
34 def create(self, parent_group_id, ip_protocol=None, from_port=None, 34 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 9daea3f..8936889 100644
--- a/novaclient/v1_1/shell.py
+++ b/novaclient/v1_1/shell.py
@@ -2503,7 +2503,7 @@ def do_host_describe(cs, args):
2503def do_host_list(cs, args): 2503def do_host_list(cs, args):
2504 """List all hosts by service""" 2504 """List all hosts by service"""
2505 columns = ["host_name", "service", "zone"] 2505 columns = ["host_name", "service", "zone"]
2506 result = cs.hosts.list_all(args.zone) 2506 result = cs.hosts.list(args.zone)
2507 utils.print_list(result, columns) 2507 utils.print_list(result, columns)
2508 2508
2509 2509
diff --git a/tests/v1_1/test_hosts.py b/tests/v1_1/test_hosts.py
index b41108f..15bb3cb 100644
--- a/tests/v1_1/test_hosts.py
+++ b/tests/v1_1/test_hosts.py
@@ -14,13 +14,13 @@ class HostsTest(utils.TestCase):
14 [self.assertTrue(isinstance(h, hosts.Host)) for h in hs] 14 [self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
15 15
16 def test_list_host(self): 16 def test_list_host(self):
17 hs = cs.hosts.list_all() 17 hs = cs.hosts.list()
18 cs.assert_called('GET', '/os-hosts') 18 cs.assert_called('GET', '/os-hosts')
19 [self.assertTrue(isinstance(h, hosts.Host)) for h in hs] 19 [self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
20 [self.assertEqual(h.zone, 'nova1') for h in hs] 20 [self.assertEqual(h.zone, 'nova1') for h in hs]
21 21
22 def test_list_host_with_zone(self): 22 def test_list_host_with_zone(self):
23 hs = cs.hosts.list_all('nova') 23 hs = cs.hosts.list('nova')
24 cs.assert_called('GET', '/os-hosts?zone=nova') 24 cs.assert_called('GET', '/os-hosts?zone=nova')
25 [self.assertTrue(isinstance(h, hosts.Host)) for h in hs] 25 [self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
26 [self.assertEqual(h.zone, 'nova') for h in hs] 26 [self.assertEqual(h.zone, 'nova') for h in hs]