Refactor of nova_manage native type

This commit refactors the nova_manage native type.

Removes the available ips parameter b/c by default,
nova-manage will calculate this based off the
CIDR and num_networks.

Adds the following params:
  - num_networks - specifies the number of networks
to split the network into.
  - project - project to associate the network with.
  - gateway - gateway to use for network.
  - dns2 - secondary dns address

Updates the create method to use options instead of
arguments.


Update nova::manage::network to include additional
parameters num_networks and project.
This commit is contained in:
Dan Bode 2012-05-05 23:55:44 -07:00
parent f6c5ccb896
commit 574c80e19d
3 changed files with 62 additions and 19 deletions

View File

@ -22,6 +22,28 @@ Puppet::Type.type(:nova_network).provide(:nova_manage) do
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'
}.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")
@ -34,15 +56,9 @@ Puppet::Type.type(:nova_network).provide(:nova_manage) do
end
end
def create
mask=resource[:network].sub(/.*\/([1-3][0-9]?)/, '\1')
available_ips=2**(32-mask.to_i)
nova_manage("network", "create", resource[:label], resource[:network], "1", available_ips, "--bridge=#{resource[:bridge]}")
end
def destroy
nova_manage("network", "delete", resource[:network])
end
end

View File

@ -9,7 +9,7 @@ Puppet::Type.newtype(:nova_network) do
# segments b/c it is actually the combination of network/prefix
# that determine uniqueness
newparam(:network, :namevar => true) do
desc "Network (ie, 192.168.1.0/24)"
desc "IPv4 Network (ie, 192.168.1.0/24)"
newvalues(/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.0\/[0-9]{1,2}$/)
end
@ -18,17 +18,30 @@ Puppet::Type.newtype(:nova_network) do
defaultto "novanetwork"
end
newparam(:available_ips) do
desc "# of available IPs. Must be greater than 4."
validate do |value|
if value.to_i < 4
raise Puppet::Error, "ERROR - nova_network: Parameter available_ips must be an integer greater than 4."
end
end
newparam(:num_networks) do
desc 'Number of networks to create'
defaultto(1)
end
newparam(:bridge) do
defaultto 'br100'
desc 'bridge to use for flat network'
end
newparam(:project) do
desc 'project that the network is associated with'
end
# we are not currently using this stuff
newparam(:gateway) do
end
newparam(:dns2) do
end
validate do
raise(Puppet::Error, 'Label must be set') unless self[:label]
end
end

View File

@ -1,11 +1,25 @@
define nova::manage::network ( $network ) {
#
# ==Parameters
# [network] ipv4 CIDR of network to create. Required.
# [num_networks] Number of networks to split $network into. Optional
# Defaults to 1.
# [project] Project that network should be associated with.
#
define nova::manage::network (
$network,
$num_networks = 1,
$project = 'openstack'
) {
File['/etc/nova/nova.conf'] -> Nova_network[$name]
Exec<| title == 'initial-db-sync' |> -> Nova_network[$name]
nova_network { $name:
ensure => present,
network => $network,
notify => Exec["nova-db-sync"],
ensure => present,
network => $network,
num_networks => $num_networks,
project => $project,
notify => Exec['nova-db-sync'],
}
}