Puppet::Type.type(:tsam_host).provide(:ruby) do
header = ':content_type => :json, :accept => :json'
baseurl = 'https://xxx....@172.16.210.10'
host_uri = '/isam/host_records'
deploy_uri = '/pending_changes/deploy'
def exist?
ip = resource[:ip]
begin
response = RestClient.get "#{baseurl}#{host_uri}/#{ip}/hostnames",header
exit if response.code == 200
rescue Puppet::ExecutionFailure => e
exit!
end
end
def create
host = resource[:name]
ip = resource[:ip]
postdata = '{ "addr" => ip, "hostnames" => [{ host }]}'
RestClient.post "#{baseurl}#{host_uri}", postdata.to_json, header
RestClient.get "#{baseurl}#{deploy_uri}",header
end
def destroy
end
end
Puppet::Type.newtype(:tsam_host) do
desc 'Create hostname/ip mapping( hostfile ) entry on Access Manager Appliance Web Service API'
ensurable
newproperty(:ip) do
desc 'The IPV4 address of the host to be added'
end
newparam(:name, :namevar => true) do
desc 'The host name.'
end
end
Hi,
I'm on my first attempt of writing a custom type/provider and hope to learn on the process. I'm got a stumbling block and lost on what's going with this as I have defined the exist? method which apparently the usual suspect for this error.
@102:~/.puppet/modules/tsam/lib/puppet/provider/tsam_host$ puppet resource tsam_host clu02 ip='192.168.200.32' ensure=present --debug
Debug: Loaded state in 0.00 seconds
Notice: /Tsam_host[clu02]/ensure: created
Debug: Finishing transaction 23116360
Debug: Storing state
Debug: Stored state in 0.01 seconds
Error: Could not run: undefined method `ip' for Tsam_host[clu02](provider=ruby):Puppet::Type::Tsam_host::ProviderRuby
require 'rest_client'
require 'json'
Puppet::Type.type(:tsam_host).provide(:ruby) do
def exists?
baseurl = 'https://xxxx:xx...@172.16.210.10'
host_uri = '/isam/host_records'
RestClient.get("#{baseurl}#{host_uri}/" + resource[:ip] + "/hostnames",:content_type => :json, :accept => :json) {|response, request, result|
if response.code == 200
true
else
false
end
}
end
def create
baseurl = 'https://xxx:xx...@172.16.210.10'
host_uri = '/isam/host_records'
deploy_uri = '/pending_changes/deploy'
RestClient.post "#{baseurl}#{host_uri}", { 'addr' => resource[:ip], 'hostnames' => [{'name' => resource[:name] }]}.to_json,:content_type => :json, :accept => :json
RestClient.get "#{baseurl}#{deploy_uri}",:content_type => :json, :accept => :json
end
def destroy
end
end
def ip=(newip)
# Mayby like this
host = resource[:name]
postdata = {
'addr' => newip,
'hostnames' => [ host ]
}
RestClient.put("#{baseurl}#{host_uri}", postdata.to_json, header)
RestClient.get("#{baseurl}#{deploy_uri}", header)
end
def ip
# Mayby like this
result = RestClient.get("#{baseurl}#{deploy_uri}", header)
result.ip
end