
This commits changes two things related to nova_network. Adds vlan_start parameter. This parameter is neeed when the vlan being created is not the first one that is created (b/c it cannot use the vlan_start flag from nova.conf if the vlan already exists) Removes the default openstack tenant from nova::manage::network so that the vlans are automatically assigned to projects by default.
66 lines
1.6 KiB
Ruby
66 lines
1.6 KiB
Ruby
Puppet::Type.type(:nova_network).provide(:nova_manage) do
|
|
|
|
desc "Manage nova network"
|
|
|
|
optional_commands :nova_manage => 'nova-manage'
|
|
|
|
# I need to setup caching and what-not to make this lookup performance not suck
|
|
def self.instances
|
|
begin
|
|
network_list = nova_manage("network", "list")
|
|
rescue Exception => e
|
|
if e.message =~ /No networks defined/
|
|
return []
|
|
else
|
|
raise(e)
|
|
end
|
|
end
|
|
network_list.split("\n")[1..-1].collect do |net|
|
|
if net =~ /^(\S+)\s+(\S+)/
|
|
new(:name => $2 )
|
|
end
|
|
end.compact
|
|
end
|
|
|
|
def create
|
|
optional_opts = []
|
|
{
|
|
# this needs to be converted from a project name to an id
|
|
:project => '--project_id',
|
|
:dns2 => '--dns2',
|
|
:gateway => '--gateway',
|
|
:bridge => '--bridge',
|
|
:vlan_start => '--vlan'
|
|
}.each do |param, opt|
|
|
if resource[param]
|
|
optional_opts.push(opt).push(resource[param])
|
|
end
|
|
end
|
|
|
|
nova_manage('network', 'create',
|
|
"--label=#{resource[:label]}",
|
|
"--fixed_range_v4=#{resource[:name]}",
|
|
"--num_networks=#{resource[:num_networks]}",
|
|
optional_opts
|
|
)
|
|
end
|
|
|
|
def exists?
|
|
begin
|
|
network_list = nova_manage("network", "list")
|
|
return network_list.split("\n")[1..-1].detect do |n|
|
|
# TODO - this does not take the CIDR into accont. Does it matter?
|
|
n =~ /^(\S+)\s+(#{resource[:network].split('/').first})/
|
|
end
|
|
rescue
|
|
return false
|
|
end
|
|
end
|
|
|
|
|
|
def destroy
|
|
nova_manage("network", "delete", resource[:network])
|
|
end
|
|
|
|
end
|