5
6
7
8
9
10
11
12
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
|
# File 'lib/ami/commands/create_ami.rb', line 5
def run(argv)
name = argv[0]
AMI::Core.load_amis
unless AMI::Core.valid_ami?(name)
warn "Invalid AMI name #{name}. Use ami-list to see available AMIs"
exit 1
end
ami = AMI::Core.ami(name).new
server_template = AMI::Server.new
ami.server(server_template)
ami_name = ami.name
config = AMI::ConfigLoader.load_config
server = AMI::InstanceProvisioner.provision(
ami_name,
server_template,
config
)
begin
ssh = AMI::SSH.create_connection(server, server_template.user_name)
ami.configure(ssh, config)
ami.create_ami(ssh, config)
puts 'done'
rescue
warn "failure occurred, terminating server"
raise
ensure
server.terminate
end
end
|