Class: Leeroy::Task::Instantiate

Inherits:
Base
  • Object
show all
Includes:
Helpers::AWS, Helpers::Inventory, Helpers::Polling, Helpers::Template
Defined in:
lib/leeroy/task/instantiate.rb

Constant Summary

Constants included from Helpers::Polling

Helpers::Polling::POLL_CALLBACK, Helpers::Polling::POLL_INTERVAL, Helpers::Polling::POLL_TIMEOUT

Constants included from Helpers::Logging

Helpers::Logging::TRACE_FORMAT, Helpers::Logging::TRACE_LEVELS, Helpers::Logging::TRUNCATE_THRESHOLD

Instance Attribute Summary

Attributes included from Helpers::Polling

#poll_callback, #poll_interval, #poll_response, #poll_timeout

Attributes included from Helpers::Env

#env

Attributes included from Helpers::AWS

#ec2, #rds, #s3

Attributes included from Helpers::State

#state

Attributes included from Leeroy::Task

#args, #global_options, #options

Instance Method Summary collapse

Methods included from Helpers::Template

#renderTemplate

Methods included from Helpers::Polling

#poll

Methods included from Helpers::Env

#checkEnv

Methods included from Helpers::Inventory

#genImageIndex, #genImageName

Methods included from Helpers::Logging

#logger

Methods included from Helpers::AWS

#awsRequest, #buildS3ObjectName, #checkSemaphore, #clearSemaphore, #createTags, #destroyInstance, #ec2Request, #filterImages, #genSemaphore, #getApplicationImageIndex, #getApplicationInstanceName, #getGoldMasterImageIndex, #getGoldMasterInstanceName, #getImageByName, #getMaxImageIndex, #getRDSInstanceEndpoint, #getSemaphore, #getSgId, #getSubnetId, #getVpcId, #rdsRequest, #s3Request, #setSemaphore

Methods included from Helpers::State

#dump_state, #load_state, #rotate_task_metadata, #state_from_pipe, #to_s

Constructor Details

#initialize(*args, &block) ⇒ Instantiate

Returns a new instance of Instantiate.



60
61
62
63
# File 'lib/leeroy/task/instantiate.rb', line 60

def initialize(*args, &block)
  super

end

Instance Method Details

#perform(args = self.args, options = self.options, global_options = self.global_options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/leeroy/task/instantiate.rb', line 16

def perform(args = self.args, options = self.options, global_options = self.global_options)
  begin
    super(args, options, global_options)

    phase = Leeroy::Types::Phase.resolve(self.state.fetch('phase'), options[:phase])
    logger.debug "phase: #{phase}"
    self.state.phase = phase

    # resolve various AWS resources from human-readable inputs
    _resolveResources

    # create instance
    instance = Leeroy::Types::Instance.new(_genInstanceParams)
    resp = ec2Request(:run_instances, instance.run_params)
    instanceid = resp.instances[0].instance_id
    self.state.instanceid = instanceid

    # wait until instance is starting
    _prepInstanceCreationPolling
    poll(instanceid)

    # tag instance
    instance_name = phase == 'gold_master' ? getGoldMasterInstanceName : getApplicationInstanceName
    createTags({'Name' => instance_name})

    # write semaphore
    s3_object = buildS3ObjectName(instanceid, 'semaphores')
    payload = _readSemaphore(phase)
    semaphore = setSemaphore(genSemaphore(s3_object, payload))
    self.state.semaphore = semaphore

    # wait until instance is done provisioning
    _prepInstanceProvisionPolling
    poll(semaphore)

    dump_state

    logger.debug "done performing for #{self.class}"

  rescue StandardError => e
    raise e
  end
end