Merge "Add --dns-nameserver, --host-route, --disable-dhcp to subnet-create"
This commit is contained in:
@@ -98,15 +98,27 @@ class CreateSubnet(CreateCommand):
|
||||
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')
|
||||
@@ -133,12 +145,14 @@ class CreateSubnet(CreateCommand):
|
||||
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
|
||||
|
||||
|
@@ -151,6 +151,94 @@ class CLITestV20Subnet(CLITestV20Base):
|
||||
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"
|
||||
|
Reference in New Issue
Block a user