make it all work correctly

This commit is contained in:
Branan Purvine-Riley 2012-05-01 15:15:05 -07:00
parent ad8dbeaceb
commit 9726119a4a
2 changed files with 7 additions and 14 deletions

View File

@ -5,22 +5,15 @@ Puppet::Type.type(:nova_floating).provide(:nova_manage) do
optional_commands :nova_manage => 'nova-manage'
def exists?
begin
# Calculate num quads to grab for prefix
mask=resource[:network].sub(/.*\/([0-9][0-9]?)/, '\1')
num_quads=32/$mask
if num_quads == 4
num_quads=3
end
prefix=resource[:network].sub(/(\.[0-9]{1,3}){#{num_quads}}(\/[0-9]{1,2})?$/, '') + "."
return nova_manage("floating", "list").match(/#{prefix}/)
rescue
return false
end
# 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}/)
end
def create
nova_manage("floating", "create", resource[:network]) if exists? == false
nova_manage("floating", "create", resource[:network])
end
def destroy

View File

@ -6,7 +6,7 @@ Puppet::Type.newtype(:nova_floating) do
newparam(:network, :namevar => true) do
desc "Network (ie, 192.168.1.0/24 or 192.168.1.128/25 etc.)"
newvalues(/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[1-9][0-9]{0,2}\/[0-9]{1,2}$/)
newvalues(/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2}$/)
end
end