Skip to content

Commit ab6ba38

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Subnet Pool: Add "subnet pool show" command"
2 parents 0a8137f + 3c8bb16 commit ab6ba38

6 files changed

Lines changed: 147 additions & 1 deletion

File tree

doc/source/command-objects/subnet_pool.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,19 @@ List subnet pools
3434
.. option:: --long
3535

3636
List additional fields in output
37+
38+
subnet pool show
39+
----------------
40+
41+
Show subnet pool details
42+
43+
.. program:: subnet pool show
44+
.. code:: bash
45+
46+
os subnet pool show
47+
<subnet-pool>
48+
49+
.. _subnet_pool_show-subnet-pool:
50+
.. describe:: <subnet-pool>
51+
52+
Subnet pool to show (name or ID)

openstackclient/network/v2/subnet_pool.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717
from openstackclient.common import utils
1818

1919

20+
def _get_columns(item):
21+
columns = item.keys()
22+
if 'tenant_id' in columns:
23+
columns.remove('tenant_id')
24+
columns.append('project_id')
25+
return tuple(sorted(columns))
26+
27+
28+
_formatters = {
29+
'prefixes': utils.format_list,
30+
}
31+
32+
2033
class DeleteSubnetPool(command.Command):
2134
"""Delete subnet pool"""
2235

@@ -83,3 +96,26 @@ def take_action(self, parsed_args):
8396
s, columns,
8497
formatters={},
8598
) for s in data))
99+
100+
101+
class ShowSubnetPool(command.ShowOne):
102+
"""Show subnet pool details"""
103+
104+
def get_parser(self, prog_name):
105+
parser = super(ShowSubnetPool, self).get_parser(prog_name)
106+
parser.add_argument(
107+
'subnet_pool',
108+
metavar="<subnet-pool>",
109+
help=("Subnet pool to show (name or ID)")
110+
)
111+
return parser
112+
113+
def take_action(self, parsed_args):
114+
client = self.app.client_manager.network
115+
obj = client.find_subnet_pool(
116+
parsed_args.subnet_pool,
117+
ignore_missing=False
118+
)
119+
columns = _get_columns(obj)
120+
data = utils.get_item_properties(obj, columns, formatters=_formatters)
121+
return (columns, data)

openstackclient/tests/network/v2/fakes.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,24 @@ def create_one_subnet_pool(attrs={}, methods={}):
695695
A FakeResource object faking the subnet pool
696696
"""
697697
# Set default attributes.
698+
project_id = 'project-id-' + uuid.uuid4().hex
698699
subnet_pool_attrs = {
699700
'id': 'subnet-pool-id-' + uuid.uuid4().hex,
700701
'name': 'subnet-pool-name-' + uuid.uuid4().hex,
701702
'prefixes': ['10.0.0.0/24', '10.1.0.0/24'],
702703
'default_prefixlen': 8,
703704
'address_scope_id': 'address-scope-id-' + uuid.uuid4().hex,
705+
'tenant_id': project_id,
706+
'is_default': False,
707+
'shared': False,
708+
'max_prefixlen': 32,
709+
'min_prefixlen': 8,
710+
'default_quota': None,
711+
'ip_version': 4,
712+
713+
# OpenStack SDK automatically translates project_id to tenant_id.
714+
# So we need an additional attr to simulate this behavior.
715+
'project_id': project_id,
704716
}
705717

706718
# Overwrite default attributes.
@@ -709,7 +721,9 @@ def create_one_subnet_pool(attrs={}, methods={}):
709721
# Set default methods.
710722
subnet_pool_methods = {
711723
'keys': ['id', 'name', 'prefixes', 'default_prefixlen',
712-
'address_scope_id']
724+
'address_scope_id', 'tenant_id', 'is_default',
725+
'shared', 'max_prefixlen', 'min_prefixlen',
726+
'default_quota', 'ip_version']
713727
}
714728

715729
# Overwrite default methods.

openstackclient/tests/network/v2/test_subnet_pool.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
import mock
1515

16+
from openstackclient.common import utils
1617
from openstackclient.network.v2 import subnet_pool
1718
from openstackclient.tests.network.v2 import fakes as network_fakes
19+
from openstackclient.tests import utils as tests_utils
1820

1921

2022
class TestSubnetPool(network_fakes.TestNetworkV2):
@@ -124,3 +126,76 @@ def test_subnet_pool_list_long(self):
124126
self.network.subnet_pools.assert_called_with()
125127
self.assertEqual(self.columns_long, columns)
126128
self.assertEqual(self.data_long, list(data))
129+
130+
131+
class TestShowSubnetPool(TestSubnetPool):
132+
133+
# The subnet_pool to set.
134+
_subnet_pool = network_fakes.FakeSubnetPool.create_one_subnet_pool()
135+
136+
columns = (
137+
'address_scope_id',
138+
'default_prefixlen',
139+
'default_quota',
140+
'id',
141+
'ip_version',
142+
'is_default',
143+
'max_prefixlen',
144+
'min_prefixlen',
145+
'name',
146+
'prefixes',
147+
'project_id',
148+
'shared',
149+
)
150+
151+
data = (
152+
_subnet_pool.address_scope_id,
153+
_subnet_pool.default_prefixlen,
154+
_subnet_pool.default_quota,
155+
_subnet_pool.id,
156+
_subnet_pool.ip_version,
157+
_subnet_pool.is_default,
158+
_subnet_pool.max_prefixlen,
159+
_subnet_pool.min_prefixlen,
160+
_subnet_pool.name,
161+
utils.format_list(_subnet_pool.prefixes),
162+
_subnet_pool.tenant_id,
163+
_subnet_pool.shared,
164+
)
165+
166+
def setUp(self):
167+
super(TestShowSubnetPool, self).setUp()
168+
169+
self.network.find_subnet_pool = mock.Mock(
170+
return_value=self._subnet_pool
171+
)
172+
173+
# Get the command object to test
174+
self.cmd = subnet_pool.ShowSubnetPool(self.app, self.namespace)
175+
176+
def test_show_no_options(self):
177+
arglist = []
178+
verifylist = []
179+
180+
# Missing required args should bail here
181+
self.assertRaises(tests_utils.ParserException, self.check_parser,
182+
self.cmd, arglist, verifylist)
183+
184+
def test_show_all_options(self):
185+
arglist = [
186+
self._subnet_pool.name,
187+
]
188+
verifylist = [
189+
('subnet_pool', self._subnet_pool.name),
190+
]
191+
192+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
193+
columns, data = self.cmd.take_action(parsed_args)
194+
195+
self.network.find_subnet_pool.assert_called_with(
196+
self._subnet_pool.name,
197+
ignore_missing=False
198+
)
199+
200+
self.assertEqual(self.columns, columns)
201+
self.assertEqual(self.data, data)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
features:
3+
- Add support for ``subnet pool show`` command.
4+
[Bug `1544590 <https://bugs.launchpad.net/python-openstackclient/+bug/1544590>`_]

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ openstack.network.v2 =
343343
subnet_list = openstackclient.network.v2.subnet:ListSubnet
344344
subnet_pool_delete = openstackclient.network.v2.subnet_pool:DeleteSubnetPool
345345
subnet_pool_list = openstackclient.network.v2.subnet_pool:ListSubnetPool
346+
subnet_pool_show = openstackclient.network.v2.subnet_pool:ShowSubnetPool
346347

347348
openstack.object_store.v1 =
348349
object_store_account_set = openstackclient.object.v1.account:SetAccount

0 commit comments

Comments
 (0)