Created
May 23, 2014 12:33
-
-
Save kbarber/d532e774e141b39b4616 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 | |
# encoding: UTF-8 | |
require 'rubygems' | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
require 'pp' | |
def replace_catalog(catalog) | |
uri = URI.parse("http://localhost:8080/v3/commands") | |
http = Net::HTTP.new(uri.host, uri.port) | |
payload = { | |
"command" => "replace catalog", | |
"version" => 4, | |
"payload" => catalog, | |
}.to_json | |
pp payload | |
headers = { 'Accept' => '*/*', 'Content-Type' => 'application/json' } | |
response = http.request_post(uri.request_uri, payload, headers) | |
puts response.body | |
end | |
def random_string | |
(0...50).map { ('a'..'z').to_a[rand(26)] }.join | |
end | |
def random_resource | |
{ | |
"type" => "Class", | |
"title" => random_string, | |
"exported" => false, | |
"file" => "asdf", | |
"line" => 3, | |
"tags" => ["asdf"], | |
"parameters" => { | |
} | |
} | |
end | |
payload1 = { | |
"name" => "puppetdb1.vm", | |
"version" => "asdfasdfasdfas", | |
"transaction-uuid" => "foo", | |
"environment" => "foo", | |
"edges" => [ | |
{ | |
"source" => { | |
"type" => "Class", | |
"title" => "foo", | |
}, | |
"target" => { | |
"type" => "File", | |
"title" => "foo", | |
}, | |
"relationship" => "contains", | |
}, | |
], | |
"resources" => [ | |
{ | |
"type" => "Class", | |
"title" => "foo", | |
"exported" => false, | |
"file" => "asdf", | |
"line" => 3, | |
"tags" => ["asdf"], | |
"parameters" => { | |
}, | |
}, | |
{ | |
"type" => "File", | |
"title" => "foo", | |
"exported" => false, | |
"file" => "asdf", | |
"line" => 3, | |
"tags" => ["asdf"], | |
"parameters" => { | |
"content" => "foobarם", | |
}, | |
}, | |
] | |
} | |
puts "Populating data ..." | |
100.times do | |
payload1["resources"].push random_resource | |
end | |
#pp payload1 | |
puts "Submitting command now ..." | |
1.times do |i| | |
payload1["name"] = "node-#{i}" | |
# payload1["environment"] = random_string | |
replace_catalog(payload1) | |
sleep 0.1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment