Skip to content

Commit 4265002

Browse files
author
Cao Xuan Hoang
committed
Add 'description' option to os subnet (pool) create/set cmd
This patch adds '--description' option to the commands. Change-Id: Ifc2828670c3c48a87a0493d98686a5babf9b2ae7 Closes-Bug: #1614458 Closes-Bug: #1614823 Partially-Implements: blueprint network-commands-options
1 parent 7e990ba commit 4265002

9 files changed

Lines changed: 169 additions & 0 deletions

File tree

doc/source/command-objects/subnet-pool.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Create subnet pool
1919
[--default-prefix-length <default-prefix-length>]
2020
[--min-prefix-length <min-prefix-length>]
2121
[--max-prefix-length <max-prefix-length>]
22+
[--description <description>]
2223
[--project <project> [--project-domain <project-domain>]]
2324
[--address-scope <address-scope>]
2425
[--default | --no-default]
@@ -38,6 +39,10 @@ Create subnet pool
3839
3940
Set subnet pool maximum prefix length
4041
42+
.. option:: --description <description>
43+
44+
Set subnet pool description
45+
4146
.. option:: --project <project>
4247
4348
Owner's project (name or ID)
@@ -125,6 +130,7 @@ Set subnet pool properties
125130
[--max-prefix-length <max-prefix-length>]
126131
[--address-scope <address-scope> | --no-address-scope]
127132
[--default | --no-default]
133+
[--description <description>]
128134
<subnet-pool>
129135
130136
.. option:: --name <name>
@@ -165,6 +171,10 @@ Set subnet pool properties
165171
166172
Set this as a non-default subnet pool
167173
174+
.. option:: --description <description>
175+
176+
Set subnet pool description
177+
168178
.. _subnet_pool_set-subnet-pool:
169179
.. describe:: <subnet-pool>
170180

doc/source/command-objects/subnet.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Create new subnet
2626
[--gateway <gateway>]
2727
[--host-route destination=<subnet>,gateway=<ip-address>]
2828
[--ip-version {4,6}]
29+
[--description <description>]
2930
[--ipv6-ra-mode {dhcpv6-stateful,dhcpv6-stateless,slaac}]
3031
[--ipv6-address-mode {dhcpv6-stateful,dhcpv6-stateless,slaac}]
3132
[--network-segment <network-segment>]
@@ -100,6 +101,10 @@ Create new subnet
100101
IP version is determined from the subnet pool and this option
101102
is ignored.
102103
104+
.. option:: --description <description>
105+
106+
Set subnet description
107+
103108
.. option:: --ipv6-ra-mode {dhcpv6-stateful,dhcpv6-stateless,slaac}
104109
105110
IPv6 RA (Router Advertisement) mode,
@@ -202,6 +207,7 @@ Set subnet properties
202207
[--host-route destination=<subnet>,gateway=<ip-address>]
203208
[--service-type <service-type>]
204209
[--name <new-name>]
210+
[--description <description>]
205211
<subnet>
206212
207213
.. option:: --allocation-pool start=<ip-address>,end=<ip-address>
@@ -243,6 +249,9 @@ Set subnet properties
243249
``network:floatingip_agent_gateway``.
244250
Must be a valid device owner value for a network port
245251
(repeat option to set multiple service types)
252+
.. option:: --description <description>
253+
254+
Set subnet description
246255
247256
.. option:: --name
248257

openstackclient/network/v2/subnet.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ def _get_attrs(client_manager, parsed_args, is_create=True):
196196
if ('service_types' in parsed_args and
197197
parsed_args.service_types is not None):
198198
attrs['service_types'] = parsed_args.service_types
199+
if parsed_args.description is not None:
200+
attrs['description'] = parsed_args.description
199201
return attrs
200202

201203

@@ -294,6 +296,11 @@ def get_parser(self, prog_name):
294296
metavar='<network>',
295297
help=_("Network this subnet belongs to (name or ID)")
296298
)
299+
parser.add_argument(
300+
'--description',
301+
metavar='<description>',
302+
help=_("Set subnet description")
303+
)
297304
_get_common_parse_arguments(parser)
298305
return parser
299306

@@ -447,6 +454,11 @@ def get_parser(self, prog_name):
447454
"'none': This subnet will not use a gateway, "
448455
"e.g.: --gateway 192.168.9.1, --gateway none.")
449456
)
457+
parser.add_argument(
458+
'--description',
459+
metavar='<description>',
460+
help=_("Set subnet description")
461+
)
450462
_get_common_parse_arguments(parser)
451463
return parser
452464

openstackclient/network/v2/subnet_pool.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ def _get_attrs(client_manager, parsed_args):
8181
).id
8282
attrs['tenant_id'] = project_id
8383

84+
if parsed_args.description is not None:
85+
attrs['description'] = parsed_args.description
86+
8487
return attrs
8588

8689

@@ -167,6 +170,11 @@ def get_parser(self, prog_name):
167170
action='store_true',
168171
help=_("Set this subnet pool as not shared"),
169172
)
173+
parser.add_argument(
174+
'--description',
175+
metavar='<description>',
176+
help=_("Set subnet pool description")
177+
)
170178
return parser
171179

172180
def take_action(self, parsed_args):
@@ -299,6 +307,11 @@ def get_parser(self, prog_name):
299307
help=_("Remove address scope associated with the subnet pool")
300308
)
301309
_add_default_options(parser)
310+
parser.add_argument(
311+
'--description',
312+
metavar='<description>',
313+
help=_("Set subnet pool description")
314+
)
302315

303316
return parser
304317

openstackclient/tests/unit/network/v2/fakes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ def create_one_subnet(attrs=None):
891891
'segment_id': None,
892892
'service_types': [],
893893
'subnetpool_id': None,
894+
'description': 'subnet-description-' + uuid.uuid4().hex,
894895
}
895896

896897
# Overwrite default attributes.
@@ -1046,6 +1047,7 @@ def create_one_subnet_pool(attrs=None):
10461047
'min_prefixlen': '8',
10471048
'default_quota': None,
10481049
'ip_version': '4',
1050+
'description': 'subnet-pool-description-' + uuid.uuid4().hex,
10491051
}
10501052

10511053
# Overwrite default attributes.

openstackclient/tests/unit/network/v2/test_subnet.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class TestCreateSubnet(TestSubnet):
110110
columns = (
111111
'allocation_pools',
112112
'cidr',
113+
'description',
113114
'dns_nameservers',
114115
'enable_dhcp',
115116
'gateway_ip',
@@ -129,6 +130,7 @@ class TestCreateSubnet(TestSubnet):
129130
data = (
130131
subnet_v2._format_allocation_pools(_subnet.allocation_pools),
131132
_subnet.cidr,
133+
_subnet.description,
132134
utils.format_list(_subnet.dns_nameservers),
133135
_subnet.enable_dhcp,
134136
_subnet.gateway_ip,
@@ -148,6 +150,7 @@ class TestCreateSubnet(TestSubnet):
148150
data_subnet_pool = (
149151
subnet_v2._format_allocation_pools(_subnet_from_pool.allocation_pools),
150152
_subnet_from_pool.cidr,
153+
_subnet_from_pool.description,
151154
utils.format_list(_subnet_from_pool.dns_nameservers),
152155
_subnet_from_pool.enable_dhcp,
153156
_subnet_from_pool.gateway_ip,
@@ -167,6 +170,7 @@ class TestCreateSubnet(TestSubnet):
167170
data_ipv6 = (
168171
subnet_v2._format_allocation_pools(_subnet_ipv6.allocation_pools),
169172
_subnet_ipv6.cidr,
173+
_subnet_ipv6.description,
170174
utils.format_list(_subnet_ipv6.dns_nameservers),
171175
_subnet_ipv6.enable_dhcp,
172176
_subnet_ipv6.gateway_ip,
@@ -427,6 +431,40 @@ def test_create_with_network_segment(self):
427431
self.assertEqual(self.columns, columns)
428432
self.assertEqual(self.data, data)
429433

434+
def test_create_with_description(self):
435+
# Mock SDK calls for this test.
436+
self.network.create_subnet = mock.Mock(return_value=self._subnet)
437+
self._network.id = self._subnet.network_id
438+
439+
arglist = [
440+
"--subnet-range", self._subnet.cidr,
441+
"--network", self._subnet.network_id,
442+
"--description", self._subnet.description,
443+
self._subnet.name,
444+
]
445+
verifylist = [
446+
('name', self._subnet.name),
447+
('description', self._subnet.description),
448+
('subnet_range', self._subnet.cidr),
449+
('network', self._subnet.network_id),
450+
('ip_version', self._subnet.ip_version),
451+
('gateway', 'auto'),
452+
453+
]
454+
455+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
456+
columns, data = self.cmd.take_action(parsed_args)
457+
458+
self.network.create_subnet.assert_called_once_with(**{
459+
'cidr': self._subnet.cidr,
460+
'ip_version': self._subnet.ip_version,
461+
'name': self._subnet.name,
462+
'network_id': self._subnet.network_id,
463+
'description': self._subnet.description,
464+
})
465+
self.assertEqual(self.columns, columns)
466+
self.assertEqual(self.data, data)
467+
430468

431469
class TestDeleteSubnet(TestSubnet):
432470

@@ -768,6 +806,30 @@ def test_append_options(self):
768806
_testsubnet, **attrs)
769807
self.assertIsNone(result)
770808

809+
def test_set_non_append_options(self):
810+
arglist = [
811+
"--description", "new_description",
812+
"--dhcp",
813+
"--gateway", self._subnet.gateway_ip,
814+
self._subnet.name,
815+
]
816+
verifylist = [
817+
('description', "new_description"),
818+
('dhcp', True),
819+
('gateway', self._subnet.gateway_ip),
820+
('subnet', self._subnet.name),
821+
]
822+
823+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
824+
result = self.cmd.take_action(parsed_args)
825+
attrs = {
826+
'enable_dhcp': True,
827+
'gateway_ip': self._subnet.gateway_ip,
828+
'description': "new_description",
829+
}
830+
self.network.update_subnet.assert_called_with(self._subnet, **attrs)
831+
self.assertIsNone(result)
832+
771833

772834
class TestShowSubnet(TestSubnet):
773835
# The subnets to be shown
@@ -776,6 +838,7 @@ class TestShowSubnet(TestSubnet):
776838
columns = (
777839
'allocation_pools',
778840
'cidr',
841+
'description',
779842
'dns_nameservers',
780843
'enable_dhcp',
781844
'gateway_ip',
@@ -795,6 +858,7 @@ class TestShowSubnet(TestSubnet):
795858
data = (
796859
subnet_v2._format_allocation_pools(_subnet.allocation_pools),
797860
_subnet.cidr,
861+
_subnet.description,
798862
utils.format_list(_subnet.dns_nameservers),
799863
_subnet.enable_dhcp,
800864
_subnet.gateway_ip,

openstackclient/tests/unit/network/v2/test_subnet_pool.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class TestCreateSubnetPool(TestSubnetPool):
5050
'address_scope_id',
5151
'default_prefixlen',
5252
'default_quota',
53+
'description',
5354
'id',
5455
'ip_version',
5556
'is_default',
@@ -64,6 +65,7 @@ class TestCreateSubnetPool(TestSubnetPool):
6465
_subnet_pool.address_scope_id,
6566
_subnet_pool.default_prefixlen,
6667
_subnet_pool.default_quota,
68+
_subnet_pool.description,
6769
_subnet_pool.id,
6870
_subnet_pool.ip_version,
6971
_subnet_pool.is_default,
@@ -245,6 +247,29 @@ def test_create_default_and_shared_options(self):
245247
self.assertEqual(self.columns, columns)
246248
self.assertEqual(self.data, data)
247249

250+
def test_create_with_description(self):
251+
arglist = [
252+
'--pool-prefix', '10.0.10.0/24',
253+
'--description', self._subnet_pool.description,
254+
self._subnet_pool.name,
255+
]
256+
verifylist = [
257+
('prefixes', ['10.0.10.0/24']),
258+
('description', self._subnet_pool.description),
259+
('name', self._subnet_pool.name),
260+
]
261+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
262+
263+
columns, data = (self.cmd.take_action(parsed_args))
264+
265+
self.network.create_subnet_pool.assert_called_once_with(**{
266+
'name': self._subnet_pool.name,
267+
'prefixes': ['10.0.10.0/24'],
268+
'description': self._subnet_pool.description,
269+
})
270+
self.assertEqual(self.columns, columns)
271+
self.assertEqual(self.data, data)
272+
248273

249274
class TestDeleteSubnetPool(TestSubnetPool):
250275

@@ -611,6 +636,26 @@ def test_set_no_default_conflict(self):
611636
self.assertRaises(tests_utils.ParserException, self.check_parser,
612637
self.cmd, arglist, verifylist)
613638

639+
def test_set_description(self):
640+
arglist = [
641+
'--description', 'new_description',
642+
self._subnet_pool.name,
643+
]
644+
verifylist = [
645+
('description', "new_description"),
646+
('subnet_pool', self._subnet_pool.name),
647+
]
648+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
649+
650+
result = self.cmd.take_action(parsed_args)
651+
652+
attrs = {
653+
'description': "new_description",
654+
}
655+
self.network.update_subnet_pool.assert_called_once_with(
656+
self._subnet_pool, **attrs)
657+
self.assertIsNone(result)
658+
614659

615660
class TestShowSubnetPool(TestSubnetPool):
616661

@@ -621,6 +666,7 @@ class TestShowSubnetPool(TestSubnetPool):
621666
'address_scope_id',
622667
'default_prefixlen',
623668
'default_quota',
669+
'description',
624670
'id',
625671
'ip_version',
626672
'is_default',
@@ -636,6 +682,7 @@ class TestShowSubnetPool(TestSubnetPool):
636682
_subnet_pool.address_scope_id,
637683
_subnet_pool.default_prefixlen,
638684
_subnet_pool.default_quota,
685+
_subnet_pool.description,
639686
_subnet_pool.id,
640687
_subnet_pool.ip_version,
641688
_subnet_pool.is_default,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Adds ``description`` option to ``subnet create`` and
5+
``subnet set`` commands.
6+
[Bug `1614458 <https://bugs.launchpad.net/bugs/1614458>`_]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Adds ``description`` option to ``subnet pool create``
5+
and ``subnet pool set`` commands.
6+
[Bug `1614823 <https://bugs.launchpad.net/bugs/1614823>`_]

0 commit comments

Comments
 (0)