diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py index f87f7abe1b..b98f86412c 100644 --- a/openstackclient/network/v2/subnet.py +++ b/openstackclient/network/v2/subnet.py @@ -672,6 +672,11 @@ class UnsetSubnet(command.Command): 'subnet e.g.: start=192.168.199.2,end=192.168.199.254 ' '(repeat option to unset multiple allocation pools)') ) + parser.add_argument( + '--gateway', + action='store_true', + help=_("Remove gateway IP from this subnet") + ) parser.add_argument( '--dns-nameserver', metavar='', @@ -715,6 +720,8 @@ class UnsetSubnet(command.Command): obj = client.find_subnet(parsed_args.subnet, ignore_missing=False) attrs = {} + if parsed_args.gateway: + attrs['gateway_ip'] = None if parsed_args.dns_nameservers: attrs['dns_nameservers'] = copy.deepcopy(obj.dns_nameservers) _update_arguments(attrs['dns_nameservers'], diff --git a/openstackclient/tests/unit/network/v2/test_subnet.py b/openstackclient/tests/unit/network/v2/test_subnet.py index 1b4bfdad2f..6085cda8a1 100644 --- a/openstackclient/tests/unit/network/v2/test_subnet.py +++ b/openstackclient/tests/unit/network/v2/test_subnet.py @@ -1264,6 +1264,7 @@ class TestUnsetSubnet(TestSubnet): 'end': '8.8.8.170'}], 'service_types': ['network:router_gateway', 'network:floatingip_agent_gateway'], + 'gateway_ip': 'fe80::a00a:0:c0de:0:1', 'tags': ['green', 'red'], }) self.network.find_subnet = mock.Mock(return_value=self._testsubnet) self.network.update_subnet = mock.Mock(return_value=None) @@ -1277,6 +1278,7 @@ class TestUnsetSubnet(TestSubnet): '--host-route', 'destination=10.30.30.30/24,gateway=10.30.30.1', '--allocation-pool', 'start=8.8.8.100,end=8.8.8.150', '--service-type', 'network:router_gateway', + '--gateway', self._testsubnet.name, ] verifylist = [ @@ -1286,6 +1288,7 @@ class TestUnsetSubnet(TestSubnet): ('allocation_pools', [{ 'start': '8.8.8.100', 'end': '8.8.8.150'}]), ('service_types', ['network:router_gateway']), + ('gateway', True), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -1297,6 +1300,7 @@ class TestUnsetSubnet(TestSubnet): "destination": "10.20.20.0/24", "nexthop": "10.20.20.1"}], 'allocation_pools': [{'start': '8.8.8.160', 'end': '8.8.8.170'}], 'service_types': ['network:floatingip_agent_gateway'], + 'gateway_ip': None, } self.network.update_subnet.assert_called_once_with( self._testsubnet, **attrs) diff --git a/releasenotes/notes/subnet-unset-gateway-20239d5910e10778.yaml b/releasenotes/notes/subnet-unset-gateway-20239d5910e10778.yaml new file mode 100644 index 0000000000..55be3e4a34 --- /dev/null +++ b/releasenotes/notes/subnet-unset-gateway-20239d5910e10778.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + Add missing ``openstack subnet unset --gateway ``.