Skip to content
This repository was archived by the owner on Nov 29, 2023. It is now read-only.

Commit f182c58

Browse files
author
Nachi Ueno
committed
Support --no-gateway option
if --no-gateway is specified, null is used for gateway value. Fixs bug 1035987 Change-Id: I6b9e00563cc2993f40de204e2c399218f00b88c4
1 parent b2b1272 commit f182c58

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎quantumclient/quantum/v2_0/subnet.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def add_known_arguments(self, parser):
6565
parser.add_argument(
6666
'--gateway', metavar='gateway',
6767
help='gateway ip of this subnet')
68+
parser.add_argument(
69+
'--no-gateway',
70+
default=False, action='store_true',
71+
help='No distribution of gateway')
6872
parser.add_argument(
6973
'--allocation_pool',
7074
action='append',
@@ -84,6 +88,13 @@ def args2body(self, parsed_args):
8488
body = {'subnet': {'cidr': parsed_args.cidr,
8589
'network_id': _network_id,
8690
'ip_version': parsed_args.ip_version, }, }
91+
92+
if parsed_args.gateway and parsed_args.no_gateway:
93+
raise exceptions.CommandError("--gateway option and "
94+
"--no-gateway option can "
95+
"not be used same time")
96+
if parsed_args.no_gateway:
97+
body['subnet'].update({'gateway_ip': None})
8798
if parsed_args.gateway:
8899
body['subnet'].update({'gateway_ip': parsed_args.gateway})
89100
if parsed_args.tenant_id:

‎quantumclient/tests/unit/test_cli20_subnet.py‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
class CLITestV20Subnet(CLITestV20Base):
3030

3131
def test_create_subnet(self):
32-
"""Create sbunet: --gateway gateway netid cidr."""
32+
"""Create subnet: --gateway gateway netid cidr."""
3333
resource = 'subnet'
3434
cmd = CreateSubnet(MyApp(sys.stdout), None)
3535
name = 'myname'
@@ -43,6 +43,39 @@ def test_create_subnet(self):
4343
_str = self._test_create_resource(resource, cmd, name, myid, args,
4444
position_names, position_values)
4545

46+
def test_create_subnet_with_no_gateway(self):
47+
"""Create subnet: --no-gateway netid cidr"""
48+
resource = 'subnet'
49+
cmd = CreateSubnet(MyApp(sys.stdout), None)
50+
name = 'myname'
51+
myid = 'myid'
52+
netid = 'netid'
53+
cidr = 'cidrvalue'
54+
args = ['--no-gateway', netid, cidr]
55+
position_names = ['ip_version', 'network_id', 'cidr', 'gateway_ip']
56+
position_values = [4, netid, cidr, None]
57+
_str = self._test_create_resource(resource, cmd, name, myid, args,
58+
position_names, position_values)
59+
60+
def test_create_subnet_with_bad_gateway_option(self):
61+
"""Create sbunet: --no-gateway netid cidr"""
62+
resource = 'subnet'
63+
cmd = CreateSubnet(MyApp(sys.stdout), None)
64+
name = 'myname'
65+
myid = 'myid'
66+
netid = 'netid'
67+
cidr = 'cidrvalue'
68+
gateway = 'gatewayvalue'
69+
args = ['--gateway', gateway, '--no-gateway', netid, cidr]
70+
position_names = ['ip_version', 'network_id', 'cidr', 'gateway_ip']
71+
position_values = [4, netid, cidr, None]
72+
try:
73+
_str = self._test_create_resource(resource, cmd, name, myid, args,
74+
position_names, position_values)
75+
except:
76+
return
77+
self.fail('No exception for bad gateway option')
78+
4679
def test_create_subnet_tenant(self):
4780
"""Create subnet: --tenant_id tenantid netid cidr."""
4881
resource = 'subnet'

0 commit comments

Comments
 (0)