veewee-to-packer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +20 -0
- data/Rakefile +1 -0
- data/bin/veewee-to-packer +61 -0
- data/lib/veewee-to-packer/builders/virtualbox.rb +198 -0
- data/lib/veewee-to-packer/builders/vmware.rb +183 -0
- data/lib/veewee-to-packer/error.rb +6 -0
- data/lib/veewee-to-packer/mock_veewee.rb +20 -0
- data/lib/veewee-to-packer/version.rb +3 -0
- data/lib/veewee-to-packer.rb +118 -0
- data/veewee-to-packer.gemspec +19 -0
- metadata +60 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Mitchell Hashimoto
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Veewee to Packer Template Converter
|
2
|
+
|
3
|
+
This is a RubyGem that will translate [Veewee](https://github.com/jedi4ever/veewee)
|
4
|
+
templates to [Packer](http://www.packer.io) templates. The conversion is
|
5
|
+
_perfect_. If 100% of the functionality can't be translated to the Packer
|
6
|
+
template, a warning or error message will be shown, depending on if its
|
7
|
+
critical or not.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Because Veewee is a RubyGem, so too is this converter. Installing using
|
12
|
+
RubyGems:
|
13
|
+
|
14
|
+
$ gem install veewee-to-packer
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Usage is simple:
|
19
|
+
|
20
|
+
$ veewee-to-packer original-template.rb
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Trap interrupts to quit cleanly so they don't result in random stacktraces.
|
4
|
+
Signal.trap("INT") { exit 1 }
|
5
|
+
|
6
|
+
# Stdout/stderr should not buffer output
|
7
|
+
$stdout.sync = true
|
8
|
+
$stderr.sync = true
|
9
|
+
|
10
|
+
require 'optparse'
|
11
|
+
|
12
|
+
# Parse arguments
|
13
|
+
options = {
|
14
|
+
:builders => [],
|
15
|
+
:output => "output"
|
16
|
+
}
|
17
|
+
|
18
|
+
OptionParser.new do |opts|
|
19
|
+
opts.banner = "Usage: veewee-to-packer [options] TEMPLATE"
|
20
|
+
|
21
|
+
opts.on("--builder x,y,z", Array, "Builders to output template for.") do |builders|
|
22
|
+
options[:builders] = builders
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("-o", "--output DIR", String, "Directory where files will be outputted.") do |output|
|
26
|
+
options[:output] = output
|
27
|
+
end
|
28
|
+
end.parse!
|
29
|
+
|
30
|
+
if ARGV.length != 1
|
31
|
+
$stderr.puts "ERROR: One argument must be given: the template to convert."
|
32
|
+
exit 1
|
33
|
+
end
|
34
|
+
|
35
|
+
# Do the actual conversion
|
36
|
+
require "veewee-to-packer"
|
37
|
+
begin
|
38
|
+
warnings = VeeweeToPacker.convert(ARGV[0], options[:output], options[:builders])
|
39
|
+
|
40
|
+
if !warnings.empty?
|
41
|
+
puts "There were some non-critical warnings during the conversion process."
|
42
|
+
puts "Your template will function despite these warnings, but they're noted"
|
43
|
+
puts "here so you can understand some aspects of the Veewee definition that"
|
44
|
+
puts "may not have carried over perfectly to the Packer template:"
|
45
|
+
puts
|
46
|
+
warnings.each do |warning|
|
47
|
+
puts "* #{warning}"
|
48
|
+
end
|
49
|
+
puts
|
50
|
+
end
|
51
|
+
|
52
|
+
puts "Success! Your Veewee definition was converted to a Packer template!"
|
53
|
+
puts "The template can be found in the `template.json` file in the output"
|
54
|
+
puts "directory: #{options[:output]}"
|
55
|
+
puts
|
56
|
+
puts "Please be sure to run `packer validate` against the new template"
|
57
|
+
puts "to verify settings are correct."
|
58
|
+
rescue VeeweeToPacker::Error => e
|
59
|
+
$stderr.puts "An error occurred:\n\n#{e}"
|
60
|
+
exit 1
|
61
|
+
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
module VeeweeToPacker
|
2
|
+
module Builders
|
3
|
+
class VirtualBox
|
4
|
+
GUESTOS_MAP ={
|
5
|
+
"Windows7_64"=>"Windows7_64",
|
6
|
+
"Windows7"=>"Windows7",
|
7
|
+
"Windows8"=>"Windows8",
|
8
|
+
"Windows8_64"=>"Windows8_64",
|
9
|
+
"WindowsNT"=>"WindowsNT",
|
10
|
+
"Windows2008"=>"Windows2008",
|
11
|
+
"Windows2008_64"=>"Windows2008_64",
|
12
|
+
"WindowsVista_64"=>"WindowsVista_64",
|
13
|
+
"WindowsVista"=>"WindowsVista",
|
14
|
+
"Windows2003"=>"Windows2003",
|
15
|
+
"Windows2003_64"=>"Windows2003_64",
|
16
|
+
"WindowsXP_64"=>"WindowsXP_64",
|
17
|
+
"WindowsXP"=>"WindowsXP",
|
18
|
+
"Windows2000"=>"Windows200",
|
19
|
+
"WindowsNT4"=>"WindowsNT4",
|
20
|
+
"WindowsMe"=>"WindowsMe",
|
21
|
+
"Windows98"=>"Windows98",
|
22
|
+
"Windows95"=>"Windows95",
|
23
|
+
"Windows31"=>"Windows31",
|
24
|
+
"Other"=>"Other",
|
25
|
+
"Other_64"=>"Other_64",
|
26
|
+
"FreeBSD"=>"FreeBSD",
|
27
|
+
"FreeBSD_64"=>"FreeBSD_64",
|
28
|
+
"Oracle"=>"Oracle",
|
29
|
+
"Oracle_64"=>"Oracle_64",
|
30
|
+
"Debian"=>"Debian",
|
31
|
+
"Debian_64"=>"Debian_64",
|
32
|
+
"Debian6"=>"Debian",
|
33
|
+
"Debian6_64"=>"Debian_64",
|
34
|
+
"Gentoo"=>"Gentoo",
|
35
|
+
"Gentoo_64"=>"Gentoo_64",
|
36
|
+
"Linux22"=>"Linux22",
|
37
|
+
"Linux24"=>"Linux24",
|
38
|
+
"Linux24_64"=>"Linux24_64",
|
39
|
+
"Linux26"=>"Linux26",
|
40
|
+
"Linux26_64"=>"Linux26_64",
|
41
|
+
"RedHat"=>"RedHat",
|
42
|
+
"RedHat_64"=>"RedHat_64",
|
43
|
+
"RedHat5"=>"RedHat",
|
44
|
+
"RedHat5_64"=>"RedHat_64",
|
45
|
+
"RedHat6"=>"RedHat",
|
46
|
+
"RedHat6_64"=>"RedHat_64",
|
47
|
+
"Centos"=>"RedHat",
|
48
|
+
"Centos_64"=>"RedHat_64",
|
49
|
+
"ArchLinux"=>"ArchLinux",
|
50
|
+
"ArchLinux_64"=>"ArchLinux_64",
|
51
|
+
"OpenSUSE"=>"OpenSUSE",
|
52
|
+
"OpenSUSE_64"=>"OpenSUSE_64",
|
53
|
+
"SUSE"=>"OpenSUSE",
|
54
|
+
"SUSE_64"=>"OpenSUSE_64",
|
55
|
+
"Fedora"=>"Fedora",
|
56
|
+
"Fedora_64"=>"Fedora_64",
|
57
|
+
"Ubuntu"=>"Ubuntu",
|
58
|
+
"Ubuntu_64"=>"Ubuntu_64",
|
59
|
+
"Linux"=>"Linux",
|
60
|
+
"Solaris"=>"Solaris",
|
61
|
+
"Solaris_64"=>"Solaris_64",
|
62
|
+
"Solaris9"=>"Solaris",
|
63
|
+
"Solaris7"=>"Solaris",
|
64
|
+
"Solaris8"=>"Solaris",
|
65
|
+
"OpenSolaris"=>"OpenSolaris",
|
66
|
+
"OpenSolaris_64"=>"OpenSolaris_64",
|
67
|
+
"OpenBSD"=>"OpenBSD",
|
68
|
+
"OpenBSD_64"=>"OpenBSD_64",
|
69
|
+
"NetBSD"=>"NetBSD",
|
70
|
+
"NetBSD_64"=>"NetBSD_64"
|
71
|
+
}
|
72
|
+
|
73
|
+
def self.name
|
74
|
+
"virtualbox"
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.convert(input, input_dir, output_dir)
|
78
|
+
warnings =[]
|
79
|
+
builder = { "type" => "virtualbox" }
|
80
|
+
|
81
|
+
if input[:boot_cmd_sequence]
|
82
|
+
builder["boot_command"] = input.delete(:boot_cmd_sequence).map do |command|
|
83
|
+
command = command.gsub("<Esc>", "<esc>").
|
84
|
+
gsub("<Enter>", "<enter>").
|
85
|
+
gsub("<Return>", "<return>").
|
86
|
+
gsub("<Tab>", "<tab>").
|
87
|
+
gsub("%IP%", "{{ .HTTPIP }}").
|
88
|
+
gsub("%PORT%", "{{ .HTTPPort }}")
|
89
|
+
|
90
|
+
# We insert a wait after every command because that is the behavior
|
91
|
+
# of Veewee
|
92
|
+
"#{command}<wait>"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
if input[:boot_wait]
|
97
|
+
builder["boot_wait"] = "#{input.delete(:boot_wait)}s"
|
98
|
+
end
|
99
|
+
|
100
|
+
if input[:disk_size]
|
101
|
+
builder["disk_size"] = input.delete(:disk_size).to_i
|
102
|
+
end
|
103
|
+
|
104
|
+
if input[:os_type_id]
|
105
|
+
guestos_id = input.delete(:os_type_id)
|
106
|
+
guestos = GUESTOS_MAP[guestos_id]
|
107
|
+
if !guestos
|
108
|
+
guestos = "other"
|
109
|
+
warnings << "Unknown guest OS type: '#{guestos_id}'. Using 'other'."
|
110
|
+
end
|
111
|
+
|
112
|
+
builder["guest_os_type"] = guestos
|
113
|
+
end
|
114
|
+
|
115
|
+
if input[:kickstart_file]
|
116
|
+
http_dir = output_dir.join("http")
|
117
|
+
http_dir.mkpath
|
118
|
+
|
119
|
+
kickstart_file = input.delete(:kickstart_file)
|
120
|
+
kickstart_file = [kickstart_file] if !kickstart_file.is_a?(Array)
|
121
|
+
|
122
|
+
kickstart_file.each do |single_file|
|
123
|
+
kickstart_file_src = Pathname.new(File.expand_path(single_file, input_dir))
|
124
|
+
kickstart_file_dest = http_dir.join(kickstart_file_src.basename)
|
125
|
+
FileUtils.cp(kickstart_file_src, kickstart_file_dest)
|
126
|
+
end
|
127
|
+
|
128
|
+
builder["http_directory"] = "http"
|
129
|
+
end
|
130
|
+
|
131
|
+
if input[:iso_download_instructions]
|
132
|
+
warnings << "ISO download instructions: #{input.delete(:iso_download_instructions)}"
|
133
|
+
end
|
134
|
+
|
135
|
+
builder["iso_md5"] = input.delete(:iso_md5)
|
136
|
+
builder["iso_url"] = input.delete(:iso_src)
|
137
|
+
|
138
|
+
builder["ssh_username"] = input.delete(:ssh_user) if input[:ssh_user]
|
139
|
+
builder["ssh_password"] = input.delete(:ssh_password) if input[:ssh_password]
|
140
|
+
builder["ssh_port"] = input.delete(:ssh_guest_port).to_i if input[:ssh_guest_port]
|
141
|
+
builder["ssh_wait_timeout"] = "#{input.delete(:ssh_login_timeout)}s" if input[:ssh_login_timeout]
|
142
|
+
|
143
|
+
builder["shutdown_command"] = input.delete(:shutdown_cmd) if input[:shutdown_cmd]
|
144
|
+
if builder["shutdown_command"] && input[:sudo_cmd]
|
145
|
+
sudo_command = input.delete(:sudo_cmd).
|
146
|
+
gsub("%p", builder["ssh_password"]).
|
147
|
+
gsub("%f", "shutdown.sh")
|
148
|
+
|
149
|
+
builder["shutdown_command"] = "echo '#{builder["shutdown_command"]}' > shutdown.sh; #{sudo_command}"
|
150
|
+
end
|
151
|
+
|
152
|
+
builder["guest_additions_path"] = "VBoxGuestAdditions_{{.Version}}.iso"
|
153
|
+
builder["virtualbox_version_file"] = ".vbox_version"
|
154
|
+
|
155
|
+
builder["vboxmanage"] = []
|
156
|
+
|
157
|
+
if input[:memory_size]
|
158
|
+
builder["vboxmanage"] << [
|
159
|
+
"modifyvm", "{{.Name}}", "--memory", input.delete(:memory_size)]
|
160
|
+
end
|
161
|
+
|
162
|
+
if input[:cpu_count]
|
163
|
+
builder["vboxmanage"] << [
|
164
|
+
"modifyvm", "{{.Name}}", "--cpus", input.delete(:cpu_count)]
|
165
|
+
end
|
166
|
+
|
167
|
+
# Taken directly from Veewee, all the flags that VirtualBox definitions
|
168
|
+
# can have.
|
169
|
+
vm_flags = %w{pagefusion acpi ioapic pae hpet hwvirtex hwvirtexcl nestedpaging largepages vtxvpid synthxcpu rtcuseutc}
|
170
|
+
vm_flags.each do |flag|
|
171
|
+
if input[flag.to_sym]
|
172
|
+
builder["vboxmanage"] << [
|
173
|
+
"modifyvm", "{{.Name}}",
|
174
|
+
"--#{flag}",
|
175
|
+
input.delete(flag.to_sym)
|
176
|
+
]
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# These are unused, so just ignore them.
|
181
|
+
input.delete(:disk_format)
|
182
|
+
input.delete(:hostiocache)
|
183
|
+
input.delete(:kickstart_port)
|
184
|
+
input.delete(:kickstart_timeout)
|
185
|
+
input.delete(:iso_download_timeout)
|
186
|
+
input.delete(:iso_file)
|
187
|
+
input.delete(:ssh_host_port)
|
188
|
+
input.delete(:ssh_key)
|
189
|
+
|
190
|
+
if input.length > 0
|
191
|
+
raise Error, "Uknown keys: #{input.keys.sort.inspect}"
|
192
|
+
end
|
193
|
+
|
194
|
+
[builder, warnings]
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
module VeeweeToPacker
|
4
|
+
module Builders
|
5
|
+
class VMware
|
6
|
+
GUESTOS_MAP ={
|
7
|
+
"Windows7_64"=>"windows7-64",
|
8
|
+
"Windows7"=>"windows7",
|
9
|
+
"WindowsNT"=>"winNT",
|
10
|
+
"Windows2008"=>"longhorn",
|
11
|
+
"Windows2008_64"=>"longhorn-64",
|
12
|
+
"WindowsVista_64"=>"winvista-64",
|
13
|
+
"WindowsVista"=>"winvista",
|
14
|
+
"Windows2003"=>"winnetstandard",
|
15
|
+
"Windows2003_64"=>"winnetstandard-64",
|
16
|
+
"WindowsXP_64"=>"winXPPro-64",
|
17
|
+
"WindowsXP"=>"winXP",
|
18
|
+
"Other"=>"other",
|
19
|
+
"Other_64"=>"other-64",
|
20
|
+
"FreeBSD"=>"freeBSD",
|
21
|
+
"FreeBSD_64"=>"freebsd-64",
|
22
|
+
"Oracle"=>"oraclelinux",
|
23
|
+
"Oracle_64"=>"oraclelinux-64",
|
24
|
+
"Debian"=>"debian5",
|
25
|
+
"Debian_64"=>"debian5-64",
|
26
|
+
"Debian6"=>"debian6",
|
27
|
+
"Debian6_64"=>"debian6-64",
|
28
|
+
"Gentoo"=>"other26xlinux",
|
29
|
+
"Gentoo_64"=>"other26xlinux-64",
|
30
|
+
"Linux22"=>"linux",
|
31
|
+
"Linux24"=>"other24xlinux",
|
32
|
+
"Linux24_64"=>"other24xlinux-64",
|
33
|
+
"Linux26"=>"other26xlinux",
|
34
|
+
"Linux26_64"=>"other26xlinux-64",
|
35
|
+
"RedHat"=>"RedHat",
|
36
|
+
"RedHat_64"=>"RedHat_64",
|
37
|
+
"RedHat5"=>"rhel5",
|
38
|
+
"RedHat5_64"=>"rhel5-64",
|
39
|
+
"RedHat6"=>"rhel6",
|
40
|
+
"RedHat6_64"=>"rhel6-64",
|
41
|
+
"Centos"=>"centos",
|
42
|
+
"Centos_64"=>"centos-64",
|
43
|
+
"ArchLinux"=>"other26xlinux",
|
44
|
+
"ArchLinux_64"=>"other26xlinux-64",
|
45
|
+
"OpenSUSE"=>"opensuse",
|
46
|
+
"OpenSUSE_64"=>"opensuse-64",
|
47
|
+
"SUSE"=>"suse",
|
48
|
+
"SUSE_64"=>"suse-64",
|
49
|
+
"SLES11"=>"sles11",
|
50
|
+
"SLES11_64"=>"sles11-64",
|
51
|
+
"Fedora"=>"fedora",
|
52
|
+
"Fedora_64"=>"fedora-64",
|
53
|
+
"Ubuntu"=>"ubuntu",
|
54
|
+
"Ubuntu_64"=>"ubuntu-64",
|
55
|
+
"Linux"=>"linux",
|
56
|
+
"Solaris"=>"solaris10",
|
57
|
+
"Solaris_64"=>"solaris10-64",
|
58
|
+
"Solaris9"=>"solaris",
|
59
|
+
"Solaris7"=>"solaris7",
|
60
|
+
"Solaris8"=>"solaris8",
|
61
|
+
"OpenSolaris"=>"solaris10",
|
62
|
+
"OpenSolaris_64"=>"solaris-64",
|
63
|
+
"OpenBSD"=>"other",
|
64
|
+
"OpenBSD_64"=>"other-64",
|
65
|
+
"NetBSD"=>"other",
|
66
|
+
"NetBSD_64"=>"other-64",
|
67
|
+
"ESXi5"=>"vmkernel5",
|
68
|
+
"Darwin_10_7"=>"darwin11",
|
69
|
+
"Darwin_10_7_64"=>"darwin11-64",
|
70
|
+
"Darwin_10_8_64"=>"darwin12-64"
|
71
|
+
}
|
72
|
+
|
73
|
+
def self.name
|
74
|
+
"vmware"
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.convert(input, input_dir, output_dir)
|
78
|
+
warnings = []
|
79
|
+
builder = { "type" => "vmware" }
|
80
|
+
|
81
|
+
if input[:boot_cmd_sequence]
|
82
|
+
builder["boot_command"] = input.delete(:boot_cmd_sequence).map do |command|
|
83
|
+
command = command.gsub("<Esc>", "<esc>").
|
84
|
+
gsub("<Enter>", "<enter>").
|
85
|
+
gsub("<Return>", "<return>").
|
86
|
+
gsub("<Tab>", "<tab>").
|
87
|
+
gsub("%IP%", "{{ .HTTPIP }}").
|
88
|
+
gsub("%PORT%", "{{ .HTTPPort }}")
|
89
|
+
|
90
|
+
# We insert a wait after every command because that is the behavior
|
91
|
+
# of Veewee
|
92
|
+
"#{command}<wait>"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
if input[:boot_wait]
|
97
|
+
builder["boot_wait"] = "#{input.delete(:boot_wait)}s"
|
98
|
+
end
|
99
|
+
|
100
|
+
if input[:disk_size]
|
101
|
+
builder["disk_size"] = input.delete(:disk_size).to_i
|
102
|
+
end
|
103
|
+
|
104
|
+
if input[:os_type_id]
|
105
|
+
guestos_id = input.delete(:os_type_id)
|
106
|
+
guestos = GUESTOS_MAP[guestos_id]
|
107
|
+
if !guestos
|
108
|
+
guestos = "other"
|
109
|
+
warnings << "Unknown guest OS type: '#{guestos_id}'. Using 'other'."
|
110
|
+
end
|
111
|
+
|
112
|
+
builder["guest_os_type"] = guestos
|
113
|
+
end
|
114
|
+
|
115
|
+
if input[:kickstart_file]
|
116
|
+
http_dir = output_dir.join("http")
|
117
|
+
http_dir.mkpath
|
118
|
+
|
119
|
+
kickstart_file = input.delete(:kickstart_file)
|
120
|
+
kickstart_file = [kickstart_file] if !kickstart_file.is_a?(Array)
|
121
|
+
|
122
|
+
kickstart_file.each do |single_file|
|
123
|
+
kickstart_file_src = Pathname.new(File.expand_path(single_file, input_dir))
|
124
|
+
kickstart_file_dest = http_dir.join(kickstart_file_src.basename)
|
125
|
+
FileUtils.cp(kickstart_file_src, kickstart_file_dest)
|
126
|
+
end
|
127
|
+
|
128
|
+
builder["http_directory"] = "http"
|
129
|
+
end
|
130
|
+
|
131
|
+
if input[:iso_download_instructions]
|
132
|
+
warnings << "ISO download instructions: #{input.delete(:iso_download_instructions)}"
|
133
|
+
end
|
134
|
+
|
135
|
+
builder["iso_md5"] = input.delete(:iso_md5)
|
136
|
+
builder["iso_url"] = input.delete(:iso_src)
|
137
|
+
|
138
|
+
builder["ssh_username"] = input.delete(:ssh_user) if input[:ssh_user]
|
139
|
+
builder["ssh_password"] = input.delete(:ssh_password) if input[:ssh_password]
|
140
|
+
builder["ssh_port"] = input.delete(:ssh_guest_port).to_i if input[:ssh_guest_port]
|
141
|
+
builder["ssh_wait_timeout"] = "#{input.delete(:ssh_login_timeout)}s" if input[:ssh_login_timeout]
|
142
|
+
|
143
|
+
builder["shutdown_command"] = input.delete(:shutdown_cmd) if input[:shutdown_cmd]
|
144
|
+
if builder["shutdown_command"] && input[:sudo_cmd]
|
145
|
+
sudo_command = input.delete(:sudo_cmd).
|
146
|
+
gsub("%p", builder["ssh_password"]).
|
147
|
+
gsub("%f", "shutdown.sh")
|
148
|
+
|
149
|
+
builder["shutdown_command"] = "echo '#{builder["shutdown_command"]}' > shutdown.sh; #{sudo_command}"
|
150
|
+
end
|
151
|
+
|
152
|
+
builder["vmx_data"] = {}
|
153
|
+
|
154
|
+
if input[:memory_size]
|
155
|
+
builder["vmx_data"]["memsize"] = input.delete(:memory_size)
|
156
|
+
end
|
157
|
+
|
158
|
+
if input[:cpu_count]
|
159
|
+
builder["vmx_data"]["numvcpus"] = input.delete(:cpu_count)
|
160
|
+
builder["vmx_data"]["cpuid.coresPerSocket"] = "1"
|
161
|
+
end
|
162
|
+
|
163
|
+
# These are unused, so just ignore them.
|
164
|
+
input.delete(:disk_format)
|
165
|
+
input.delete(:ioapic)
|
166
|
+
input.delete(:kickstart_port)
|
167
|
+
input.delete(:kickstart_timeout)
|
168
|
+
input.delete(:hostiocache)
|
169
|
+
input.delete(:iso_download_timeout)
|
170
|
+
input.delete(:iso_file)
|
171
|
+
input.delete(:pae)
|
172
|
+
input.delete(:ssh_host_port)
|
173
|
+
input.delete(:ssh_key)
|
174
|
+
|
175
|
+
if input.length > 0
|
176
|
+
raise Error, "Uknown keys: #{input.keys.sort.inspect}"
|
177
|
+
end
|
178
|
+
|
179
|
+
[builder, warnings]
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file contains mocked out Veewee classes in order to load
|
2
|
+
# a Veewee definition into a format we like.
|
3
|
+
|
4
|
+
module Veewee
|
5
|
+
class Definition
|
6
|
+
@@captured = nil
|
7
|
+
|
8
|
+
def self.captured
|
9
|
+
@@captured
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.declare(options)
|
13
|
+
@@captured = options
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Some templates also use "Veewee::Session" so we just alias that
|
18
|
+
# to the same thing.
|
19
|
+
Session = Definition
|
20
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "json"
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
require "veewee-to-packer/builders/virtualbox"
|
6
|
+
require "veewee-to-packer/builders/vmware"
|
7
|
+
require "veewee-to-packer/error"
|
8
|
+
require "veewee-to-packer/mock_veewee"
|
9
|
+
require "veewee-to-packer/version"
|
10
|
+
|
11
|
+
module VeeweeToPacker
|
12
|
+
BUILDERS = {
|
13
|
+
"virtualbox" => Builders::VirtualBox,
|
14
|
+
"vmware" => Builders::VMware
|
15
|
+
}
|
16
|
+
|
17
|
+
# Converts the given Veewee template into a Packer template, outputting
|
18
|
+
# the JSON to the given output path. The builders that the template will
|
19
|
+
# contain is specified by `builders`.
|
20
|
+
def self.convert(input, output, builders)
|
21
|
+
builders = builders.map do |builder|
|
22
|
+
klass = BUILDERS[builder.downcase]
|
23
|
+
raise Error, "No such builder: #{builder}" if !klass
|
24
|
+
klass
|
25
|
+
end
|
26
|
+
|
27
|
+
# Make the output directory
|
28
|
+
output = Pathname.new(output)
|
29
|
+
output.mkpath
|
30
|
+
|
31
|
+
# Determine the directory where the template is
|
32
|
+
input_dir = Pathname.new(input).parent
|
33
|
+
|
34
|
+
# Load the definition file and capture its configuration
|
35
|
+
begin
|
36
|
+
load input
|
37
|
+
rescue LoadError => e
|
38
|
+
raise Error, "Error loading input template: #{e}"
|
39
|
+
end
|
40
|
+
|
41
|
+
definition = Veewee::Definition.captured
|
42
|
+
|
43
|
+
# This will keep track of any warnings (errors are raised) that
|
44
|
+
# we have during the conversion process.
|
45
|
+
warnings = []
|
46
|
+
|
47
|
+
# This will be the packer template contents that we'll turn to JSON
|
48
|
+
template = {}
|
49
|
+
|
50
|
+
# First, convert the postinstall_files into a shell provisioning step
|
51
|
+
if definition[:postinstall_files]
|
52
|
+
provisioner = { "type" => "shell" }
|
53
|
+
provisioner["scripts"] = definition.delete(:postinstall_files).map do |script|
|
54
|
+
scripts_dir = output.join("scripts")
|
55
|
+
scripts_dir.mkpath
|
56
|
+
|
57
|
+
script_file_src = Pathname.new(File.expand_path(script, input_dir))
|
58
|
+
script_file_dest = scripts_dir.join(script_file_src.basename)
|
59
|
+
|
60
|
+
FileUtils.cp(script_file_src, script_file_dest)
|
61
|
+
|
62
|
+
"scripts/#{script_file_dest.basename}"
|
63
|
+
end
|
64
|
+
|
65
|
+
if definition[:sudo_cmd]
|
66
|
+
override = {}
|
67
|
+
provisioner["override"] = override
|
68
|
+
|
69
|
+
builders.each do |builder|
|
70
|
+
execute_command = definition[:sudo_cmd].
|
71
|
+
gsub("%p", definition[:ssh_password]).
|
72
|
+
gsub("%f", "{{.Path}}")
|
73
|
+
|
74
|
+
override[builder.name] = {
|
75
|
+
"execute_command" => execute_command
|
76
|
+
}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
template["provisioners"] = [provisioner]
|
81
|
+
|
82
|
+
# Unused fields
|
83
|
+
if definition[:postinstall_timeout]
|
84
|
+
definition.delete(:postinstall_timeout)
|
85
|
+
warnings << "':postinstall_timeout' doesn't exist in Packer."
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Some overall things
|
90
|
+
if definition[:hooks]
|
91
|
+
definition.delete(:hooks)
|
92
|
+
warnings << ":hooks are not supported by Packer."
|
93
|
+
end
|
94
|
+
|
95
|
+
if definition[:params]
|
96
|
+
definition.delete(:params)
|
97
|
+
warnings << ":params are not supported by Packer."
|
98
|
+
end
|
99
|
+
|
100
|
+
# Build the builders
|
101
|
+
template["builders"] = builders.map do |builder|
|
102
|
+
config, build_warnings = builder.convert(definition.dup, input_dir, output)
|
103
|
+
if build_warnings && !build_warnings.empty?
|
104
|
+
build_warnings.each do |warning|
|
105
|
+
warnings << "Builder '#{builder.name}': #{warning}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
config
|
110
|
+
end
|
111
|
+
|
112
|
+
output.join("template.json").open("w") do |f|
|
113
|
+
f.write(JSON.pretty_generate(template))
|
114
|
+
end
|
115
|
+
|
116
|
+
warnings
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'veewee-to-packer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "veewee-to-packer"
|
8
|
+
gem.version = VeeweeToPacker::VERSION
|
9
|
+
gem.authors = ["Mitchell Hashimoto"]
|
10
|
+
gem.email = ["mitchell.hashimoto@gmail.com"]
|
11
|
+
gem.description = %q{Converts Veewee templates to Packer templates.}
|
12
|
+
gem.summary = %q{Converts Veewee templates to Packer templates perfectly.}
|
13
|
+
gem.homepage = "https://github.com/mitchellh/veewee-to-packer"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: veewee-to-packer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mitchell Hashimoto
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-28 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Converts Veewee templates to Packer templates.
|
15
|
+
email:
|
16
|
+
- mitchell.hashimoto@gmail.com
|
17
|
+
executables:
|
18
|
+
- veewee-to-packer
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- bin/veewee-to-packer
|
28
|
+
- lib/veewee-to-packer.rb
|
29
|
+
- lib/veewee-to-packer/builders/virtualbox.rb
|
30
|
+
- lib/veewee-to-packer/builders/vmware.rb
|
31
|
+
- lib/veewee-to-packer/error.rb
|
32
|
+
- lib/veewee-to-packer/mock_veewee.rb
|
33
|
+
- lib/veewee-to-packer/version.rb
|
34
|
+
- veewee-to-packer.gemspec
|
35
|
+
homepage: https://github.com/mitchellh/veewee-to-packer
|
36
|
+
licenses: []
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.8.23
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: Converts Veewee templates to Packer templates perfectly.
|
59
|
+
test_files: []
|
60
|
+
has_rdoc:
|