Class: CloudInfo
- Inherits:
-
Object
- Object
- CloudInfo
- Defined in:
- lib/cloud_info.rb,
lib/cloud_info/instances.rb
Defined Under Namespace
Classes: Instances
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
-
#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.
8 9 10 11 12 |
# File 'lib/cloud_info.rb', line 8 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.
7 8 9 |
# File 'lib/cloud_info.rb', line 7 def env_name @env_name end |
Class Method Details
.all_hosts(options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cloud_info.rb', line 47 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
65 66 67 |
# File 'lib/cloud_info.rb', line 65 def self.read_yaml(path) YAML.load(IO.read(path)) end |
.write_yaml(path, hosts) ⇒ Object
60 61 62 63 64 |
# File 'lib/cloud_info.rb', line 60 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
40 41 42 |
# File 'lib/cloud_info.rb', line 40 def app_master apps[0][1] end |
#apps ⇒ Object
37 38 39 |
# File 'lib/cloud_info.rb', line 37 def apps apps = hosts.select{|k,v| k =~ Regexp.new("#{@env_name}_app")}.sort {|a,b| a[0] <=> b[0] } end |
#hosts ⇒ Object
if a cache exist it uses it instead of finding the servers
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cloud_info.rb', line 15 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 CloudInfo.write_yaml(@cache_path, all_hosts) end @hosts end |
#utils ⇒ Object
43 44 45 |
# File 'lib/cloud_info.rb', line 43 def utils utils = hosts.select{|k,v| k =~ Regexp.new("#{@env_name}_util")}.sort {|a,b| a[0] <=> b[0] } end |