Class: Terraspace::Cloud::Base
Instance Method Summary
collapse
#pretty_path, #pretty_time
Methods included from Util::Sure
#sure?
#logger
Methods included from Context
#setup_context
#validate
#api, #cloud_stack_name, #expander, #region
#error_message, #errors?
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
8
9
10
11
12
13
14
|
# File 'lib/terraspace/cloud/base.rb', line 8
def initialize(options={})
super
@cani = options[:cani]
@kind = options[:kind]
@vcs_vars = options[:vcs_vars]
setup_context(options)
end
|
Instance Method Details
#cancelled? ⇒ Boolean
71
72
73
74
75
|
# File 'lib/terraspace/cloud/base.rb', line 71
def cancelled?
!!Terraspace::Logger.buffer.detect do |line|
line.include?(' cancelled')
end
end
|
#changes? ⇒ Boolean
61
62
63
64
65
66
67
68
69
|
# File 'lib/terraspace/cloud/base.rb', line 61
def changes?
no_changes = Terraspace::Logger.buffer.detect do |line|
line.include?('No changes')
end
zero_destroyed = Terraspace::Logger.buffer.detect do |line|
line.include?('Destroy complete! Resources: 0 destroyed')
end
!no_changes && !zero_destroyed
end
|
#clean_cache2_stage ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/terraspace/cloud/base.rb', line 48
def clean_cache2_stage
kind = self.class.name.to_s.split('::').last.underscore dir = "#{@mod.cache_dir}/.terraspace-cache/.cache2/#{kind}"
FileUtils.rm_rf(dir)
FileUtils.mkdir_p(dir)
end
|
#cloud_upload ⇒ Object
26
27
28
|
# File 'lib/terraspace/cloud/base.rb', line 26
def cloud_upload
Upload.new(@options)
end
|
#record? ⇒ Boolean
57
58
59
|
# File 'lib/terraspace/cloud/base.rb', line 57
def record?
changes? && !cancelled? || Terraspace.config.cloud.record == "all"
end
|
#sh(command, exit_on_fail: true) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/terraspace/cloud/base.rb', line 39
def sh(command, exit_on_fail: true)
logger.debug "=> #{command}"
system command
if $?.exitstatus != 0 && exit_on_fail
logger.info "ERROR RUNNING: #{command}"
exit $?.exitstatus
end
end
|
#stage_attrs(success) ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/terraspace/cloud/base.rb', line 16
def stage_attrs(success)
status = success_status(success)
attrs = {
status: status,
kind: @kind,
}
attrs.merge!(@vcs_vars)
attrs
end
|
#success_status(success) ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/terraspace/cloud/base.rb', line 31
def success_status(success)
case success
when true then "success"
when false then "fail"
when nil then "started"
end
end
|