Class: Kitchen::Driver::Ec2
- Inherits:
-
Base
- Object
- Base
- Kitchen::Driver::Ec2
- Defined in:
- lib/kitchen/driver/ec2.rb
Overview
Amazon EC2 driver for Test Kitchen.
Class Method Summary collapse
Instance Method Summary collapse
-
#create(state) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
- #default_ami ⇒ Object
- #destroy(state) ⇒ Object
-
#finalize_config!(instance) ⇒ self
A lifecycle method that should be invoked when the object is about ready to be used.
Class Method Details
.validation_warn(driver, old_key, new_key) ⇒ Object
67 68 69 70 |
# File 'lib/kitchen/driver/ec2.rb', line 67 def self.validation_warn(driver, old_key, new_key) driver.warn "WARN: The driver[#{driver.class.name}] config key `#{old_key}` " \ "is deprecated, please use `#{new_key}`" end |
Instance Method Details
#create(state) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/kitchen/driver/ec2.rb', line 168 def create(state) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength copy_deprecated_configs(state) return if state[:server_id] info(Kitchen::Util.outdent!(" Creating <\#{state[:server_id]}>...\n If you are not using an account that qualifies under the AWS\n free-tier, you may be charged to run these suites. The charge\n should be minimal, but neither Test Kitchen nor its maintainers\n are responsible for your incurred costs.\n END\n\n if config[:price]\n # Spot instance when a price is set\n server = submit_spot(state)\n else\n # On-demand instance\n server = submit_server\n end\n info(\"Instance <\#{server.id}> requested.\")\n tag_server(server)\n\n state[:server_id] = server.id\n info(\"EC2 instance <\#{state[:server_id]}> created.\")\n wait_log = proc do |attempts|\n c = attempts * config[:retryable_sleep]\n t = config[:retryable_tries] * config[:retryable_sleep]\n info \"Waited \#{c}/\#{t}s for instance <\#{state[:server_id]}> to become ready.\"\n end\n server = server.wait_until(\n :max_attempts => config[:retryable_tries],\n :delay => config[:retryable_sleep],\n :before_attempt => wait_log\n ) do |s|\n hostname = hostname(s)\n # Euca instances often report ready before they have an IP\n s.state.name == \"running\" && !hostname.nil? && hostname != \"0.0.0.0\"\n end\n\n info(\"EC2 instance <\#{state[:server_id]}> ready.\")\n state[:hostname] = hostname(server)\n instance.transport.connection(state).wait_until_ready\n create_ec2_json(state)\n debug(\"ec2:create '\#{state[:hostname]}'\")\nend\n")) |
#default_ami ⇒ Object
233 234 235 236 |
# File 'lib/kitchen/driver/ec2.rb', line 233 def default_ami region = amis["regions"][config[:region]] region && region[instance.platform.name] end |
#destroy(state) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/kitchen/driver/ec2.rb', line 214 def destroy(state) return if state[:server_id].nil? server = ec2.get_instance(state[:server_id]) unless server.nil? instance.transport.connection(state).close server.terminate unless server.nil? end if state[:spot_request_id] debug("Deleting spot request <#{state[:server_id]}>") ec2.client.cancel_spot_instance_requests( :spot_instance_request_ids => [state[:spot_request_id]] ) end info("EC2 instance <#{state[:server_id]}> destroyed.") state.delete(:server_id) state.delete(:hostname) end |
#finalize_config!(instance) ⇒ self
A lifecycle method that should be invoked when the object is about ready to be used. A reference to an Instance is required as configuration dependant data may be access through an Instance. This also acts as a hook point where the object may wish to perform other last minute checks, validations, or configuration expansions.
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/kitchen/driver/ec2.rb', line 154 def finalize_config!(instance) super if config[:availability_zone].nil? config[:availability_zone] = config[:region] + "b" end # TODO: when we get rid of flavor_id, move this to a default if config[:instance_type].nil? config[:instance_type] = config[:flavor_id] || "m1.small" end self end |