Class: CloudManager::Configuration::Service::EC2Machine
- Defined in:
- lib/cloud_manager/configuration/service/ec2.rb
Overview
This class represents an EC2 machine along with its settings.
Instance Attribute Summary collapse
-
#instances ⇒ Array<Aws::EC2::Instance>
readonly
The EC2 instances of this machine – docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Instance.html.
Attributes inherited from Machine
#alias, #config, #parent_service
Instance Method Summary collapse
-
#dns_names ⇒ Array<String>
Returns the DNS name list for the machine.
-
#initialize(machine_alias, config, parent_service) ⇒ EC2Machine
constructor
Returns a new instance of EC2Machine.
-
#ips ⇒ Array<String>
Returns the IP list for the machine.
-
#start ⇒ void
Starts the machine in the EC2 cloud.
Constructor Details
#initialize(machine_alias, config, parent_service) ⇒ EC2Machine
Returns a new instance of EC2Machine.
127 128 129 130 131 132 133 134 135 |
# File 'lib/cloud_manager/configuration/service/ec2.rb', line 127 def initialize(machine_alias, config, parent_service) super(machine_alias, config, parent_service) @instances = [] raise "services.ec2.#{@alias} configuration is missing" unless @config.is_a?(Hash) raise "services.ec2.#{@alias}.image_id must be configured" unless @config.include?('image_id') && @config['image_id'].is_a?(String) raise "services.ec2.#{@alias}.key_name must be configured" unless @config.include?('key_name') && @config['key_name'].is_a?(String) raise "services.ec2.#{@alias}.instance_type must be configured" unless @config.include?('instance_type') && @config['instance_type'].is_a?(String) end |
Instance Attribute Details
#instances ⇒ Array<Aws::EC2::Instance> (readonly)
Returns the EC2 instances of this machine – docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Instance.html.
120 121 122 |
# File 'lib/cloud_manager/configuration/service/ec2.rb', line 120 def instances @instances end |
Instance Method Details
#dns_names ⇒ Array<String>
Returns the DNS name list for the machine.
185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/cloud_manager/configuration/service/ec2.rb', line 185 def dns_names dns_names = [] unless @instances.empty? @instances.each do |instance| instance.load # need to refresh data to get dns names dns_names.push(instance.public_dns_name) unless instance.public_dns_name.nil? end end dns_names end |
#ips ⇒ Array<String>
Returns the IP list for the machine.
169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/cloud_manager/configuration/service/ec2.rb', line 169 def ips ips = [] unless @instances.empty? @instances.each do |instance| instance.load # need to refresh data to get ip address ips.push(instance.public_ip_address) unless instance.public_ip_address.nil? end end ips end |
#start ⇒ void
Available instances with the same alias could be checked before start. If there is any, the #instances property could be filled with them.
This method returns an undefined value.
Starts the machine in the EC2 cloud.
The used aws-sdk methods:
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/cloud_manager/configuration/service/ec2.rb', line 145 def start if @instances.empty? @instances = @parent_service.resource.create_instances({ image_id: @config['image_id'], min_count: @config.include?('min_count') ? @config['min_count'] : 1, max_count: @config.include?('max_count') ? @config['max_count'] : 1, key_name: @config['key_name'], instance_type: @config['instance_type'], }) @instances.each do |instance| @parent_service.resource.({ resources: [instance.id], tags: [key: 'Name', value: @alias] }) puts " > instance started: #{instance.id} (#{@alias})" end end end |