lib/right_chimp/exec/ExecReport.rb in right_chimp-1.1.3 vs lib/right_chimp/exec/ExecReport.rb in right_chimp-2.0

- old
+ new

@@ -1,56 +1,50 @@ # # Report # # :fields is a comma seperated list of fields to report on, -# and are taken from the RestConnection Server objects directly. # -# Example: ip-address,name,href,private-ip-address,aws-id,ec2-instance-type,dns-name,locked -# +# Example: ip-address,name,href,private-ip-address,resource_uid, +# ec2-instance-type,datacenter,dns-name,locked,tag=foo module Chimp class ExecReport < Executor attr_reader :server, :fields attr_writer :server, :fields - + def info return "report on server #{fields.inspect}" end def run run_with_retry do output = [] - - # - # The API and rest_connection return very different data - # depending on the API call made (here, tag query vs. array) - # so the logic to load the server information and tags is - # messy. - # + begin - s = Server.find(@server.href) - s.settings - response = ::Tag.search_by_href(s.current_instance_href) + s=@server + Log.debug "Making API 1.5 call: client.tags" + response=Connection.client.tags.by_resource(:resource_hrefs => [@server.href]).first.tags rescue Exception => ex + raise e s = @server - response = ::Tag.search_by_href(s.href) + response = nil end - s.tags = [] unless s.tags + s.params["tags"] = [] unless s.params["tags"] response.each do |t| - s.tags += [ t['name'] ] + s.params["tags"] += [ t['name'] ] end - + @fields.split(",").each do |f| if f =~ /^tag=([^,]+)/ tag_search_string = $1 - s.tags.each do |tag| + s.params["tags"].each do |tag| output << tag if tag =~ /^#{tag_search_string}/ end else output << s.params[f] end end - + puts output.join(",") end end end end