diff options
author | Matt Woodson <mwoodson@redhat.com> | 2015-02-24 10:16:20 -0500 |
---|---|---|
committer | Matt Woodson <mwoodson@redhat.com> | 2015-02-24 10:16:20 -0500 |
commit | 41ad58a9b9cd59eb5d8bece20d0c1073190d67b4 (patch) | |
tree | 7f11cf6a031a5c8b0efe9618c7ec3476c39fcbb8 /lib/gce_helper.rb | |
parent | f780d4fa01a1e8b1559d31a7065715317a884ec4 (diff) | |
parent | 0d0b7fa2bba160e8d04ba0f67a0de5c7a06499db (diff) | |
download | openshift-41ad58a9b9cd59eb5d8bece20d0c1073190d67b4.tar.gz openshift-41ad58a9b9cd59eb5d8bece20d0c1073190d67b4.tar.bz2 openshift-41ad58a9b9cd59eb5d8bece20d0c1073190d67b4.tar.xz openshift-41ad58a9b9cd59eb5d8bece20d0c1073190d67b4.zip |
Merge branch 'master' into tower_install
Conflicts:
lib/aws_command.rb
Diffstat (limited to 'lib/gce_helper.rb')
-rw-r--r-- | lib/gce_helper.rb | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/lib/gce_helper.rb b/lib/gce_helper.rb index 2ff716ce1..19fa00020 100644 --- a/lib/gce_helper.rb +++ b/lib/gce_helper.rb @@ -5,23 +5,41 @@ module OpenShift class GceHelper MYDIR = File.expand_path(File.dirname(__FILE__)) - def self.get_hosts() + def self.get_list() cmd = "#{MYDIR}/../inventory/gce/gce.py --list" hosts = %x[#{cmd} 2>&1] raise "Error: failed to list hosts\n#{hosts}" unless $?.exitstatus == 0 - # 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 } + return JSON.parse(hosts) + end + + def self.get_tag(tags, selector) + tags.each do |tag| + return $1 if tag =~ selector end - # For now, we only care about the name. In the future, we may want the other metadata included. + return nil + end + + def self.get_hosts() + hosts = get_list() + retval = [] - data.keys.sort.each { |k| retval << OpenStruct.new({ :name => k }) } + hosts['_meta']['hostvars'].each do |host, info| + retval << OpenStruct.new({ + :name => info['gce_name'], + :env => get_tag(info['gce_tags'], /^env-(\w+)$/) || 'UNSET', + :public_ip => info['gce_public_ip'], + :state => info['gce_status'], + :created_by => get_tag(info['gce_tags'], /^created-by-(\w+)$/) || 'UNSET', + }) + end + + retval.sort_by! { |h| [h.env, h.state, h.name] } return retval + end def self.get_host_details(host) |