
Use Hash values instead of Array values to avoid unnecessary conversion between actual value type and internal data type. This allows us to avoid potential issues caused by tricky parsing or conversion. Note that this could not be backword compatible and users have to update their manifests to adopt to this change. Change-Id: Id4a32752eb1073c6467d089bc97c8271741feba0
104 lines
2.7 KiB
Ruby
104 lines
2.7 KiB
Ruby
require File.join(File.dirname(__FILE__), '..','..','..', 'puppet/provider/cinder')
|
|
|
|
Puppet::Type.type(:cinder_qos).provide(
|
|
:openstack,
|
|
:parent => Puppet::Provider::Cinder
|
|
) do
|
|
|
|
desc 'Provider for cinder QOS.'
|
|
|
|
@credentials = Puppet::Provider::Openstack::CredentialsV3.new
|
|
|
|
mk_resource_methods
|
|
|
|
def create
|
|
properties = []
|
|
unless resource[:consumer].empty?
|
|
properties << '--consumer' << resource[:consumer]
|
|
end
|
|
if resource[:properties]
|
|
resource[:properties].each do |k, v|
|
|
properties << '--property' << "#{k}=#{v}"
|
|
end
|
|
end
|
|
properties << name
|
|
self.class.request('volume qos', 'create', properties)
|
|
@property_hash[:ensure] = :present
|
|
@property_hash[:properties] = resource[:properties]
|
|
@property_hash[:consumer] = resource[:consumer]
|
|
@property_hash[:name] = name
|
|
unless resource[:associations].empty?
|
|
resource[:associations].each do |item|
|
|
self.class.request('volume qos', 'associate', [name, item])
|
|
end
|
|
@property_hash[:associations] = resource[:associations]
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
self.class.request('volume qos', 'delete', name)
|
|
@property_hash.clear
|
|
end
|
|
|
|
def exists?
|
|
@property_hash[:ensure] == :present
|
|
end
|
|
|
|
def properties=(value)
|
|
added = []
|
|
@property_hash[:properties].each do |k, v|
|
|
if value[k] != v
|
|
added << '--property' << "#{k}=#{value[k]}"
|
|
end
|
|
end
|
|
unless added.empty?
|
|
self.class.request('volume type', 'set', [properties, added])
|
|
@property_hash[:properties] = value
|
|
end
|
|
end
|
|
|
|
def associations=(value)
|
|
added = value - @property_hash[:associations]
|
|
removed = @property_hash[:associations] - value
|
|
added.each do |item|
|
|
self.class.request('volume qos', 'associate', [name, item])
|
|
end
|
|
removed.each do |item|
|
|
self.class.request('volume qos', 'disassociate', [name, item])
|
|
end
|
|
@property_hash[:associations] = value
|
|
end
|
|
|
|
def self.instances
|
|
list = request('volume qos', 'list')
|
|
list.collect do |qos|
|
|
properties = qos[:properties]
|
|
new({
|
|
:name => qos[:name],
|
|
:ensure => :present,
|
|
:id => qos[:id],
|
|
:properties => pythondict2hash(properties),
|
|
:consumer => qos[:consumer],
|
|
:associations => string2array(qos[:associations])
|
|
})
|
|
end
|
|
end
|
|
|
|
def self.prefetch(resources)
|
|
qoss = instances
|
|
resources.keys.each do |name|
|
|
if provider = qoss.find{ |qos| qos.name == name }
|
|
resources[name].provider = provider
|
|
end
|
|
end
|
|
end
|
|
|
|
def self.string2array(input)
|
|
return input.delete("'").split(/,\s/)
|
|
end
|
|
|
|
def self.pythondict2hash(input)
|
|
return JSON.parse(input.gsub(/'/, '"'))
|
|
end
|
|
end
|