From 5f9c7eb2d2ad44776d33197857dcd0afe693b5f5 Mon Sep 17 00:00:00 2001 From: Thomas Wiest Date: Wed, 22 Oct 2014 11:12:46 -0400 Subject: Added atomic aws host to cloud.rb --- lib/gce_helper.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) mode change 100755 => 100644 lib/gce_helper.rb (limited to 'lib/gce_helper.rb') diff --git a/lib/gce_helper.rb b/lib/gce_helper.rb old mode 100755 new mode 100644 index 6c0f57cf3..2ff716ce1 --- a/lib/gce_helper.rb +++ b/lib/gce_helper.rb @@ -1,15 +1,27 @@ +require 'ostruct' + module OpenShift module Ops class GceHelper MYDIR = File.expand_path(File.dirname(__FILE__)) - def self.list_hosts() + def self.get_hosts() cmd = "#{MYDIR}/../inventory/gce/gce.py --list" hosts = %x[#{cmd} 2>&1] raise "Error: failed to list hosts\n#{hosts}" unless $?.exitstatus == 0 - return JSON.parse(hosts) + # invert the hash so that it's key is the host, and values is an array of metadata + data = {} + JSON.parse(hosts).each do |key,value| + value.each { |h| (data[h] ||= []) << key } + end + + # For now, we only care about the name. In the future, we may want the other metadata included. + retval = [] + data.keys.sort.each { |k| retval << OpenStruct.new({ :name => k }) } + + return retval end def self.get_host_details(host) -- cgit v1.2.3