Files
puppet-keystone/lib/puppet/provider/keystone_service/openstack.rb
Sofer Athlan-Guyot 1c2408d176 Support for services different only by type.
First, Keystone_service provider was not able to create service
different by type.  So service type computev3 and compute with name nova
could not be created.

Second, on a system with such resource it would not be able to
differentiate between the two.  Then if

   keystone_service {'nova': type => 'compute'}

was in the catalog, then the service nova/computev3 would be changed to
nova/compute.

Now you can specify:

   keystone_service {'service::type'}

or

   keystone_service {'service': type => 'type'}

It keeps a full backward compatibility.

Change-Id: I24bbcf8cbf3760fd061e2439f37864ae97ce86f6
Closes-Bug: #1508886
2015-11-05 13:47:28 +01:00

82 lines
2.1 KiB
Ruby

require 'puppet/provider/keystone'
Puppet::Type.type(:keystone_service).provide(
:openstack,
:parent => Puppet::Provider::Keystone
) do
desc "Provider to manage keystone services."
@credentials = Puppet::Provider::Openstack::CredentialsV3.new
include PuppetX::Keystone::CompositeNamevar::Helpers
def initialize(value = {})
super(value)
@property_flush = {}
end
def create
properties = [resource[:type]]
properties << '--name' << resource[:name]
if resource[:description]
properties << '--description' << resource[:description]
end
created = self.class.request('service', 'create', properties)
@property_hash[:ensure] = :present
@property_hash[:type] = resource[:type]
@property_hash[:id] = created[:id]
@property_hash[:description] = resource[:description]
end
def destroy
self.class.request('service', 'delete', @property_hash[:id])
@property_hash.clear
end
def exists?
@property_hash[:ensure] == :present
end
mk_resource_methods
def description=(value)
@property_flush[:description] = value
end
def type=(value)
@property_flush[:type] = value
end
def self.instances
list = request('service', 'list', '--long')
list.collect do |service|
new(
:name => resource_to_name(service[:type], service[:name], false),
:ensure => :present,
:type => service[:type],
:description => service[:description],
:id => service[:id]
)
end
end
def self.prefetch(resources)
prefetch_composite(resources) do |sorted_namevars|
name = sorted_namevars[0]
type = sorted_namevars[1]
resource_to_name(type, name, false)
end
end
def flush
options = []
if @property_flush && !@property_flush.empty?
options << "--description=#{resource[:description]}" if @property_flush[:description]
options << "--type=#{resource[:type]}" if @property_flush[:type]
self.class.request('service', 'set', [@property_hash[:id]] + options) unless options.empty?
@property_flush.clear
end
end
end