Class: Instance
Defined Under Namespace
Constant Summary collapse
- NA_STATUS =
'n/a'
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#index ⇒ Object
Returns the value of attribute index.
-
#name ⇒ Object
Returns the value of attribute name.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#region ⇒ Object
Returns the value of attribute region.
-
#role ⇒ Object
Returns the value of attribute role.
-
#zone ⇒ Object
Returns the value of attribute zone.
Class Method Summary collapse
- .create(maws, config, prefix, zone, role, index, options = {}) ⇒ Object
- .name_for(config, prefix, zone, role, index) ⇒ Object
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #aws_id ⇒ Object
- #config(key, required = false) ⇒ Object
- #connection ⇒ Object
- #display ⇒ Object
- #display_fields ⇒ Object
- #has_approximate_status?(approximate_status) ⇒ Boolean
-
#initialize(maws, config, name, region, prefix, zone, role, index) ⇒ Instance
constructor
A new instance of Instance.
- #inspect ⇒ Object
- #instances ⇒ Object
- #logical_zone ⇒ Object
- #matches?(filters = {}) ⇒ Boolean
- #method_missing(method_name, *args, &block) ⇒ Object
- #physical_zone ⇒ Object
- #region_physical_zone ⇒ Object
- #region_zone ⇒ Object
- #security_groups ⇒ Object
- #service ⇒ Object
- #status ⇒ Object
- #terminated? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(maws, config, name, region, prefix, zone, role, index) ⇒ Instance
Returns a new instance of Instance.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/maws/instance.rb', line 30 def initialize(maws, config, name, region, prefix, zone, role, index) @maws = maws @config = config @name = name @region = region @zone = zone @role = role @index = index @prefix = prefix @description = mash @groups = %w(all) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
111 112 113 114 115 |
# File 'lib/maws/instance.rb', line 111 def method_missing(method_name, *args, &block) config(method_name) || description[method_name] || @config.command_line[method_name] end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
9 10 11 |
# File 'lib/maws/instance.rb', line 9 def description @description end |
#groups ⇒ Object
Returns the value of attribute groups.
8 9 10 |
# File 'lib/maws/instance.rb', line 8 def groups @groups end |
#index ⇒ Object
Returns the value of attribute index.
8 9 10 |
# File 'lib/maws/instance.rb', line 8 def index @index end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/maws/instance.rb', line 7 def name @name end |
#prefix ⇒ Object
Returns the value of attribute prefix.
8 9 10 |
# File 'lib/maws/instance.rb', line 8 def prefix @prefix end |
#region ⇒ Object
Returns the value of attribute region.
8 9 10 |
# File 'lib/maws/instance.rb', line 8 def region @region end |
#role ⇒ Object
Returns the value of attribute role.
8 9 10 |
# File 'lib/maws/instance.rb', line 8 def role @role end |
#zone ⇒ Object
Returns the value of attribute zone.
8 9 10 |
# File 'lib/maws/instance.rb', line 8 def zone @zone end |
Class Method Details
.create(maws, config, prefix, zone, role, index, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/maws/instance.rb', line 13 def self.create(maws, config, prefix, zone, role, index, = {}) = mash() service = .service || config.combined[role].service region = .region || config.region name = .name || name_for(config, prefix, zone, role, index) klass = Instance.const_get("#{service.to_s.upcase}") klass.new(maws, config, name, region, prefix, zone, role, index) end |
.name_for(config, prefix, zone, role, index) ⇒ Object
25 26 27 28 |
# File 'lib/maws/instance.rb', line 25 def self.name_for(config, prefix, zone, role, index) add_prefix = prefix.empty? ? "" : prefix + "." "#{add_prefix}#{config.profile.name}-#{role}-#{index}#{zone}" end |
Instance Method Details
#alive? ⇒ Boolean
87 88 89 |
# File 'lib/maws/instance.rb', line 87 def alive? aws_id && !terminated? end |
#aws_id ⇒ Object
66 67 68 |
# File 'lib/maws/instance.rb', line 66 def aws_id description.aws_id end |
#config(key, required = false) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/maws/instance.rb', line 117 def config(key, required=false) if required && @config.combined[role][key].nil? raise ArgumentError.new("Missing required config: #{key}") end @config.combined[role][key] end |
#connection ⇒ Object
45 46 47 |
# File 'lib/maws/instance.rb', line 45 def connection @maws.connection end |
#display ⇒ Object
144 145 146 |
# File 'lib/maws/instance.rb', line 144 def display InstanceDisplay.new(self, display_fields) end |
#display_fields ⇒ Object
140 141 142 |
# File 'lib/maws/instance.rb', line 140 def display_fields [:zone, :name, :status] end |
#has_approximate_status?(approximate_status) ⇒ Boolean
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/maws/instance.rb', line 99 def has_approximate_status?(approximate_status) if approximate_status == "n/a" or approximate_status == "terminated" !alive? elsif approximate_status == "ssh" self.respond_to?(:ssh_available?) ? self.ssh_available? : has_approximate_status?("available") elsif approximate_status == "running" || approximate_status == "available" status == "running" || status == "available" else approximate_status == status end end |
#inspect ⇒ Object
95 96 97 |
# File 'lib/maws/instance.rb', line 95 def inspect "<#{self.class} #{to_s}>" end |
#instances ⇒ Object
49 50 51 |
# File 'lib/maws/instance.rb', line 49 def instances @maws.instances end |
#logical_zone ⇒ Object
58 59 60 |
# File 'lib/maws/instance.rb', line 58 def logical_zone @zone end |
#matches?(filters = {}) ⇒ Boolean
148 149 150 151 152 153 154 155 156 |
# File 'lib/maws/instance.rb', line 148 def matches?(filters={}) approximate_status = filters.delete(:approximate_status) matched = InstanceMatcher.matches?(self, filters) # approximate status is not a single state # it might require an ssh connection matched &&= has_approximate_status?(approximate_status) if approximate_status matched end |
#physical_zone ⇒ Object
62 63 64 |
# File 'lib/maws/instance.rb', line 62 def physical_zone @zone || @description.physical_zone || @config.specified_zones.first end |
#region_physical_zone ⇒ Object
78 79 80 |
# File 'lib/maws/instance.rb', line 78 def region_physical_zone region + physical_zone end |
#region_zone ⇒ Object
74 75 76 |
# File 'lib/maws/instance.rb', line 74 def region_zone region + zone end |
#security_groups ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/maws/instance.rb', line 125 def security_groups groups = config(:security_groups).to_a.dup groups << "#{service}_default" if @config.profile.security_rules and @config.profile.security_rules[role] groups << "#{@profile.name}-#{role_name}" end groups end |
#service ⇒ Object
136 137 138 |
# File 'lib/maws/instance.rb', line 136 def service raise ArgumentError, "No service for generic instance" end |
#status ⇒ Object
70 71 72 |
# File 'lib/maws/instance.rb', line 70 def status description.status || 'n/a' end |
#terminated? ⇒ Boolean
83 84 85 |
# File 'lib/maws/instance.rb', line 83 def terminated? status == 'terminated' end |
#to_s ⇒ Object
91 92 93 |
# File 'lib/maws/instance.rb', line 91 def to_s "#{name} #{status} #{aws_id}" end |