Modified provider to prefetch model

This commit is contained in:
Andrew Smith 2016-03-07 09:13:20 -05:00
parent e9836100a1
commit 8e9babbc0a
3 changed files with 79 additions and 94 deletions

4
.gitignore vendored
View File

@ -1,3 +1,7 @@
## Emacs ##
*~
\#*\#
*.gem
*.rbc
/.config

View File

@ -4,114 +4,95 @@ Puppet::Type.type(:qdr_listener).provide(:qdmanage) do
# should rely on environment rather fq path
commands :qdmanage => '/usr/bin/qdmanage'
def self.instances
mk_resource_methods
def initialize(value={})
super(value)
@property_flush = {}
end
def self.get_list_of_listeners
begin
listeners = json.load(execute("/usr/bin/qdmanage QUERY --type=listener"))
# parsed["name"].each do |name|
# notice("Found a name")
@listeners=JSON.load(qdmanage('QUERY','--type=listener'))
rescue Puppet::ExecutionFailure => e
@listeners = {}
end
end
def self.get_listener_properties(listener)
listener_properties = {}
listener_properties[:provider] = :qdmanage
listener_properties[:ensure] = :present
listener_properties[:name] = listener["name"]
listener_properties[:addr] = listener["addr"]
listener_properties[:port] = listener["port"]
listener_properties[:role] = listener["role"].to_s
listener_properties[:auth_peer] = listener["auth_peer"].to_s
listener_properties
end
def self.instances
listeners = []
get_list_of_listeners.each do |listener|
listeners << new( :name => listener["name"],
:ensure => :present,
:addr => listener["addr"],
:port => listener["port"],
:role => listener["role"].to_s,
:auth_peer => listener["auth_peer"].to_s)
end
listeners
end
def create
@property_flush[:ensure] = :present
end
def exists?
@property_hash[:ensure] == :present
end
def destroy
@property_flush[:ensure] = :absent
end
def self.prefetch(resources)
instances.each do |prov|
if resource = resources[prov.name]
resource.provider = prov
end
end
end
def set_listener
# TODO(ansmith) - full CRUD once supported by qdmanage
if @property_flush[:ensure] == :absent
notice("Listener destroy not supported")
return
end
begin
# TODO(ansmith) - name, addr:port uniqueness check
qdmanage('CREATE',
'--type=listener',
'--name',
resource[:name],
'addr='+resource[:addr],
'port='+resource[:port],
'role='+resource[:role].to_s)
'role='+resource[:role].to_s)
rescue Puppet::ExecutionFailure => e
false
return
end
end
def destroy
notice("Listener destroy not supported")
true
end
def exists?
begin
qdmanage('READ',
'--type=listener',
'--name',
resource[:name])
true
rescue Puppet::ExecutionFailure => e
false
end
def flush
set_listener
@property_hash = self.class.get_listener_properties(resource[:name])
end
def addr
begin
listener=JSON.load(qdmanage('READ',
'--type=listener',
'--name',
resource[:name]))
addr=listener["addr"]
rescue Puppet::ExecutionFailure => e
addr=empty
end
end
def addr=(value)
notice("Listener update address not supported")
true
end
def port
begin
listener=JSON.load(qdmanage('READ',
'--type=listener',
'--name',
resource[:name]))
port=listener["port"]
rescue Puppet::ExecutionFailure => e
port=empty
end
end
def port=(value)
notice("Listener port value update not supported")
true
end
def role
begin
listener=JSON.load(qdmanage('READ',
'--type=listener',
'--name',
resource[:name]))
role=listener["role"]
rescue Puppet::ExecutionFailure => e
role=empty
end
end
def role=(value)
notice("Listener role value update not supported")
end
def auth_peer
begin
listener=JSON.load(qdmanage('READ',
'--type=listener',
'--name',
resource[:name]))
auth_peer=listener["auth_peer"]
rescue Puppet::ExecutionFailure => e
auth_peer=empty
end
end
def auth_peer=(value)
notice("Listener auth_peer value update not supported")
true
end
end

View File

@ -3,8 +3,8 @@ Puppet::Type.newtype(:qdr_listener) do
ensurable
# this autorequire should not be hard coded
# autorequire(:service) { 'qdrouterd' }
# TODO(ansmith) - dynamic autorequire for qdrouterd service
# autorequire(:service) { 'qdrouterd' }
newparam(:name, :namevar => true) do
desc "The unique name for the listener"
end