| 1 |
require File.join(File.dirname(__FILE__), '..','..','..', 'puppet/provider/nova') |
| 2 |
|
| 3 |
Puppet::Type.type(:nova_service).provide( |
| 4 |
:openstack, |
| 5 |
:parent => Puppet::Provider::Nova |
| 6 |
) do |
| 7 |
desc <<-EOT |
| 8 |
Provider to manage nova host services |
| 9 |
EOT |
| 10 |
|
| 11 |
@credentials = Puppet::Provider::Openstack::CredentialsV3.new |
| 12 |
|
| 13 |
mk_resource_methods |
| 14 |
|
| 15 |
def self.instances |
| 16 |
hosts = {} |
| 17 |
request('compute service', 'list').collect do |host_svc| |
| 18 |
hname = host_svc[:host] |
| 19 |
if hosts[hname].nil? |
| 20 |
hosts[hname] = Hash.new {|h,k| h[k]=[]} |
| 21 |
hosts[hname][:ids] = [] |
| 22 |
hosts[hname][:service_name] = [] |
| 23 |
end |
| 24 |
hosts[hname][:ids] << host_svc[:id] |
| 25 |
hosts[hname][:service_name] << host_svc[:binary] |
| 26 |
end |
| 27 |
hosts.collect do |hname, host| |
| 28 |
new( |
| 29 |
:ensure => :present, |
| 30 |
:name => hname, |
| 31 |
:ids => host[:ids], |
| 32 |
:service_name => host[:service_name] |
| 33 |
) |
| 34 |
end |
| 35 |
end |
| 36 |
|
| 37 |
def self.prefetch(resources) |
| 38 |
instances_ = self.instances |
| 39 |
resources.keys.each do |name| |
| 40 |
if provider = instances_.find{ |instance| instance.name == name } |
| 41 |
resources[name].provider = provider |
| 42 |
end |
| 43 |
end |
| 44 |
end |
| 45 |
|
| 46 |
def exists? |
| 47 |
@property_hash[:ensure] == :present |
| 48 |
end |
| 49 |
|
| 50 |
def destroy |
| 51 |
return unless @property_hash[:ids].kind_of?(Array) |
| 52 |
svcname_id_map = @property_hash[:service_name].zip(@property_hash[:ids]) || {} |
| 53 |
svcname_id_map.each do |service_name, id| |
| 54 |
if (@resource[:service_name].empty? || |
| 55 |
(@resource[:service_name].include? service_name)) |
| 56 |
self.class.request('compute service', 'delete', id) |
| 57 |
end |
| 58 |
end |
| 59 |
@property_hash.clear |
| 60 |
end |
| 61 |
|
| 62 |
def create |
| 63 |
warning("Nova_service provider can only delete compute services because "\ |
| 64 |
"of openstackclient limitations.") |
| 65 |
end |
| 66 |
end |