diff --git a/lib/puppet/provider/neutron_subnet/neutron.rb b/lib/puppet/provider/neutron_subnet/neutron.rb index 27a4d6620..25dfbbb2c 100644 --- a/lib/puppet/provider/neutron_subnet/neutron.rb +++ b/lib/puppet/provider/neutron_subnet/neutron.rb @@ -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']), @@ -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? @@ -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] @@ -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']), @@ -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) diff --git a/lib/puppet/type/neutron_subnet.rb b/lib/puppet/type/neutron_subnet.rb index caeb718d6..fb3736332 100644 --- a/lib/puppet/type/neutron_subnet.rb +++ b/lib/puppet/type/neutron_subnet.rb @@ -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 diff --git a/spec/unit/provider/neutron_subnet/neutron_spec.rb b/spec/unit/provider/neutron_subnet/neutron_spec.rb index ae2201d06..c2a658387 100644 --- a/spec/unit/provider/neutron_subnet/neutron_spec.rb +++ b/spec/unit/provider/neutron_subnet/neutron_spec.rb @@ -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',