Skip to content

Commit aa5ff67

Browse files
author
Huanxuan Ao
committed
Implement "address scope list" command
This patch add a command that supports listing address scopes Change-Id: Id14757011560cacf28011ba51841a8e23b824f33 Partial-Bug: #1566269
1 parent 4cb5e0b commit aa5ff67

5 files changed

Lines changed: 98 additions & 0 deletions

File tree

doc/source/command-objects/address-scope.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,13 @@ Delete an address scope
6262
.. describe:: <address-scope>
6363
6464
Address scope to delete (name or ID)
65+
66+
address scope list
67+
------------------
68+
69+
List address scopes
70+
71+
.. program:: address scope list
72+
.. code:: bash
73+
74+
os address scope list

openstackclient/network/v2/address_scope.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,30 @@ def take_action(self, parsed_args):
113113
client = self.app.client_manager.network
114114
obj = client.find_address_scope(parsed_args.address_scope)
115115
client.delete_address_scope(obj)
116+
117+
118+
class ListAddressScope(command.Lister):
119+
"""List address scopes"""
120+
121+
def take_action(self, parsed_args):
122+
client = self.app.client_manager.network
123+
columns = (
124+
'id',
125+
'name',
126+
'ip_version',
127+
'shared',
128+
'tenant_id',
129+
)
130+
column_headers = (
131+
'ID',
132+
'Name',
133+
'IP Version',
134+
'Shared',
135+
'Project',
136+
)
137+
data = client.address_scopes()
138+
139+
return (column_headers,
140+
(utils.get_item_properties(
141+
s, columns, formatters={},
142+
) for s in data))

openstackclient/tests/network/v2/fakes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,24 @@ def create_one_address_scope(attrs=None):
107107

108108
return address_scope
109109

110+
@staticmethod
111+
def create_address_scopes(attrs=None, count=2):
112+
"""Create multiple fake address scopes.
113+
114+
:param Dictionary attrs:
115+
A dictionary with all attributes
116+
:param int count:
117+
The number of address scopes to fake
118+
:return:
119+
A list of FakeResource objects faking the address scopes
120+
"""
121+
address_scopes = []
122+
for i in range(0, count):
123+
address_scopes.append(
124+
FakeAddressScope.create_one_address_scope(attrs))
125+
126+
return address_scopes
127+
110128

111129
class FakeAvailabilityZone(object):
112130
"""Fake one or more network availability zones (AZs)."""

openstackclient/tests/network/v2/test_address_scope.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,45 @@ def test_delete(self):
193193
self.network.delete_address_scope.assert_called_once_with(
194194
self._address_scope)
195195
self.assertIsNone(result)
196+
197+
198+
class TestListAddressScope(TestAddressScope):
199+
200+
# The address scopes to list up.
201+
address_scopes = (
202+
network_fakes.FakeAddressScope.create_address_scopes(count=3))
203+
columns = (
204+
'ID',
205+
'Name',
206+
'IP Version',
207+
'Shared',
208+
'Project',
209+
)
210+
data = []
211+
for scope in address_scopes:
212+
data.append((
213+
scope.id,
214+
scope.name,
215+
scope.ip_version,
216+
scope.shared,
217+
scope.project_id,
218+
))
219+
220+
def setUp(self):
221+
super(TestListAddressScope, self).setUp()
222+
self.network.address_scopes = mock.Mock(
223+
return_value=self.address_scopes)
224+
225+
# Get the command object to test
226+
self.cmd = address_scope.ListAddressScope(self.app, self.namespace)
227+
228+
def test_address_scope_list(self):
229+
arglist = []
230+
verifylist = []
231+
232+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
233+
columns, data = self.cmd.take_action(parsed_args)
234+
235+
self.network.address_scopes.assert_called_once_with(**{})
236+
self.assertEqual(self.columns, columns)
237+
self.assertEqual(self.data, list(data))

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ openstack.image.v2 =
321321
openstack.network.v2 =
322322
address_scope_create = openstackclient.network.v2.address_scope:CreateAddressScope
323323
address_scope_delete = openstackclient.network.v2.address_scope:DeleteAddressScope
324+
address_scope_list = openstackclient.network.v2.address_scope:ListAddressScope
324325

325326
ip_floating_create = openstackclient.network.v2.floating_ip:CreateFloatingIP
326327
ip_floating_delete = openstackclient.network.v2.floating_ip:DeleteFloatingIP

0 commit comments

Comments
 (0)