Skip to content

Commit

Permalink
more work on #45, need to get the pson conversion down
Browse files Browse the repository at this point in the history
  • Loading branch information
chorankates committed Aug 29, 2013
1 parent 075f150 commit 2a1ee85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/rouster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Rouster
# custom exceptions -- what else do we want them to include/do?
class FileTransferError < StandardError; end # thrown by get() and put()
class InternalError < StandardError; end # thrown by most (if not all) Rouster methods
class ExternalError < StandardError; end # thrown when external dependencies do not respond as expected
class LocalExecutionError < StandardError; end # thrown by _run()
class RemoteExecutionError < StandardError; end # thrown by run()
class SSHConnectionError < StandardError; end # thrown by available_via_ssh() -- and potentially _run()
Expand Down
16 changes: 9 additions & 7 deletions lib/rouster/puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'json'
require 'net/https'
require 'socket'
require 'uri'

class Rouster

Expand All @@ -26,22 +27,23 @@ def facter(cache=true, custom_facts=true)
res
end

def get_catalog(hostname=nil, puppetmaster=nil, facts=nil)
def get_catalog(hostname=nil, puppetmaster=nil, facts=nil, puppetmaster_port=8140)
# post https://<puppetmaster>/catalog/<node>?facts_format=pson&facts=<pson URL encoded> == ht to patrick@puppetlabs
certname = hostname.nil? ? self.run('hostname --fqdn').chomp : hostname
puppetmaster = puppetmaster.nil? ? 'puppet' : puppetmaster
facts = facts.nil? ? self.facter() : facts # TODO check for presence of certain 'required' facts?

facts.to_pson # this does not work, but needs to

json = nil
url = sprintf('https://%s/catalog/%s?facts_format=pson&facts=%s', puppetmaster, certname, facts)

res = self.run(sprintf('puppet catalog find %s', certname))
url = sprintf('https://%s:%s/catalog/%s?facts_format=pson&facts=%s', puppetmaster, puppetmaster_port, certname, facts)
uri = URI.parse(url)

begin
json = JSON.parse(res)
rescue
raise InternalError.new(sprintf('unable to parse[%s] as JSON', res))
res = Net::HTTP.get(uri)
json = res.to_json
rescue => e
raise ExternalError.new("calling[#{url}] led to exception[#{e}")
end

json
Expand Down

0 comments on commit 2a1ee85

Please sign in to comment.