Skip to content

Commit

Permalink
Added '' as a valid value for gateway_ip
Browse files Browse the repository at this point in the history
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
  • Loading branch information
claytono committed May 26, 2014
1 parent 66c436b commit d202e4b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
21 changes: 17 additions & 4 deletions lib/puppet/provider/neutron_subnet/neutron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def self.instances
:id => attrs['id'],
:cidr => attrs['cidr'],
:ip_version => attrs['ip_version'],
:gateway_ip => attrs['gateway_ip'],
:gateway_ip => parse_gateway_ip(attrs['gateway_ip']),
:allocation_pools => parse_allocation_pool(attrs['allocation_pools']),
:host_routes => parse_host_routes(attrs['host_routes']),
:dns_nameservers => parse_dns_nameservers(attrs['dns_nameservers']),
Expand All @@ -48,6 +48,11 @@ def self.prefetch(resources)
end
end

def self.parse_gateway_ip(value)
return '' if value.nil?
return value
end

def self.parse_allocation_pool(values)
allocation_pools = []
return [] if values.empty?
Expand Down Expand Up @@ -89,7 +94,11 @@ def create
end

if @resource[:gateway_ip]
opts << "--gateway-ip=#{@resource[:gateway_ip]}"
if @resource[:gateway_ip] == ''
opts << '--no-gateway'
else
opts << "--gateway-ip=#{@resource[:gateway_ip]}"
end
end

if @resource[:enable_dhcp]
Expand Down Expand Up @@ -139,7 +148,7 @@ def create
:id => attrs['id'],
:cidr => attrs['cidr'],
:ip_version => attrs['ip_version'],
:gateway_ip => attrs['gateway_ip'],
:gateway_ip => self.class.parse_gateway_ip(attrs['gateway_ip']),
:allocation_pools => self.class.parse_allocation_pool(attrs['allocation_pools']),
:host_routes => self.class.parse_host_routes(attrs['host_routes']),
:dns_nameservers => self.class.parse_dns_nameservers(attrs['dns_nameservers']),
Expand All @@ -158,7 +167,11 @@ def destroy
end

def gateway_ip=(value)
auth_neutron('subnet-update', "--gateway-ip=#{value}", name)
if value == ''
auth_neutron('subnet-update', '--no-gateway', name)
else
auth_neutron('subnet-update', "--gateway-ip=#{value}", name)
end
end

def enable_dhcp=(value)
Expand Down
5 changes: 4 additions & 1 deletion lib/puppet/type/neutron_subnet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
end

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

newproperty(:enable_dhcp) do
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/provider/neutron_subnet/neutron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
provider.gateway_ip=('10.0.0.2')
end

it 'should call subnet-update to remove gateway_ip with empty string' do
provider.expects(:auth_neutron).with('subnet-update',
'--no-gateway',
subnet_name)
provider.gateway_ip=('')
end

it 'should call subnet-update to change enable_dhcp' do
provider.expects(:auth_neutron).with('subnet-update',
'--enable-dhcp=True',
Expand Down

0 comments on commit d202e4b

Please sign in to comment.