Created
June 11, 2014 13:17
-
-
Save kbarber/6190c64335613111c9df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
require 'facter' | |
require 'pp' | |
facts = {} | |
Facter.to_hash.each do |k,v| | |
facts[k] = v.to_s | |
end | |
payload = { | |
"name" => "puppetdb1.vm", | |
"environment" => "foo", | |
"values" => facts, | |
} | |
def replace_facts(payload, version = :v2) | |
uri = URI.parse("http://localhost:8080/v3/commands") | |
http = Net::HTTP.new(uri.host, uri.port) | |
payload = case version | |
when :v1 | |
{ | |
"command" => "replace facts", | |
"version" => 1, | |
"payload" => payload.to_json, | |
}.to_json | |
when :v2 | |
{ | |
"command" => "replace facts", | |
"version" => 2, | |
"payload" => payload, | |
}.to_json | |
end | |
puts payload | |
headers = { 'Accept' => '*/*', 'Content-Type' => 'application/json' } | |
response = http.request_post(uri.request_uri, payload, headers) | |
puts response.body | |
end | |
1.times do |i| | |
payload["name"] = "node-#{i}" | |
payload["values"].delete("uptime_hours") | |
replace_facts(payload, :v2) | |
sleep 0.1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment