# coding: utf-8 require 'gaptool-api' module Gaptool module API def self.client @client ||= new end def self.new GTAPI::GaptoolServer.new( ENV['GT_USER'], ENV['GT_KEY'], ENV['GT_URL'], ENV['GT_AWS_ZONE'] ) end def self.query_nodes(opts) instance = opts[:instance] role = opts[:role] environment = opts[:environment] params = opts[:params] cl = opts[:client] || client if instance puts Rainbow('Ignoring role and environment as instance is set').red \ if role || environment [cl.getonenode(instance)] elsif role && environment cl.getenvroles(role, environment, params) elsif role cl.getrolenodes(role, params) elsif environment cl.getenvnodes(environment, params) else cl.getallnodes(params) end end def self.get_host(node) "#{node['role']}-#{node['environment']}-#{node['instance']}" end end end