Class: SimpleDeploy::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_deploy/stack.rb,
lib/simple_deploy/stack/ssh.rb,
lib/simple_deploy/stack/execute.rb,
lib/simple_deploy/stack/deployment.rb,
lib/simple_deploy/stack/deployment/status.rb

Defined Under Namespace

Classes: Deployment, Execute, SSH

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Stack

Returns a new instance of Stack.



9
10
11
12
13
14
15
16
# File 'lib/simple_deploy/stack.rb', line 9

def initialize(args)
  @environment = args[:environment]
  @name = args[:name]
  @config = Config.new :logger => args[:logger]
  @logger = @config.logger

  @use_internal_ips = !!args[:internal]
end

Instance Method Details

#attributesObject



97
98
99
# File 'lib/simple_deploy/stack.rb', line 97

def attributes
  stack.attributes 
end

#create(args) ⇒ Object



18
19
20
21
22
# File 'lib/simple_deploy/stack.rb', line 18

def create(args)
  attributes = stack_attribute_formater.updated_attributes args[:attributes]
  stack.create :attributes => attributes,
               :template   => args[:template]
end

#deploy(force = false) ⇒ Object



46
47
48
# File 'lib/simple_deploy/stack.rb', line 46

def deploy(force = false)
  deployment.execute force
end

#destroyObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/simple_deploy/stack.rb', line 58

def destroy
  if attributes['protection'] != 'on'
    stack.destroy
    @logger.info "#{@name} destroyed."
    true
  else
    @logger.warn "#{@name} could not be destroyed because it is protected. Run the protect subcommand to unprotect it"
    false
  end
end

#events(limit) ⇒ Object



69
70
71
# File 'lib/simple_deploy/stack.rb', line 69

def events(limit)
  stack.events limit
end

#execute(args) ⇒ Object



50
51
52
# File 'lib/simple_deploy/stack.rb', line 50

def execute(args)
  executer.execute args
end

#instancesObject



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/simple_deploy/stack.rb', line 81

def instances
  stack.instances.map do |instance| 
    instance['instancesSet'].map do |info|
      if info['vpcId'] || @use_internal_ips
        info['privateIpAddress']
      else
        info['ipAddress']
      end
    end
  end.flatten
end

#outputsObject



73
74
75
# File 'lib/simple_deploy/stack.rb', line 73

def outputs
  stack.outputs
end

#parametersObject



101
102
103
# File 'lib/simple_deploy/stack.rb', line 101

def parameters
  stack.parameters 
end

#resourcesObject



77
78
79
# File 'lib/simple_deploy/stack.rb', line 77

def resources
  stack.resources
end

#sshObject



54
55
56
# File 'lib/simple_deploy/stack.rb', line 54

def ssh
  deployment.ssh
end

#statusObject



93
94
95
# File 'lib/simple_deploy/stack.rb', line 93

def status
  stack.status
end

#templateObject



105
106
107
# File 'lib/simple_deploy/stack.rb', line 105

def template
  JSON.parse stack.template
end

#update(args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/simple_deploy/stack.rb', line 24

def update(args)
  if !deployment.clear_for_deployment? && args[:force]
    deployment.clear_deployment_lock true

    Backoff.exp_periods do |p|
      sleep p
      break if deployment.clear_for_deployment?
    end
  end

  if deployment.clear_for_deployment?
    @logger.info "Updating #{@name}."
    attributes = stack_attribute_formater.updated_attributes args[:attributes]
    stack.update :attributes => attributes
    @logger.info "Update complete for #{@name}."
    true
  else
    @logger.info "Not clear to update."
    false
  end
end