13
14
15
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/appops-client/cli/launcher.rb', line 13
def stack( stack_name, account_name, region_name, template )
fs_root = "%s/dev/appops/cf_templates" % ENV['HOME']
account = AppOpsClientConfig.get( account_name )
AppOpsClientConfig.set_aws_config( account )
fs_template_file = "%s/%s.json" % [fs_root, template]
if(!File.exists?( fs_template_file ))
puts "Unable to find template file: %s".red % fs_template_file
exit
else
puts "Found template file: %s".green % fs_template_file
end
params = {}
params["KeyName"] = "appops"
params["DomainName"] = account["domain_name"]
params["EncKey"] = File.read( "%s/.intuit/enc_key" % ENV['HOME'] )
params["AppOpsClientSecureUrl"] = "https://s3.amazonaws.com/appops0/archive_1393206113.bz2.enc"
template_json = JSON::parse(File.read( fs_template_file ))
template_json["Parameters"].each do |el|
if(el[1].has_key?( "Lookup" ))
lookup = el[1]["Lookup"]
filters = []
lookup["Filters"].each do |f|
filters.push({
name: f["name"],
values: f["values"]
})
end
t = Kernel.const_get( lookup["Type"] ).new()
key = (lookup.has_key?( "Key" ) ? lookup["Key"] : nil)
el[1].delete( "Lookup" )
el[1]["Default"] = t.get( filters, region_name, key, account_name )
end
end
params = params.map{|k,v| { :parameter_key => k, :parameter_value => v}}.compact
AppOpsClientCache.cache.set( "stacks_%s_%s" % [account_name, region_name], nil )
cf = Aws::CloudFormation.new({ region: region_name })
summaries = AppOpsClientCache.get( "stacks_%s_%s" % [account_name, region_name], 900 ) do |keyname|
summaries = cf.list_stacks({ stack_status_filter: [ "CREATE_IN_PROGRESS", "CREATE_COMPLETE", "UPDATE_COMPLETE" ] }).stack_summaries
ro = []
summaries.each{|s| ro.push( s.to_hash )}
ro
end
if(summaries.select{|s| s[:stack_name] == stack_name}.compact.size == 0)
puts "\tUnable to find current stack launching new for %s".yellow % stack_name
cf.create_stack({
stack_name: stack_name,
parameters: params,
capabilities: ["CAPABILITY_IAM"],
template_body: template_json.to_json
})
else
begin
puts "\tFound active stack: %s".yellow % stack_name
cf.update_stack({
stack_name: stack_name,
parameters: params,
capabilities: ["CAPABILITY_IAM"],
template_body: template_json.to_json
})
rescue Aws::CloudFormation::Errors::ValidationError => e
puts "Caught exception: %s" % e
end
end
end
|