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): ...@@ -367,6 +367,7 @@ class subnet_create(_NetworkInit, OptionalOutput):
' e.g., --alloc-pool=123.45.67.1,123.45.67.8', ' e.g., --alloc-pool=123.45.67.1,123.45.67.8',
'--alloc-pool'), '--alloc-pool'),
gateway=ValueArgument('Gateway IP', '--gateway'), 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'), subnet_id=ValueArgument('The id for the subnet', '--id'),
ipv6=FlagArgument('If set, IP version is set to 6, else 4', '--ipv6'), ipv6=FlagArgument('If set, IP version is set to 6, else 4', '--ipv6'),
enable_dhcp=FlagArgument('Enable dhcp (default: off)', '--with-dhcp'), enable_dhcp=FlagArgument('Enable dhcp (default: off)', '--with-dhcp'),
...@@ -378,10 +379,11 @@ class subnet_create(_NetworkInit, OptionalOutput): ...@@ -378,10 +379,11 @@ class subnet_create(_NetworkInit, OptionalOutput):
@errors.Generic.all @errors.Generic.all
@errors.Cyclades.connection @errors.Cyclades.connection
def _run(self): def _run(self):
gateway = '' if self['no_gateway'] else self['gateway']
try: try:
net = self.client.create_subnet( net = self.client.create_subnet(
self['network_id'], self['cidr'], 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']) self['subnet_id'], self['ipv6'], self['enable_dhcp'])
except ClientError as ce: except ClientError as ce:
if ce.status in (404, 400): if ce.status in (404, 400):
...@@ -391,6 +393,11 @@ class subnet_create(_NetworkInit, OptionalOutput): ...@@ -391,6 +393,11 @@ class subnet_create(_NetworkInit, OptionalOutput):
def main(self): def main(self):
super(self.__class__, self)._run() 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' % (
self.arguments['gateway'].lvalue,
self.arguments['no_gateway'].lvalue)])
self._run() self._run()
......
...@@ -123,8 +123,9 @@ class NetworkClient(NetworkRestClient, Waiter): ...@@ -123,8 +123,9 @@ class NetworkClient(NetworkRestClient, Waiter):
:param name: (str) The subnet name :param name: (str) The subnet name
:param allocation_pools: (list of dicts) start/end addresses of :param allocation_pools: (list of dicts) start/end addresses of
allocation pools: [{'start': ..., 'end': ...}, ...] allocation pools: [{'start': ..., 'end': ...}, ...]
:param gateway_ip: (str) :param gateway_ip: (str) Special cases:
:param subnet_id: (str) 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 ipv6: (bool) ip_version == 6 if true else 4 (default)
:param enable_dhcp: (bool) :param enable_dhcp: (bool)
""" """
...@@ -134,8 +135,8 @@ class NetworkClient(NetworkRestClient, Waiter): ...@@ -134,8 +135,8 @@ class NetworkClient(NetworkRestClient, Waiter):
subnet['name'] = name subnet['name'] = name
if allocation_pools: if allocation_pools:
subnet['allocation_pools'] = allocation_pools subnet['allocation_pools'] = allocation_pools
if gateway_ip: if gateway_ip is not None:
subnet['gateway_ip'] = gateway_ip subnet['gateway_ip'] = gateway_ip or None
if subnet_id: if subnet_id:
subnet['id'] = subnet_id subnet['id'] = subnet_id
if enable_dhcp not in (None, ): 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