Skip to content

Commit f8f174c

Browse files
author
Miguel Lavalle
committed
Add the flavor-id option to router create
The --flavor-id option is added to the router create command. The flavor_id attribute has been supported by the Neutron API for router POST operations since a long time ago [0]. Partial-Bug: #2020823 [0] https://review.opendev.org/c/openstack/neutron-lib/+/494289 Change-Id: If88499533a92c09e67b0827d1d64156682a3bb8e
1 parent 7dc1276 commit f8f174c

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

openstackclient/network/v2/router.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ def _get_attrs(client_manager, parsed_args):
139139
ips.append(ip_spec)
140140
gateway_info['external_fixed_ips'] = ips
141141
attrs['external_gateway_info'] = gateway_info
142+
# "router set" command doesn't support setting flavor_id.
143+
if 'flavor_id' in parsed_args and parsed_args.flavor_id is not None:
144+
attrs['flavor_id'] = parsed_args.flavor_id
142145

143146
return attrs
144147

@@ -399,6 +402,11 @@ def get_parser(self, prog_name):
399402
action='store_false',
400403
help=_("Disable IPv6 NDP proxy on external gateway"),
401404
)
405+
parser.add_argument(
406+
'--flavor-id',
407+
metavar='<flavor-id>',
408+
help=_("Associate the router to a flavor by ID"),
409+
)
402410

403411
return parser
404412

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,32 @@ def test_create_with_tags(self):
379379
def test_create_with_no_tag(self):
380380
self._test_create_with_tag(add_tags=False)
381381

382+
def test_create_with_flavor_id(self):
383+
_flavor = network_fakes.create_one_network_flavor()
384+
arglist = [
385+
self.new_router.name,
386+
'--flavor-id',
387+
_flavor.id,
388+
]
389+
verifylist = [
390+
('name', self.new_router.name),
391+
('enable', True),
392+
('distributed', False),
393+
('ha', False),
394+
('flavor_id', _flavor.id),
395+
]
396+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
397+
columns, data = self.cmd.take_action(parsed_args)
398+
self.network.create_router.assert_called_once_with(
399+
**{
400+
'admin_state_up': True,
401+
'name': self.new_router.name,
402+
'flavor_id': _flavor.id,
403+
}
404+
)
405+
self.assertEqual(self.columns, columns)
406+
self.assertCountEqual(self.data, data)
407+
382408

383409
class TestDeleteRouter(TestRouter):
384410
# The routers to delete.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
features:
3+
- |
4+
Add the ``--flavor-id`` option to the ``router create`` command.

0 commit comments

Comments
 (0)