Files
puppet-nova/lib/puppet/provider/nova_network/nova.rb
Denis Egorenko 21a7a682e9 Rewrite nova_network provider with using only nova client
Currently nova_network provider uses admin tool nova-manage for
managing nova-networks, but this tool doesn't have any authentication
and doesn't provide all features of nova client. This patch avoids
problem with authentication by using nova client for managing networks.

Another goal of this patch, with using nova client, is that all
providers should use one way for authentication, based on
openstack client and openstacklib [1] But the problem is that
openstack client doesn't provide possibility to manage nova-networks.
So, this provider will be used with nova client, until nova-network
exists.

Also added new tests.

[1] blueprint use-openstackclient-in-module-resources

Change-Id: I34c88ab9601b8b0bbf77588005422620eb575d6a
2015-12-10 17:25:48 +00:00

44 lines
1.2 KiB
Ruby

require File.join(File.dirname(__FILE__), '..','..','..', 'puppet/provider/nova')
Puppet::Type.type(:nova_network).provide(:nova, :parent => Puppet::Provider::Nova) do
desc "Manage nova network"
optional_commands :nova => 'nova'
def create
optional_opts = []
{
# this needs to be converted from a project name to an id
:project => '--project_id',
:dns1 => '--dns1',
:dns2 => '--dns2',
:gateway => '--gateway',
:bridge => '--bridge',
:vlan_start => '--vlan-start',
:allowed_start => '--allowed-start',
:allowed_end => '--allowed-end',
}.each do |param, opt|
if resource[param]
optional_opts.push(opt).push(resource[param])
end
end
opts = [resource[:label], "--fixed-range-v4", resource[:name]]
auth_nova('network-create', opts + optional_opts)
end
def exists?
instances = auth_nova('network-list')
return instances.split('\n')[1..-1].detect do |n|
n =~ /(\S+)\s+(#{resource[:network]})\s+(\S+)/
end
end
def destroy
auth_nova("network-delete", resource[:network])
end
end