Skip to content

Commit 6513cb6

Browse files
committed
Added '' as a valid value for gateway_ip
If the gateway_ip attribute on neutron_subnet is set to an empty string ('') then it will trigger removing the DHCP gateway setting from the subnet. This is equivalent to the --no-gateway flag in the CLI. Change-Id: Id4b74062d5b5b2fb335167af4e7cfcc32c4db703 (cherry picked from commit d202e4b)
1 parent 55ef5b5 commit 6513cb6

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

lib/puppet/provider/neutron_subnet/neutron.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def self.instances
2828
:id => attrs['id'],
2929
:cidr => attrs['cidr'],
3030
:ip_version => attrs['ip_version'],
31-
:gateway_ip => attrs['gateway_ip'],
31+
:gateway_ip => parse_gateway_ip(attrs['gateway_ip']),
3232
:allocation_pools => parse_allocation_pool(attrs['allocation_pools']),
3333
:host_routes => parse_host_routes(attrs['host_routes']),
3434
:dns_nameservers => parse_dns_nameservers(attrs['dns_nameservers']),
@@ -48,6 +48,11 @@ def self.prefetch(resources)
4848
end
4949
end
5050

51+
def self.parse_gateway_ip(value)
52+
return '' if value.nil?
53+
return value
54+
end
55+
5156
def self.parse_allocation_pool(values)
5257
allocation_pools = []
5358
return [] if values.empty?
@@ -89,7 +94,11 @@ def create
8994
end
9095

9196
if @resource[:gateway_ip]
92-
opts << "--gateway-ip=#{@resource[:gateway_ip]}"
97+
if @resource[:gateway_ip] == ''
98+
opts << '--no-gateway'
99+
else
100+
opts << "--gateway-ip=#{@resource[:gateway_ip]}"
101+
end
93102
end
94103

95104
if @resource[:enable_dhcp]
@@ -139,7 +148,7 @@ def create
139148
:id => attrs['id'],
140149
:cidr => attrs['cidr'],
141150
:ip_version => attrs['ip_version'],
142-
:gateway_ip => attrs['gateway_ip'],
151+
:gateway_ip => self.class.parse_gateway_ip(attrs['gateway_ip']),
143152
:allocation_pools => self.class.parse_allocation_pool(attrs['allocation_pools']),
144153
:host_routes => self.class.parse_host_routes(attrs['host_routes']),
145154
:dns_nameservers => self.class.parse_dns_nameservers(attrs['dns_nameservers']),
@@ -158,7 +167,11 @@ def destroy
158167
end
159168

160169
def gateway_ip=(value)
161-
auth_neutron('subnet-update', "--gateway-ip=#{value}", name)
170+
if value == ''
171+
auth_neutron('subnet-update', '--no-gateway', name)
172+
else
173+
auth_neutron('subnet-update', "--gateway-ip=#{value}", name)
174+
end
162175
end
163176

164177
def enable_dhcp=(value)

lib/puppet/type/neutron_subnet.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
end
3232

3333
newproperty(:gateway_ip) do
34-
desc 'The default gateway used by devices in this subnet'
34+
desc <<-EOT
35+
The default gateway provided by DHCP to devices in this subnet. If set to
36+
'' then no gateway IP address will be provided via DHCP.
37+
EOT
3538
end
3639

3740
newproperty(:enable_dhcp) do

spec/unit/provider/neutron_subnet/neutron_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
provider.gateway_ip=('10.0.0.2')
4343
end
4444

45+
it 'should call subnet-update to remove gateway_ip with empty string' do
46+
provider.expects(:auth_neutron).with('subnet-update',
47+
'--no-gateway',
48+
subnet_name)
49+
provider.gateway_ip=('')
50+
end
51+
4552
it 'should call subnet-update to change enable_dhcp' do
4653
provider.expects(:auth_neutron).with('subnet-update',
4754
'--enable-dhcp=True',

0 commit comments

Comments
 (0)