From 65e50b4dd338a4757a2bfb883d34d803350c3aae Mon Sep 17 00:00:00 2001 From: Jhon Honce Date: Mon, 2 Feb 2015 10:40:48 -0700 Subject: Use more descriptive name in Development Project --- lib/aws_command.rb | 2 +- lib/gce_command.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/aws_command.rb b/lib/aws_command.rb index 1c3efc91c..5979b8eb6 100644 --- a/lib/aws_command.rb +++ b/lib/aws_command.rb @@ -7,7 +7,7 @@ module OpenShift module Ops class AwsCommand < Thor # WARNING: we do not currently support environments with hyphens in the name - SUPPORTED_ENVS = %w(prod stg int tint kint test jint amint tdint lint) + SUPPORTED_ENVS = %w(prod stg int tint kint test jhonce amint tdint lint) option :type, :required => true, :enum => LaunchHelper.get_aws_host_types, :desc => 'The host type of the new instances.' diff --git a/lib/gce_command.rb b/lib/gce_command.rb index 54dbf29ba..b0a84d27b 100644 --- a/lib/gce_command.rb +++ b/lib/gce_command.rb @@ -10,7 +10,7 @@ module OpenShift module Ops class GceCommand < Thor # WARNING: we do not currently support environments with hyphens in the name - SUPPORTED_ENVS = %w(prod stg int tint kint test jint amint tdint lint) + SUPPORTED_ENVS = %w(prod stg int tint kint test jhonce amint tdint lint) option :type, :required => true, :enum => LaunchHelper.get_gce_host_types, :desc => 'The host type of the new instances.' -- cgit v1.2.3 From b3507fa9b3e03f431c5de00a10137ddcf354593e Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Thu, 19 Feb 2015 15:30:26 -0500 Subject: Fixed an issue with the latest gce list. Correctly handles _meta --- lib/gce_command.rb | 12 +++++++++--- lib/gce_helper.rb | 32 +++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/gce_command.rb b/lib/gce_command.rb index b0a84d27b..b23834af5 100644 --- a/lib/gce_command.rb +++ b/lib/gce_command.rb @@ -120,14 +120,20 @@ module OpenShift ah.run_playbook("playbooks/gce/#{host_type}/terminate.yml") end + option :env, :required => false, :aliases => '-e', :enum => SUPPORTED_ENVS, + :desc => 'The environment to list.' desc "list", "Lists instances." def list() hosts = GceHelper.get_hosts() + hosts.delete_if { |h| h.env != options[:env] } unless options[:env].nil? + + fmt_str = "%34s %5s %8s %17s %7s" + puts - puts "Instances" - puts "---------" - hosts.each { |k| puts " #{k.name}" } + puts fmt_str % ['Name','Env', 'State', 'IP Address', 'Created By'] + puts fmt_str % ['----','---', '-----', '----------', '----------'] + hosts.each { |h| puts fmt_str % [h.name, h.env, h.state, h.public_ip, h.created_by ] } puts end 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) -- cgit v1.2.3 From fa3122ce4edc48f1c4f4663257a5feaa69fc8c0b Mon Sep 17 00:00:00 2001 From: Thomas Wiest Date: Mon, 23 Feb 2015 15:55:58 -0500 Subject: changed tint to twiest and added gshipley env --- lib/aws_command.rb | 2 +- lib/gce_command.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/aws_command.rb b/lib/aws_command.rb index 1205fd5f7..0c714cdb4 100644 --- a/lib/aws_command.rb +++ b/lib/aws_command.rb @@ -7,7 +7,7 @@ module OpenShift module Ops class AwsCommand < Thor # WARNING: we do not currently support environments with hyphens in the name - SUPPORTED_ENVS = %w(prod stg int tint kint test jhonce amint tdint lint) + SUPPORTED_ENVS = %w(prod stg int twiest gshipley kint test jhonce amint tdint lint) option :type, :required => true, :enum => LaunchHelper.get_aws_host_types, :desc => 'The host type of the new instances.' diff --git a/lib/gce_command.rb b/lib/gce_command.rb index b23834af5..b7ebee18e 100644 --- a/lib/gce_command.rb +++ b/lib/gce_command.rb @@ -10,7 +10,7 @@ module OpenShift module Ops class GceCommand < Thor # WARNING: we do not currently support environments with hyphens in the name - SUPPORTED_ENVS = %w(prod stg int tint kint test jhonce amint tdint lint) + SUPPORTED_ENVS = %w(prod stg int twiest gshipley kint test jhonce amint tdint lint) option :type, :required => true, :enum => LaunchHelper.get_gce_host_types, :desc => 'The host type of the new instances.' -- cgit v1.2.3