X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;ds=sidebyside;f=3rdparty%2Fmodules%2Fkeystone%2Flib%2Fpuppet%2Fprovider%2Fkeystone_service%2Fopenstack.rb;h=4ac76469b137e4661ebd1eb4832e2357dbc06543;hb=87423ba664cd5f2bb462ebadd08b1a90d0fe1c8d;hp=54e75f5963504e21af9168e99886766894cc9432;hpb=4631045ebb77ee8622f6fa09277a50c372bcc02e;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/keystone/lib/puppet/provider/keystone_service/openstack.rb b/3rdparty/modules/keystone/lib/puppet/provider/keystone_service/openstack.rb index 54e75f596..4ac76469b 100644 --- a/3rdparty/modules/keystone/lib/puppet/provider/keystone_service/openstack.rb +++ b/3rdparty/modules/keystone/lib/puppet/provider/keystone_service/openstack.rb @@ -7,57 +7,58 @@ Puppet::Type.type(:keystone_service).provide( desc "Provider to manage keystone services." + @credentials = Puppet::Provider::Openstack::CredentialsV3.new + def initialize(value={}) super(value) @property_flush = {} end def create - properties = [] - if resource[:description] - properties << '--description' - properties << resource[:description] - end if resource[:type] - properties << '--type' - properties << resource[:type] + properties = [resource[:type]] + properties << '--name' << resource[:name] + if resource[:description] + properties << '--description' << resource[:description] + end + self.class.request('service', 'create', properties) + @property_hash[:ensure] = :present + else + raise(Puppet::Error, 'The type is mandatory for creating a keystone service') end - @instance = request('service', 'create', resource[:name], resource[:auth], properties) - end - - def exists? - ! instance(resource[:name]).empty? end def destroy - request('service', 'delete', resource[:name], resource[:auth]) + self.class.request('service', 'delete', @property_hash[:id]) + @property_hash.clear end - - def description=(value) - raise(Puppet::Error, "Updating the service is not currently supported.") + def exists? + @property_hash[:ensure] == :present end def description - instance(resource[:name])[:description] + @property_hash[:description] end - - def type=(value) - raise(Puppet::Error, "Updating the service is not currently supported.") + def description=(value) + @property_flush[:description] = value end def type - instance(resource[:name])[:type] + @property_hash[:type] end + def type=(value) + @property_flush[:type] = value + end def id - instance(resource[:name])[:id] + @property_hash[:id] end def self.instances - list = request('service', 'list', nil, nil, '--long') + list = request('service', 'list', '--long') list.collect do |service| new( :name => service[:name], @@ -69,30 +70,22 @@ Puppet::Type.type(:keystone_service).provide( end end - def instances - instances = request('service', 'list', nil, resource[:auth], '--long') - instances.collect do |service| - { - :name => service[:name], - :type => service[:type], - :description => service[:description], - :id => service[:id] - } + def self.prefetch(resources) + services = instances + resources.keys.each do |name| + if provider = services.find{ |service| service.name == name } + resources[name].provider = provider + end end end - def instance(name) - @instance ||= instances.select { |instance| instance[:name] == name }.first || {} - end - def flush options = [] - if @property_flush - # There is a --description flag for the set command, but it does not work if the value is empty - (options << '--property' << "type=#{resource[:type]}") if @property_flush[:type] - (options << '--property' << "description=#{resource[:description]}") if @property_flush[:description] - request('project', 'set', resource[:name], resource[:auth], options) unless options.empty? + 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