Commit 4b37e7d8 authored by Stavros Sachtouris's avatar Stavros Sachtouris

Create subnets without gateway IPs

Fixes grnet/kamaki#101

The "create_subnet" library method is modified to accept empty
iterables as gateway values.

The "kamaki subnet create" CLI command is enhanced with a new
argument "--no-gateway".
parent b9e32039
......@@ -367,6 +367,7 @@ class subnet_create(_NetworkInit, OptionalOutput):
' e.g., --alloc-pool=,',
gateway=ValueArgument('Gateway IP', '--gateway'),
no_gateway=FlagArgument('Do not assign a gateway IP', '--no-gateway'),
subnet_id=ValueArgument('The id for the subnet', '--id'),
ipv6=FlagArgument('If set, IP version is set to 6, else 4', '--ipv6'),
enable_dhcp=FlagArgument('Enable dhcp (default: off)', '--with-dhcp'),
......@@ -378,10 +379,11 @@ class subnet_create(_NetworkInit, OptionalOutput):
def _run(self):
gateway = '' if self['no_gateway'] else self['gateway']
net = self.client.create_subnet(
self['network_id'], self['cidr'],
self['name'], self['allocation_pools'], self['gateway'],
self['name'], self['allocation_pools'], gateway,
self['subnet_id'], self['ipv6'], self['enable_dhcp'])
except ClientError as ce:
if ce.status in (404, 400):
......@@ -391,6 +393,11 @@ class subnet_create(_NetworkInit, OptionalOutput):
def main(self):
super(self.__class__, self)._run()
if self['gateway'] and self['no_gateway']:
raise CLIInvalidArgument('Conflicting arguments', details=[
'Arguments %s and %s cannot be used together' % (
......@@ -123,8 +123,9 @@ class NetworkClient(NetworkRestClient, Waiter):
:param name: (str) The subnet name
:param allocation_pools: (list of dicts) start/end addresses of
allocation pools: [{'start': ..., 'end': ...}, ...]
:param gateway_ip: (str)
:param subnet_id: (str)
:param gateway_ip: (str) Special cases:
None: server applies the default policy
empty iterable: no gateway IP on this subnet
:param ipv6: (bool) ip_version == 6 if true else 4 (default)
:param enable_dhcp: (bool)
......@@ -134,8 +135,8 @@ class NetworkClient(NetworkRestClient, Waiter):
subnet['name'] = name
if allocation_pools:
subnet['allocation_pools'] = allocation_pools
if gateway_ip:
subnet['gateway_ip'] = gateway_ip
if gateway_ip is not None:
subnet['gateway_ip'] = gateway_ip or None
if subnet_id:
subnet['id'] = subnet_id
if enable_dhcp not in (None, ):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment