Skip to content

Commit

Permalink
Add --dns-nameserver, --host-route, --disable-dhcp to subnet-create
Browse files Browse the repository at this point in the history
Fixes bug 1042982

Change-Id: I71f7e54a0982ac5fd188986d902667bd3fd6b219
  • Loading branch information
amotoki committed Dec 13, 2012
1 parent 2ba519d commit 4f337d9
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 12 deletions.
38 changes: 26 additions & 12 deletions quantumclient/quantum/v2_0/subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,27 @@ def add_known_arguments(self, parser):
default=False, action='store_true',
help='No distribution of gateway')
parser.add_argument(
'--allocation-pool',
action='append',
help='Allocation pool IP addresses for this subnet: '
'start=<ip_address>,end=<ip_address> '
'can be repeated')
'--allocation-pool', metavar='start=IP_ADDR,end=IP_ADDR',
action='append', dest='allocation_pools', type=utils.str2dict,
help='Allocation pool IP addresses for this subnet '
'(This option can be repeated)')
parser.add_argument(
'--allocation_pool',
action='append',
action='append', dest='allocation_pools', type=utils.str2dict,
help=argparse.SUPPRESS)
parser.add_argument(
'--host-route', metavar='destination=CIDR,nexthop=IP_ADDR',
action='append', dest='host_routes', type=utils.str2dict,
help='Additional route (This option can be repeated)')
parser.add_argument(
'--dns-nameserver', metavar='DNS_NAMESERVER',
action='append', dest='dns_nameservers',
help='DNS name server for this subnet '
'(This option can be repeated)')
parser.add_argument(
'--disable-dhcp',
action='store_true',
help='Disable DHCP for this subnet')
parser.add_argument(
'network_id', metavar='network',
help='Network id or name this subnet belongs to')
Expand All @@ -133,12 +145,14 @@ def args2body(self, parsed_args):
body['subnet'].update({'tenant_id': parsed_args.tenant_id})
if parsed_args.name:
body['subnet'].update({'name': parsed_args.name})
ips = []
if parsed_args.allocation_pool:
for ip_spec in parsed_args.allocation_pool:
ips.append(utils.str2dict(ip_spec))
if ips:
body['subnet'].update({'allocation_pools': ips})
if parsed_args.disable_dhcp:
body['subnet'].update({'enable_dhcp': False})
if parsed_args.allocation_pools:
body['subnet']['allocation_pools'] = parsed_args.allocation_pools
if parsed_args.host_routes:
body['subnet']['host_routes'] = parsed_args.host_routes
if parsed_args.dns_nameservers:
body['subnet']['dns_nameservers'] = parsed_args.dns_nameservers

return body

Expand Down
88 changes: 88 additions & 0 deletions quantumclient/tests/unit/test_cli20_subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,94 @@ def test_create_subnet_allocation_pools(self):
position_names, position_values,
tenant_id='tenantid')

def test_create_subnet_host_route(self):
"""Create subnet: --tenant_id tenantid <host_route> netid cidr.
The <host_route> is
--host-route destination=172.16.1.0/24,nexthop=1.1.1.20
"""
resource = 'subnet'
cmd = CreateSubnet(MyApp(sys.stdout), None)
name = 'myname'
myid = 'myid'
netid = 'netid'
cidr = 'prefixvalue'
args = ['--tenant_id', 'tenantid',
'--host-route', 'destination=172.16.1.0/24,nexthop=1.1.1.20',
netid, cidr]
position_names = ['ip_version', 'host_routes', 'network_id',
'cidr']
route = [{'destination': '172.16.1.0/24', 'nexthop': '1.1.1.20'}]
position_values = [4, route, netid, cidr]
_str = self._test_create_resource(resource, cmd, name, myid, args,
position_names, position_values,
tenant_id='tenantid')

def test_create_subnet_host_routes(self):
"""Create subnet: --tenant-id tenantid <host_routes> netid cidr.
The <host_routes> are
--host-route destination=172.16.1.0/24,nexthop=1.1.1.20 and
--host-route destination=172.17.7.0/24,nexthop=1.1.1.40
"""
resource = 'subnet'
cmd = CreateSubnet(MyApp(sys.stdout), None)
name = 'myname'
myid = 'myid'
netid = 'netid'
cidr = 'prefixvalue'
args = ['--tenant_id', 'tenantid',
'--host-route', 'destination=172.16.1.0/24,nexthop=1.1.1.20',
'--host-route', 'destination=172.17.7.0/24,nexthop=1.1.1.40',
netid, cidr]
position_names = ['ip_version', 'host_routes', 'network_id',
'cidr']
routes = [{'destination': '172.16.1.0/24', 'nexthop': '1.1.1.20'},
{'destination': '172.17.7.0/24', 'nexthop': '1.1.1.40'}]
position_values = [4, routes, netid, cidr]
_str = self._test_create_resource(resource, cmd, name, myid, args,
position_names, position_values,
tenant_id='tenantid')

def test_create_subnet_dns_nameservers(self):
"""Create subnet: --tenant-id tenantid <dns-nameservers> netid cidr.
The <dns-nameservers> are
--dns-nameserver 1.1.1.20 and --dns-nameserver 1.1.1.40
"""
resource = 'subnet'
cmd = CreateSubnet(MyApp(sys.stdout), None)
name = 'myname'
myid = 'myid'
netid = 'netid'
cidr = 'prefixvalue'
args = ['--tenant_id', 'tenantid',
'--dns-nameserver', '1.1.1.20',
'--dns-nameserver', '1.1.1.40',
netid, cidr]
position_names = ['ip_version', 'dns_nameservers', 'network_id',
'cidr']
nameservers = ['1.1.1.20', '1.1.1.40']
position_values = [4, nameservers, netid, cidr]
_str = self._test_create_resource(resource, cmd, name, myid, args,
position_names, position_values,
tenant_id='tenantid')

def test_create_subnet_with_disable_dhcp(self):
"""Create subnet: --tenant-id tenantid --disable-dhcp netid cidr."""
resource = 'subnet'
cmd = CreateSubnet(MyApp(sys.stdout), None)
name = 'myname'
myid = 'myid'
netid = 'netid'
cidr = 'prefixvalue'
args = ['--tenant_id', 'tenantid',
'--disable-dhcp',
netid, cidr]
position_names = ['ip_version', 'enable_dhcp', 'network_id',
'cidr']
position_values = [4, False, netid, cidr]
_str = self._test_create_resource(resource, cmd, name, myid, args,
position_names, position_values,
tenant_id='tenantid')

def test_list_subnets_detail(self):
"""List subnets: -D."""
resources = "subnets"
Expand Down

0 comments on commit 4f337d9

Please sign in to comment.