Skip to content

Commit a83f3c8

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add 'description' option to os subnet (pool) create/set cmd"
2 parents a51406d + 4265002 commit a83f3c8

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)
@@ -163,6 +168,7 @@ Set subnet pool properties
163168
[--max-prefix-length <max-prefix-length>]
164169
[--address-scope <address-scope> | --no-address-scope]
165170
[--default | --no-default]
171+
[--description <description>]
166172
<subnet-pool>
167173
168174
.. option:: --name <name>
@@ -203,6 +209,10 @@ Set subnet pool properties
203209
204210
Set this as a non-default subnet pool
205211
212+
.. option:: --description <description>
213+
214+
Set subnet pool description
215+
206216
.. _subnet_pool_set-subnet-pool:
207217
.. describe:: <subnet-pool>
208218

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,
@@ -233,6 +238,7 @@ Set subnet properties
233238
[--host-route destination=<subnet>,gateway=<ip-address>]
234239
[--service-type <service-type>]
235240
[--name <new-name>]
241+
[--description <description>]
236242
<subnet>
237243
238244
.. option:: --allocation-pool start=<ip-address>,end=<ip-address>
@@ -274,6 +280,9 @@ Set subnet properties
274280
``network:floatingip_agent_gateway``.
275281
Must be a valid device owner value for a network port
276282
(repeat option to set multiple service types)
283+
.. option:: --description <description>
284+
285+
Set subnet description
277286
278287
.. option:: --name
279288

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

@@ -496,6 +503,11 @@ def get_parser(self, prog_name):
496503
"'none': This subnet will not use a gateway, "
497504
"e.g.: --gateway 192.168.9.1, --gateway none.")
498505
)
506+
parser.add_argument(
507+
'--description',
508+
metavar='<description>',
509+
help=_("Set subnet description")
510+
)
499511
_get_common_parse_arguments(parser)
500512
return parser
501513

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):
@@ -340,6 +348,11 @@ def get_parser(self, prog_name):
340348
help=_("Remove address scope associated with the subnet pool")
341349
)
342350
_add_default_options(parser)
351+
parser.add_argument(
352+
'--description',
353+
metavar='<description>',
354+
help=_("Set subnet pool description")
355+
)
343356

344357
return parser
345358

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

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

897898
# Overwrite default attributes.
@@ -1047,6 +1048,7 @@ def create_one_subnet_pool(attrs=None):
10471048
'min_prefixlen': '8',
10481049
'default_quota': None,
10491050
'ip_version': '4',
1051+
'description': 'subnet-pool-description-' + uuid.uuid4().hex,
10501052
}
10511053

10521054
# 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

@@ -876,6 +914,30 @@ def test_append_options(self):
876914
_testsubnet, **attrs)
877915
self.assertIsNone(result)
878916

917+
def test_set_non_append_options(self):
918+
arglist = [
919+
"--description", "new_description",
920+
"--dhcp",
921+
"--gateway", self._subnet.gateway_ip,
922+
self._subnet.name,
923+
]
924+
verifylist = [
925+
('description', "new_description"),
926+
('dhcp', True),
927+
('gateway', self._subnet.gateway_ip),
928+
('subnet', self._subnet.name),
929+
]
930+
931+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
932+
result = self.cmd.take_action(parsed_args)
933+
attrs = {
934+
'enable_dhcp': True,
935+
'gateway_ip': self._subnet.gateway_ip,
936+
'description': "new_description",
937+
}
938+
self.network.update_subnet.assert_called_with(self._subnet, **attrs)
939+
self.assertIsNone(result)
940+
879941

880942
class TestShowSubnet(TestSubnet):
881943
# The subnets to be shown
@@ -884,6 +946,7 @@ class TestShowSubnet(TestSubnet):
884946
columns = (
885947
'allocation_pools',
886948
'cidr',
949+
'description',
887950
'dns_nameservers',
888951
'enable_dhcp',
889952
'gateway_ip',
@@ -903,6 +966,7 @@ class TestShowSubnet(TestSubnet):
903966
data = (
904967
subnet_v2._format_allocation_pools(_subnet.allocation_pools),
905968
_subnet.cidr,
969+
_subnet.description,
906970
utils.format_list(_subnet.dns_nameservers),
907971
_subnet.enable_dhcp,
908972
_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

@@ -749,6 +774,26 @@ def test_set_no_default_conflict(self):
749774
self.assertRaises(tests_utils.ParserException, self.check_parser,
750775
self.cmd, arglist, verifylist)
751776

777+
def test_set_description(self):
778+
arglist = [
779+
'--description', 'new_description',
780+
self._subnet_pool.name,
781+
]
782+
verifylist = [
783+
('description', "new_description"),
784+
('subnet_pool', self._subnet_pool.name),
785+
]
786+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
787+
788+
result = self.cmd.take_action(parsed_args)
789+
790+
attrs = {
791+
'description': "new_description",
792+
}
793+
self.network.update_subnet_pool.assert_called_once_with(
794+
self._subnet_pool, **attrs)
795+
self.assertIsNone(result)
796+
752797

753798
class TestShowSubnetPool(TestSubnetPool):
754799

@@ -759,6 +804,7 @@ class TestShowSubnetPool(TestSubnetPool):
759804
'address_scope_id',
760805
'default_prefixlen',
761806
'default_quota',
807+
'description',
762808
'id',
763809
'ip_version',
764810
'is_default',
@@ -774,6 +820,7 @@ class TestShowSubnetPool(TestSubnetPool):
774820
_subnet_pool.address_scope_id,
775821
_subnet_pool.default_prefixlen,
776822
_subnet_pool.default_quota,
823+
_subnet_pool.description,
777824
_subnet_pool.id,
778825
_subnet_pool.ip_version,
779826
_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)