diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py index e601f98e94..fdb7102bbd 100644 --- a/openstackclient/network/v2/router.py +++ b/openstackclient/network/v2/router.py @@ -139,6 +139,9 @@ def _get_attrs(client_manager, parsed_args): ips.append(ip_spec) gateway_info['external_fixed_ips'] = ips attrs['external_gateway_info'] = gateway_info + # "router set" command doesn't support setting flavor_id. + if 'flavor_id' in parsed_args and parsed_args.flavor_id is not None: + attrs['flavor_id'] = parsed_args.flavor_id return attrs @@ -399,6 +402,11 @@ class CreateRouter(command.ShowOne, common.NeutronCommandWithExtraArgs): action='store_false', help=_("Disable IPv6 NDP proxy on external gateway"), ) + parser.add_argument( + '--flavor-id', + metavar='<flavor-id>', + help=_("Associate the router to a flavor by ID"), + ) return parser diff --git a/openstackclient/tests/unit/network/v2/test_router.py b/openstackclient/tests/unit/network/v2/test_router.py index da7267af24..e4bce6bbea 100644 --- a/openstackclient/tests/unit/network/v2/test_router.py +++ b/openstackclient/tests/unit/network/v2/test_router.py @@ -379,6 +379,32 @@ class TestCreateRouter(TestRouter): def test_create_with_no_tag(self): self._test_create_with_tag(add_tags=False) + def test_create_with_flavor_id(self): + _flavor = network_fakes.create_one_network_flavor() + arglist = [ + self.new_router.name, + '--flavor-id', + _flavor.id, + ] + verifylist = [ + ('name', self.new_router.name), + ('enable', True), + ('distributed', False), + ('ha', False), + ('flavor_id', _flavor.id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + self.network.create_router.assert_called_once_with( + **{ + 'admin_state_up': True, + 'name': self.new_router.name, + 'flavor_id': _flavor.id, + } + ) + self.assertEqual(self.columns, columns) + self.assertCountEqual(self.data, data) + class TestDeleteRouter(TestRouter): # The routers to delete. diff --git a/releasenotes/notes/add-flavor-id-to-router-create-76e916e129b5b80c.yaml b/releasenotes/notes/add-flavor-id-to-router-create-76e916e129b5b80c.yaml new file mode 100644 index 0000000000..56ccf6d511 --- /dev/null +++ b/releasenotes/notes/add-flavor-id-to-router-create-76e916e129b5b80c.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Add the ``--flavor-id`` option to the ``router create`` command.