Class: CloudInfo
- Inherits:
-
Object
- Object
- CloudInfo
- Defined in:
- lib/cloud_info.rb,
lib/cloud_info/cli.rb,
lib/cloud_info/version.rb,
lib/cloud_info/instances.rb
Overview
usage: require “cloud_info” irb(main):003:0> cloud_info = CloudInfo.new(“prod”,:private_key => “~/.ssh/id_rsa-private-key”) irb(main):005:0> pp cloud_info.apps [[“prod_app0”, “xxx.xxx.xxx.xxx”],
["prod_app1", "xxx.xxx.xxx.xxx"],
["prod_app2", "xxx.xxx.xxx.xxx"],
["prod_app3", "xxx.xxx.xxx.xxx"]]
Defined Under Namespace
Constant Summary collapse
- Version =
"0.1.6"
Instance Attribute Summary collapse
-
#env_name ⇒ Object
readonly
Returns the value of attribute env_name.
Class Method Summary collapse
Instance Method Summary collapse
- #app_master ⇒ Object
- #apps ⇒ Object
- #djs ⇒ Object
-
#hosts ⇒ Object
if a cache exist it uses it instead of finding the servers.
-
#initialize(env_name, options = {}) ⇒ CloudInfo
constructor
A new instance of CloudInfo.
- #utils ⇒ Object
Constructor Details
#initialize(env_name, options = {}) ⇒ CloudInfo
Returns a new instance of CloudInfo.
19 20 21 22 23 |
# File 'lib/cloud_info.rb', line 19 def initialize(env_name, = {}) @env_name = env_name @options = @cache_path = [:cache_path] || 'config/cloud_info.yml' end |
Instance Attribute Details
#env_name ⇒ Object (readonly)
Returns the value of attribute env_name.
18 19 20 |
# File 'lib/cloud_info.rb', line 18 def env_name @env_name end |
Class Method Details
.all_hosts(options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/cloud_info.rb', line 61 def self.all_hosts( = {}) all_hosts = {} environments = Instances.ey_environments environments.each do |env| info = CloudInfo.new(env, ) hosts = info.hosts # pp env # pp hosts all_hosts.merge!(hosts) end all_hosts end |
.read_yaml(path) ⇒ Object
79 80 81 |
# File 'lib/cloud_info.rb', line 79 def self.read_yaml(path) YAML.load(IO.read(path)) end |
.write_yaml(path, hosts) ⇒ Object
74 75 76 77 78 |
# File 'lib/cloud_info.rb', line 74 def self.write_yaml(path, hosts) File.open(path, 'w') do |out| out.write(hosts.to_yaml) end end |
Instance Method Details
#app_master ⇒ Object
51 52 53 |
# File 'lib/cloud_info.rb', line 51 def app_master apps[0][1] end |
#apps ⇒ Object
48 49 50 |
# File 'lib/cloud_info.rb', line 48 def apps apps = hosts.select{|k,v| k =~ Regexp.new("#{@env_name}_app")}.sort {|a,b| a[0] <=> b[0] } end |
#djs ⇒ Object
57 58 59 |
# File 'lib/cloud_info.rb', line 57 def djs utils = hosts.select{|k,v| k =~ Regexp.new("#{@env_name}_dj")}.sort {|a,b| a[0] <=> b[0] } end |
#hosts ⇒ Object
if a cache exist it uses it instead of finding the servers
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cloud_info.rb', line 26 def hosts use_cache = @options[:use_cache] # check yaml file first if use_cache and File.exist?(@cache_path) @hosts = (CloudInfo.read_yaml(@cache_path) || {})[env_name] end unless @hosts @instances = Instances.new(self, @options) @hosts = @instances.hosts if File.exist?(@cache_path) all_hosts = (CloudInfo.read_yaml(@cache_path) || {}) else all_hosts = {} end all_hosts[env_name] = @hosts unless @hosts.empty? # do not replace cached version if its empty CloudInfo.write_yaml(@cache_path, all_hosts) end @hosts end |
#utils ⇒ Object
54 55 56 |
# File 'lib/cloud_info.rb', line 54 def utils utils = hosts.select{|k,v| k =~ Regexp.new("#{@env_name}_util")}.sort {|a,b| a[0] <=> b[0] } end |