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
|
# File 'lib/vagrant-ttl/command/ttl.rb', line 14
def execute
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant ttl [machine-name]"
end
argv = parse_options(opts)
argv = ["default"] if !argv
ssh_info = nil
with_target_vms(argv) do |machine|
if machine.state.id == :poweroff
@env.ui.info("[ \e[31mError\e[0m ] #{machine.name} is poweroff. Please execute `vagrant up`")
next
end
ssh_info = machine.ssh_info
macro = <<"EOS"
username = '#{ssh_info[:username]}'
keyfile = '#{ssh_info[:private_key_path][0]}'
hostname = '#{ssh_info[:host]}'
msg = hostname
strconcat msg ':#{ssh_info[:port]} /ssh2 /auth=publickey /user='
strconcat msg username
strconcat msg ' /keyfile='
strconcat msg keyfile
connect msg
EOS
begin
File.open("#{machine.name}.ttl", "wb") do |fout|
fout.write(macro)
end
@env.ui.info("[ \e[32mINFO\e[0m ] Generating #{machine.name}.ttl")
rescue
@env.ui.info("[ \e[31mError \e[0m ] Generating #{machine.name}.ttl")
end
end
0
end
|