Return back nova floating IP range support
This patch: a88bc1906a
was missed by mistake in adapt of nova module,
which broke deployment with nova network.
So, we should move back this provider as addition
to adapt nova module.
Add noop test coverage for this resource.
Closes-bug: #1472529
TODO (iberezovskiy): rework this change using
one of the following ways:
1. Get rid of usage of custom ruby-openstack and
ruby-netaddr packages and propose
this patch to upstream module
2. Move floating ip range support out of nova module
3. Merge new functions to nova_floating provider
and use it in deployment
(also with proposed patch to upstream)
Change-Id: Ie1f48b9bb58b8ab205ee1b7eabe9fc4787aa8011
This commit is contained in:
parent
5013a66357
commit
6f78b4214f
|
@ -1,23 +1,86 @@
|
|||
Puppet::Type.type(:nova_floating).provide(:nova_manage) do
|
||||
# Return back nova floating IP range support
|
||||
# commit a88bc1906a6670c672d145508a1aa516682db28b
|
||||
# TODO (iberezovskiy): rework this change using one of the following ways:
|
||||
# 1. Get rid of usage of custom ruby-openstack and ruby-netaddr packages and propose
|
||||
# this patch to upstream module
|
||||
# 2. Move floating ip range support out of nova module
|
||||
# 3. Merge new functions to nova_floating provider and use it in deployment
|
||||
# (also with proposed patch to upstream)
|
||||
|
||||
desc "Manage nova floating"
|
||||
require 'openstack'
|
||||
require 'netaddr'
|
||||
|
||||
Puppet::Type.type(:nova_floating_range).provide :nova_manage do
|
||||
desc 'Manage nova floating'
|
||||
|
||||
optional_commands :nova_manage => 'nova-manage'
|
||||
|
||||
def exists?
|
||||
# Calculate num quads to grab for prefix
|
||||
mask=resource[:network].sub(/.*\/([0-9][0-9]?)/, '\1').to_i
|
||||
num_quads = 4 - mask / 8
|
||||
prefix=resource[:network].sub(/(\.[0-9]{1,3}){#{num_quads}}(\/[0-9]{1,2})?$/, '') + "."
|
||||
return nova_manage("floating", "list").match(/#{prefix}/)
|
||||
@resource[:ensure] = 'present' unless @resource[:ensure]
|
||||
|
||||
if @resource[:ensure] == :absent
|
||||
operate_range.any?
|
||||
else
|
||||
operate_range.empty?
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
nova_manage("floating", "create", resource[:network])
|
||||
mixed_range.each do |ip|
|
||||
connect.create_floating_ips_bulk :ip_range => ip, :pool => @resource[:pool]
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
nova_manage("floating", "delete", resource[:network])
|
||||
mixed_range.each do |ip|
|
||||
nova_manage("floating", "delete", ip )
|
||||
end
|
||||
end
|
||||
|
||||
# Create range in cidr, including first and last ip
|
||||
# Nova will create this range, excluding network and broadcast IPs
|
||||
def mixed_range
|
||||
range = []
|
||||
NetAddr.merge(operate_range).each do |cidr|
|
||||
tmp_range = NetAddr::CIDR.create(cidr).enumerate
|
||||
range << tmp_range.first.to_s
|
||||
range << tmp_range.last.to_s
|
||||
end
|
||||
|
||||
range.uniq!
|
||||
|
||||
range += NetAddr.merge(operate_range).delete_if{ |part| part =~ /\/3[12]/}
|
||||
end
|
||||
|
||||
# Calculate exist IP and current range
|
||||
def operate_range
|
||||
exist_range = []
|
||||
connect.get_floating_ips_bulk.each do |element|
|
||||
exist_range << element.address
|
||||
end
|
||||
if @resource[:ensure] == :absent
|
||||
ip_range & exist_range
|
||||
else
|
||||
ip_range - exist_range
|
||||
end
|
||||
end
|
||||
|
||||
# Create array of IPs from range
|
||||
def ip_range
|
||||
ip = @resource[:name].split('-')
|
||||
ip_range = NetAddr.range NetAddr::CIDR.create(ip.first), NetAddr::CIDR.create(ip.last)
|
||||
ip_range.unshift(ip.first).push(ip.last)
|
||||
end
|
||||
|
||||
# Connect to OpenStack
|
||||
def connect
|
||||
@connect ||= OpenStack::Connection.create :username => @resource[:username],
|
||||
:api_key => @resource[:api_key],
|
||||
:auth_method => @resource[:auth_method],
|
||||
:auth_url => @resource[:auth_url],
|
||||
:authtenant_name => @resource[:authtenant_name],
|
||||
:service_type => @resource[:service_type],
|
||||
:retries => @resource[:api_retries],
|
||||
:is_debug => Puppet[:debug]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
# Return back nova floating IP range support
|
||||
# commit a88bc1906a6670c672d145508a1aa516682db28b
|
||||
# TODO (iberezovskiy): rework this change using one of the following ways:
|
||||
# 1. Get rid of usage of custom ruby-openstack and ruby-netaddr packages and propose
|
||||
# this patch to upstream module
|
||||
# 2. Move floating ip range support out of nova module
|
||||
# 3. Merge new functions to nova_floating provider and use it in deployment
|
||||
# (also with proposed patch to upstream)
|
||||
|
||||
Puppet::Type.newtype(:nova_floating_range) do
|
||||
|
||||
@doc = 'Manage creation/deletion of nova floating ip ranges.'
|
||||
|
|
|
@ -5,6 +5,12 @@ manifest = 'openstack-controller/openstack-controller.pp'
|
|||
describe manifest do
|
||||
shared_examples 'catalog' do
|
||||
|
||||
use_neutron = Noop.hiera 'use_neutron'
|
||||
primary_controller = Noop.hiera 'primary_controller'
|
||||
if !use_neutron && primary_controller
|
||||
floating_ips_range = Noop.hiera 'floating_network_range'
|
||||
access_hash = Noop.hiera_structure 'access'
|
||||
end
|
||||
service_endpoint = Noop.hiera 'service_endpoint'
|
||||
if service_endpoint
|
||||
keystone_host = service_endpoint
|
||||
|
@ -46,6 +52,22 @@ describe manifest do
|
|||
)
|
||||
end
|
||||
|
||||
if floating_ips_range && access_hash
|
||||
floating_ips_range.each do |ips_range|
|
||||
it "should configure nova floating IP range for #{ips_range}" do
|
||||
should contain_nova_floating_range(ips_range).with(
|
||||
'ensure' => 'present',
|
||||
'pool' => 'nova',
|
||||
'username' => access_hash['user'],
|
||||
'api_key' => access_hash['password'],
|
||||
'auth_method' => 'password',
|
||||
'auth_url' => "http://#{keystone_host}:5000/v2.0/",
|
||||
'api_retries' => '10',
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end # end of shared_examples
|
||||
|
||||
test_ubuntu_and_centos manifest
|
||||
|
|
Loading…
Reference in New Issue