Class: Maws
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#descriptions ⇒ Object
readonly
Returns the value of attribute descriptions.
-
#instances ⇒ Object
readonly
Returns the value of attribute instances.
Class Method Summary collapse
Instance Method Summary collapse
- #build_instances ⇒ Object
- #connect(services = nil) ⇒ Object
- #create_from_descriptions ⇒ Object
- #create_from_specification ⇒ Object
- #find_or_create_specified(prefix, zone, role_name, index) ⇒ Object
-
#initialize(config, command) ⇒ Maws
constructor
A new instance of Maws.
- #resync_instances ⇒ Object
- #run! ⇒ Object
- #services ⇒ Object
- #specified_roles ⇒ Object
- #specified_zones ⇒ Object
Constructor Details
#initialize(config, command) ⇒ Maws
Returns a new instance of Maws.
9 10 11 12 13 14 15 16 17 |
# File 'lib/maws/maws.rb', line 9 def initialize(config, command) @config = config @command = command @connection = Connection.new(@config) @instances = InstanceCollection.new @specification = Specification.new(@config, @config.command_line.selection || "") end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
7 8 9 |
# File 'lib/maws/maws.rb', line 7 def command @command end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/maws/maws.rb', line 7 def config @config end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
7 8 9 |
# File 'lib/maws/maws.rb', line 7 def connection @connection end |
#descriptions ⇒ Object (readonly)
Returns the value of attribute descriptions.
7 8 9 |
# File 'lib/maws/maws.rb', line 7 def descriptions @descriptions end |
#instances ⇒ Object (readonly)
Returns the value of attribute instances.
7 8 9 |
# File 'lib/maws/maws.rb', line 7 def instances @instances end |
Class Method Details
.load_and_run! ⇒ Object
19 20 21 22 23 24 |
# File 'lib/maws.rb', line 19 def self.load_and_run! base_path = Dir.pwd cc_path = 'maws.yml' Loader.new(base_path, cc_path).load_and_run end |
Instance Method Details
#build_instances ⇒ Object
63 64 65 66 67 68 |
# File 'lib/maws/maws.rb', line 63 def build_instances @descriptions = @connection.descriptions(services) create_from_descriptions create_from_specification end |
#connect(services = nil) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/maws/maws.rb', line 47 def connect(services = nil) services ||= @specification.services @connection.connect(services) @config.available_zones = @connection.available_zones @config.specified_zones = @specification.zones end |
#create_from_descriptions ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/maws/maws.rb', line 70 def create_from_descriptions @descriptions.map { |description| instance = description.create_instance(self, @config) @instances.add(instance) instance.groups << "aws" } end |
#create_from_specification ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/maws/maws.rb', line 78 def create_from_specification @specification.existing_instances = @instances.matching(:groups => 'aws') prefix = @config.prefix @specification.role_indexes.each {|role_name, indexes| @specification.zones_for_role(role_name).each {|zone| indexes.each do |index| instance = find_or_create_specified(prefix, zone, role_name, index) instance.groups << "specified" end } } end |
#find_or_create_specified(prefix, zone, role_name, index) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/maws/maws.rb', line 92 def find_or_create_specified(prefix, zone, role_name, index) found = @instances.matching({:zone => zone, :role => role_name, :index => index, :prefix => prefix}) if !found.empty? found.first else instance = Instance.create(self, @config, prefix, zone, role_name, index) @instances.add(instance) instance end end |
#resync_instances ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/maws/maws.rb', line 55 def resync_instances @descriptions = @connection.descriptions(services) @descriptions.each {|description| instance = @instances.matching(:aws_id => description.aws_id).first instance.description = description if instance } end |
#run! ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/maws/maws.rb', line 31 def run! connect info "\n" info "REGION: #{@config.region}" info "AVAILABLE ZONES: #{@connection.available_zones.join(', ')}" build_instances info "\n" info "QUERYING SERVICES: #{instances.services.join(', ')}" info "TOTAL #{@config.profile.name.upcase} ON AWS: #{instances.aws.count} " info "TOTAL SELECTED: #{instances.specified.count}" info "TOTAL SELECTED ON AWS: #{instances.specified.aws.count}" @command.run! end |
#services ⇒ Object
19 20 21 |
# File 'lib/maws/maws.rb', line 19 def services @specification.services end |
#specified_roles ⇒ Object
23 24 25 |
# File 'lib/maws/maws.rb', line 23 def specified_roles @specification.roles end |
#specified_zones ⇒ Object
27 28 29 |
# File 'lib/maws/maws.rb', line 27 def specified_zones @specification.zones end |