summaryrefslogtreecommitdiffstats
path: root/lib/gce_helper.rb
diff options
context:
space:
mode:
authorThomas Wiest <twiest@redhat.com>2014-10-21 14:24:54 -0400
committerThomas Wiest <twiest@redhat.com>2014-10-21 14:24:54 -0400
commit441d6e258a20248a73fb5b5b69e71bf43afb6037 (patch)
treea9ced1359a76b50513b62fcf1b94088cc7b28447 /lib/gce_helper.rb
parentc80a333791e92e3441a96bff2c504288e020029b (diff)
downloadopenshift-441d6e258a20248a73fb5b5b69e71bf43afb6037.tar.gz
openshift-441d6e258a20248a73fb5b5b69e71bf43afb6037.tar.bz2
openshift-441d6e258a20248a73fb5b5b69e71bf43afb6037.tar.xz
openshift-441d6e258a20248a73fb5b5b69e71bf43afb6037.zip
broke out parts of cloud.rb into libs for easier maintenance.
Diffstat (limited to 'lib/gce_helper.rb')
-rwxr-xr-xlib/gce_helper.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/gce_helper.rb b/lib/gce_helper.rb
new file mode 100755
index 000000000..6c0f57cf3
--- /dev/null
+++ b/lib/gce_helper.rb
@@ -0,0 +1,64 @@
+module OpenShift
+ module Ops
+ class GceHelper
+ MYDIR = File.expand_path(File.dirname(__FILE__))
+
+ def self.list_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)
+ end
+
+ def self.get_host_details(host)
+ cmd = "#{MYDIR}/../inventory/gce/gce.py --host #{host}"
+ details = %x[#{cmd} 2>&1]
+
+ raise "Error: failed to get host details\n#{details}" unless $?.exitstatus == 0
+
+ retval = JSON.parse(details)
+
+ raise "Error: host not found [#{host}]" if retval.empty?
+
+ # Convert OpenShift specific tags to entries
+ retval['gce_tags'].each do |tag|
+ if tag =~ /\Ahost-type-([\w\d-]+)\z/
+ retval['host-type'] = $1
+ end
+
+ if tag =~ /\Aenv-([\w\d]+)\z/
+ retval['env'] = $1
+ end
+ end
+
+ return retval
+ end
+
+ def self.generate_env_tag(env)
+ return "env-#{env}"
+ end
+
+ def self.generate_env_tag_name(env)
+ return "tag_#{generate_env_tag(env)}"
+ end
+
+ def self.generate_host_type_tag(host_type)
+ return "host-type-#{host_type}"
+ end
+
+ def self.generate_host_type_tag_name(host_type)
+ return "tag_#{generate_host_type_tag(host_type)}"
+ end
+
+ def self.generate_env_host_type_tag(env, host_type)
+ return "env-host-type-#{env}-#{host_type}"
+ end
+
+ def self.generate_env_host_type_tag_name(env, host_type)
+ return "tag_#{generate_env_host_type_tag(env, host_type)}"
+ end
+ end
+ end
+end