Class: Infrastructure
- Inherits:
-
Object
- Object
- Infrastructure
- Includes:
- Cluster::Logging
- Defined in:
- lib/cluster/infrastructure.rb
Direct Known Subclasses
Constant Summary collapse
- @@subsystem =
nil
- @@cluster_name =
'cluster'
- @@in_cluster =
false
- @@machine_sizes =
%w(minimum basic average power super)
- @@dns =
nil
Class Method Summary collapse
- .cluster_name ⇒ Object
- .connect(arguments = nil) ⇒ Object
- .current ⇒ Object
- .dns ⇒ Object
- .in_cluster? ⇒ Boolean
- .sizes ⇒ Object (also: machine_sizes)
Instance Method Summary collapse
- #configure ⇒ Object
- #credentials ⇒ Object
- #credentials? ⇒ Boolean
- #current_instance ⇒ Object
- #in_cluster? ⇒ Boolean
-
#initialize(arguments = nil) ⇒ Infrastructure
constructor
A new instance of Infrastructure.
- #instances ⇒ Object
- #machines(*filter_groups) ⇒ Object
- #names(*roles) ⇒ Object
- #release_class ⇒ Object
- #services(filter_services) ⇒ Object
- #to_credentials ⇒ Object
Methods included from Cluster::Logging
Constructor Details
permalink #initialize(arguments = nil) ⇒ Infrastructure
Returns a new instance of Infrastructure.
11 12 13 |
# File 'lib/cluster/infrastructure.rb', line 11 def initialize(arguments = nil) @arguments = arguments end |
Class Method Details
permalink .cluster_name ⇒ Object
[View source]
110 111 112 |
# File 'lib/cluster/infrastructure.rb', line 110 def cluster_name @@cluster_name end |
permalink .connect(arguments = nil) ⇒ Object
[View source]
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/cluster/infrastructure.rb', line 114 def connect(arguments = nil) name = nil # removes the infrastructure argument, if given, and processes it new_args = arguments.map {|arg| case arg when /^-i([^=]+)$/, /^--infr[^=]+=(.+)$/ name = $1 nil when /^-n([^=]+)$/, /^--name[^=]+=(.+)$/ @@cluster_name = $1 else arg end }.compact name ||= 'amazon' begin require File.join('cluster', 'infrastructures', name) rescue LoadError => err STDERR.puts "Subsystem of #{name} either is not included or not available.\n\t#{err.}\n#{err.backtrace.join("\n\t")}" exit 1 end begin sub = Object.const_get name.capitalize rescue NameError STDERR.puts "Subsystem of #{name.capitalize} cannot be initialized." exit 1 end sub.new new_args end |
permalink .current ⇒ Object
[View source]
106 107 108 |
# File 'lib/cluster/infrastructure.rb', line 106 def current @@subsystem end |
permalink .dns ⇒ Object
[View source]
148 149 150 151 152 153 154 |
# File 'lib/cluster/infrastructure.rb', line 148 def dns return @@dns unless @@dns.nil? ns = '' File.open('/etc/resolv.conf').each do |line| ns = $1 if line =~ /nameserver\s+([\d\.]+)/; end @@dns = Resolv::DNS.new(:nameserver => ns) end |
permalink .in_cluster? ⇒ Boolean
156 157 158 |
# File 'lib/cluster/infrastructure.rb', line 156 def in_cluster? @@in_cluster end |
permalink .sizes ⇒ Object Also known as: machine_sizes
[View source]
101 102 103 |
# File 'lib/cluster/infrastructure.rb', line 101 def sizes @@machine_sizes end |
Instance Method Details
permalink #configure ⇒ Object
[View source]
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cluster/infrastructure.rb', line 15 def configure @options = OpenStruct.new @options.current_instance_id = nil @options.original_services = [] if credentials? cluster = credentials['cluster'] if cluster @options.current_instance_id = cluster['id'] @options.original_services = cluster['services'].split(',') end end @@subsystem ||= self end |
permalink #credentials ⇒ Object
[View source]
50 51 52 |
# File 'lib/cluster/infrastructure.rb', line 50 def credentials @credentials end |
permalink #credentials? ⇒ Boolean
42 43 44 45 46 47 48 |
# File 'lib/cluster/infrastructure.rb', line 42 def credentials? return true if @credentials if Cluster::Configuration.credentials? @credentials = Cluster::Configuration.credentials end end |
permalink #current_instance ⇒ Object
[View source]
35 36 37 38 39 |
# File 'lib/cluster/infrastructure.rb', line 35 def current_instance return nil unless @options.current_instance_id instances.detect {|ins| ins.id.eql?(@options.current_instance_id) } end |
permalink #in_cluster? ⇒ Boolean
54 55 56 |
# File 'lib/cluster/infrastructure.rb', line 54 def in_cluster? raise NotImplementedError end |
permalink #instances ⇒ Object
31 32 33 |
# File 'lib/cluster/infrastructure.rb', line 31 def instances raise NotImplementedError end |
permalink #machines(*filter_groups) ⇒ Object
[View source]
66 67 68 69 70 71 72 |
# File 'lib/cluster/infrastructure.rb', line 66 def machines(*filter_groups) if filter_groups.empty? self.instances else self.instances.select {|i| i.groups.any? {|g| filter_groups.include? g }} end end |
permalink #names(*roles) ⇒ Object
58 59 60 |
# File 'lib/cluster/infrastructure.rb', line 58 def names(*roles) raise NotImplementedError end |
permalink #release_class ⇒ Object
62 63 64 |
# File 'lib/cluster/infrastructure.rb', line 62 def release_class raise NotImplementedError end |
permalink #services(filter_services) ⇒ Object
[View source]
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/cluster/infrastructure.rb', line 74 def services(filter_services) filter_services = Array(filter_services) unless filter_services.is_a? Array if filter_services.empty? puts "No services provided to return a list for #{filter_services.join(' ')}" exit 1 else self.instances.select {|i| i.services.any? {|s| filter_services.include?(s) and !i.disabled_services.include?(s)} } end end |
permalink #to_credentials ⇒ Object
[View source]
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cluster/infrastructure.rb', line 87 def to_credentials opts = @options.marshal_dump.keys.inject({}) {|m, k| if k.eql? :role m else m.merge k.to_s => @options.send(k) end } {'cluster_name' => self.class.cluster_name, self.class.to_s.downcase => opts } end |