PackerFiles 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/PackerFiles.gemspec +36 -0
- data/README.md +32 -0
- data/Rakefile +21 -0
- data/bin/pkf +5 -0
- data/lib/PackerFiles/CLI/OS.rb +44 -0
- data/lib/PackerFiles/CLI/Root.rb +41 -0
- data/lib/PackerFiles/Core/Base.rb +23 -0
- data/lib/PackerFiles/Core/CDImage.rb +185 -0
- data/lib/PackerFiles/Core/Disk.rb +135 -0
- data/lib/PackerFiles/Core/Exceptions.rb +65 -0
- data/lib/PackerFiles/Core/Hypervisor.rb +96 -0
- data/lib/PackerFiles/Core/Keyboard.rb +38 -0
- data/lib/PackerFiles/Core/Locale.rb +62 -0
- data/lib/PackerFiles/Core/LogicalVolume.rb +41 -0
- data/lib/PackerFiles/Core/Network.rb +67 -0
- data/lib/PackerFiles/Core/Packages.rb +30 -0
- data/lib/PackerFiles/Core/Partition.rb +41 -0
- data/lib/PackerFiles/Core/TimeZone.rb +45 -0
- data/lib/PackerFiles/Core/User.rb +46 -0
- data/lib/PackerFiles/Core/VolumeGroup.rb +50 -0
- data/lib/PackerFiles/Core/example/CDImage.txt +75 -0
- data/lib/PackerFiles/Core/example/Disk.txt +29 -0
- data/lib/PackerFiles/Core/example/Hypervisor.txt +111 -0
- data/lib/PackerFiles/Core/example/Keyboard.txt +28 -0
- data/lib/PackerFiles/Core/example/Locale.txt +31 -0
- data/lib/PackerFiles/Core/example/Network.txt +68 -0
- data/lib/PackerFiles/Core/example/Packages.txt +22 -0
- data/lib/PackerFiles/Core/example/TimeZone.txt +36 -0
- data/lib/PackerFiles/Core/example/User.txt +48 -0
- data/lib/PackerFiles/OS/Builder.rb +116 -0
- data/lib/PackerFiles/OS/CentOS/CD.rb +81 -0
- data/lib/PackerFiles/OS/CentOS/Kickstart.rb +64 -0
- data/lib/PackerFiles/OS/CentOS/Server.rb +170 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Base_erb.rb +4 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Disk_erb.rb +35 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Keyboard_erb.rb +4 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Locale_erb.rb +4 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Network_erb.rb +17 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Packages_erb.rb +34 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Tail_erb.rb +15 -0
- data/lib/PackerFiles/OS/CentOS/Templates/TimeZone_erb.rb +10 -0
- data/lib/PackerFiles/OS/CentOS/Templates/User_erb.rb +20 -0
- data/lib/PackerFiles/OS/CentOS/Templates/boot_command_erb.rb +16 -0
- data/lib/PackerFiles/OS/CentOS/Templates/command_as_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/CentOS/Templates/disable_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/CentOS/Templates/enable_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/CentOS/Templates/shutdown_command_erb.rb +1 -0
- data/lib/PackerFiles/OS/Debian/Apt.rb +42 -0
- data/lib/PackerFiles/OS/Debian/CD.rb +65 -0
- data/lib/PackerFiles/OS/Debian/Mirrors.rb +73 -0
- data/lib/PackerFiles/OS/Debian/Preseed.rb +64 -0
- data/lib/PackerFiles/OS/Debian/Server.rb +169 -0
- data/lib/PackerFiles/OS/Debian/Templates/Apt_erb.rb +18 -0
- data/lib/PackerFiles/OS/Debian/Templates/Disk_erb.rb +69 -0
- data/lib/PackerFiles/OS/Debian/Templates/Keyboard_erb.rb +5 -0
- data/lib/PackerFiles/OS/Debian/Templates/Locale_erb.rb +7 -0
- data/lib/PackerFiles/OS/Debian/Templates/Mirrors_erb.rb +9 -0
- data/lib/PackerFiles/OS/Debian/Templates/Network_erb.rb +19 -0
- data/lib/PackerFiles/OS/Debian/Templates/Packages_erb.rb +6 -0
- data/lib/PackerFiles/OS/Debian/Templates/TimeZone_erb.rb +6 -0
- data/lib/PackerFiles/OS/Debian/Templates/User_erb.rb +14 -0
- data/lib/PackerFiles/OS/Debian/Templates/boot_command_erb.rb +24 -0
- data/lib/PackerFiles/OS/Debian/Templates/command_as_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/Debian/Templates/disable_root_erb.rb +5 -0
- data/lib/PackerFiles/OS/Debian/Templates/enable_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/Debian/Templates/shutdown_command_erb.rb +1 -0
- data/lib/PackerFiles/OS/Debian/example/Apt.txt +55 -0
- data/lib/PackerFiles/OS/DocGenerator.rb +51 -0
- data/lib/PackerFiles/OS/Finder.rb +96 -0
- data/lib/PackerFiles/OS/RHEL/CD.rb +32 -0
- data/lib/PackerFiles/OS/RHEL/Fedora.rb +59 -0
- data/lib/PackerFiles/OS/RHEL/FedoraCD.rb +68 -0
- data/lib/PackerFiles/OS/RHEL/Server.rb +32 -0
- data/lib/PackerFiles/OS/RHEL/Templates/Fedora_Tail_erb.rb +14 -0
- data/lib/PackerFiles/OS/RHEL/Templates/boot_command_fedora_erb.rb +16 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Base_erb.xml +32 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Disk_erb.xml +110 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Keyboard_erb.xml +7 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Locale_erb.xml +18 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Network_erb.xml +143 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Packages_erb.xml +29 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Tail_erb.xml +4 -0
- data/lib/PackerFiles/OS/SUSE/Templates/TimeZone_erb.xml +15 -0
- data/lib/PackerFiles/OS/SUSE/Templates/User_erb.xml +57 -0
- data/lib/PackerFiles/OS/SUSE/Templates/boot_command_erb.rb +23 -0
- data/lib/PackerFiles/OS/SUSE/Templates/command_as_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/SUSE/Templates/disable_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/SUSE/Templates/enable_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/SUSE/Templates/shutdown_command_erb.rb +1 -0
- data/lib/PackerFiles/OS/Ubuntu/CD.rb +81 -0
- data/lib/PackerFiles/OS/Ubuntu/Desktop.rb +50 -0
- data/lib/PackerFiles/OS/Ubuntu/DesktopCD.rb +16 -0
- data/lib/PackerFiles/OS/Ubuntu/Mirrors.rb +103 -0
- data/lib/PackerFiles/OS/Ubuntu/Server.rb +78 -0
- data/lib/PackerFiles/OS/Ubuntu/Templates/Apt_erb.rb +18 -0
- data/lib/PackerFiles/OS/Ubuntu/Templates/boot_command_desktop_erb.rb +36 -0
- data/lib/PackerFiles/OS/Ubuntu/Templates/boot_command_erb.rb +30 -0
- data/lib/PackerFiles/OS/Ubuntu/Templates/ubiquity_erb.rb +8 -0
- data/lib/PackerFiles/OS/example/Doc.txt +8 -0
- data/lib/PackerFiles/Provision/Base.rb +20 -0
- data/lib/PackerFiles/Provision/ChefSolo.rb +90 -0
- data/lib/PackerFiles/Provision/ChefSoloHelper.rb +72 -0
- data/lib/PackerFiles/Provision/Copy.rb +22 -0
- data/lib/PackerFiles/Provision/ExternalScript.rb +43 -0
- data/lib/PackerFiles/Provision/InlineScript.rb +37 -0
- data/lib/PackerFiles/Provision/Provisioners.rb +87 -0
- data/lib/PackerFiles/Provision/example/Provisioners.txt +21 -0
- data/lib/PackerFiles/Utils/AutoZone.rb +96 -0
- data/lib/PackerFiles/Utils/FastestURL.rb +73 -0
- data/lib/PackerFiles/Utils/Generator.rb +34 -0
- data/lib/PackerFiles/Utils/HashSerializer.rb +110 -0
- data/lib/PackerFiles/Utils/Size.rb +44 -0
- data/lib/PackerFiles/Utils/TypeAccessor.rb +71 -0
- data/lib/PackerFiles/Virtual/Hypervisors.rb +72 -0
- data/lib/PackerFiles/Virtual/KVM.rb +119 -0
- data/lib/PackerFiles/Virtual/KVMConverter.rb +79 -0
- data/lib/PackerFiles/Virtual/VMWare.rb +108 -0
- data/lib/PackerFiles/Virtual/VMWareConverter.rb +78 -0
- data/lib/PackerFiles/Virtual/VirtualBox.rb +98 -0
- data/lib/PackerFiles/Virtual/VirtualBoxConverter.rb +75 -0
- data/lib/PackerFiles/Virtual/example/Hypervisors.txt +23 -0
- data/lib/PackerFiles/version.rb +3 -0
- data/lib/PackerFiles.rb +44 -0
- data/spec/core/builder_spec.rb +84 -0
- data/spec/core/cdimage_spec.rb +159 -0
- data/spec/core/disk_spec.rb +191 -0
- data/spec/core/keyboard_spec.rb +36 -0
- data/spec/core/locale_spec.rb +73 -0
- data/spec/core/network_spec.rb +96 -0
- data/spec/core/packages_spec.rb +18 -0
- data/spec/core/timezone_spec.rb +43 -0
- data/spec/core/user_spec.rb +44 -0
- data/spec/core/volume_group_spec.rb +53 -0
- data/spec/os/centos/cd_spec.rb +12 -0
- data/spec/os/centos/data/Server-Script-Provisioner.rb +57 -0
- data/spec/os/centos/data/Server.rb +55 -0
- data/spec/os/centos/data/chef-solo-provisioner.rb +58 -0
- data/spec/os/centos/finder_spec.rb +22 -0
- data/spec/os/centos/templates/boot_command_spec.rb +57 -0
- data/spec/os/centos/templates/disk_spec.rb +79 -0
- data/spec/os/centos/templates/keyboard_spec.rb +18 -0
- data/spec/os/centos/templates/locale_spec.rb +26 -0
- data/spec/os/centos/templates/network_spec.rb +38 -0
- data/spec/os/centos/templates/packages_spec.rb +18 -0
- data/spec/os/centos/templates/timezone_spec.rb +37 -0
- data/spec/os/centos/templates/user_spec.rb +24 -0
- data/spec/os/debian/apt_spec.rb +50 -0
- data/spec/os/debian/cd_spec.rb +30 -0
- data/spec/os/debian/data/7zip.tar.gz +0 -0
- data/spec/os/debian/data/All-sections.rb +60 -0
- data/spec/os/debian/data/Chef-Solo-Provisioner.rb +60 -0
- data/spec/os/debian/data/Copy-Provisioner.rb +61 -0
- data/spec/os/debian/data/External-Script-Provisioner.rb +69 -0
- data/spec/os/debian/data/Missing-CDImage.rb +53 -0
- data/spec/os/debian/data/Missing-VMWare-KVM-sections.rb +51 -0
- data/spec/os/debian/data/Missing-sections.rb +53 -0
- data/spec/os/debian/data/Script-Provisioner.rb +62 -0
- data/spec/os/debian/data/chef-solo-cookbooks/git_setup/Berksfile.lock +32 -0
- data/spec/os/debian/data/chef-solo-cookbooks/git_setup/README.md +81 -0
- data/spec/os/debian/data/chef-solo-cookbooks/git_setup/attributes/default.rb +3 -0
- data/spec/os/debian/data/chef-solo-cookbooks/git_setup/metadata.rb +11 -0
- data/spec/os/debian/data/chef-solo-cookbooks/git_setup/recipes/default.rb +30 -0
- data/spec/os/debian/data/chef-solo.json +5 -0
- data/spec/os/debian/data/test-script.sh +4 -0
- data/spec/os/debian/finder_spec.rb +59 -0
- data/spec/os/debian/mirrors_spec.rb +18 -0
- data/spec/os/debian/preseed_spec.rb +56 -0
- data/spec/os/debian/server_spec.rb +59 -0
- data/spec/os/debian/templates/apt_spec.rb +20 -0
- data/spec/os/debian/templates/boot_command_spec.rb +56 -0
- data/spec/os/debian/templates/disk_spec.rb +81 -0
- data/spec/os/debian/templates/keyboard_spec.rb +18 -0
- data/spec/os/debian/templates/locale_spec.rb +36 -0
- data/spec/os/debian/templates/mirrors_spec.rb +16 -0
- data/spec/os/debian/templates/network_spec.rb +38 -0
- data/spec/os/debian/templates/packages_spec.rb +17 -0
- data/spec/os/debian/templates/timezone_spec.rb +36 -0
- data/spec/os/debian/templates/user_spec.rb +25 -0
- data/spec/os/finder_spec.rb +21 -0
- data/spec/os/rhel/data/Fedora.rb +45 -0
- data/spec/os/rhel/data/Server-Custom.rb +54 -0
- data/spec/os/rhel/data/Server.rb +45 -0
- data/spec/os/rhel/finder_spec.rb +21 -0
- data/spec/os/ubuntu/cd_spec.rb +28 -0
- data/spec/os/ubuntu/data/Desktop.rb +61 -0
- data/spec/os/ubuntu/data/Server.rb +61 -0
- data/spec/os/ubuntu/finder_spec.rb +17 -0
- data/spec/os/ubuntu/mirrors_spec.rb +18 -0
- data/spec/utils/autozone_spec.rb +33 -0
- data/spec/virtual/virtual_box_spec.rb +16 -0
- metadata +405 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed4d8bf7590cae12aeecfbea9800a7a74de39e43
|
4
|
+
data.tar.gz: 9189448e12badff0acb1fb2a8300f5d5fdd77d17
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4117c5b57a67a5f9e1ec59072dc79038bbb0edfa45d4462eee2acd5a303217fb6bf1c6d739edccd1428c0336dc21ac90581b46a6e3d7ee61e28aca7eede62547
|
7
|
+
data.tar.gz: a4f3c5f76406dc249f1a0c7bdd7c4e392f4ee554d2c3d0951b2139cecebfecb145e0091fc82d1217ac7d58972266dae73ffab58a213069e85f176f5b0a29fe0e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Anand Venkatanarayanan
|
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/PackerFiles.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'PackerFiles/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "PackerFiles"
|
8
|
+
spec.version = PackerFiles::VERSION
|
9
|
+
spec.authors = ["Anand Venkatanarayanan"]
|
10
|
+
spec.email = ["external_mails_anandv-github@yahoo.co.in"]
|
11
|
+
spec.description = %q{Generates Packer files based on a simple spec. file for certain configurations.}
|
12
|
+
spec.summary = %q{Generates Packer files based on a simple spec. file for certain configurations.}
|
13
|
+
spec.homepage = "https://github.com/anandvenkatanarayanan/PackerFiles/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib",
|
20
|
+
File.join("lib", spec.name),
|
21
|
+
File.join("lib", spec.name, "OS")
|
22
|
+
]
|
23
|
+
|
24
|
+
# Development dependencies
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rspec", "~> 2.6"
|
28
|
+
|
29
|
+
# Run Time dependencies
|
30
|
+
spec.add_runtime_dependency 'json'
|
31
|
+
spec.add_runtime_dependency 'erubis'
|
32
|
+
spec.add_runtime_dependency 'thor'
|
33
|
+
spec.add_runtime_dependency 'nokogiri'
|
34
|
+
|
35
|
+
end
|
36
|
+
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# PackerFiles
|
2
|
+
|
3
|
+
A Ruby library that can generate various files required for packer to work in a consistent manner without having to manually edit those files. It is mostly used for creating full fledged VM Images that run on top of a hypervisor and not for cloud environments like Amazon or Digital ocean.
|
4
|
+
|
5
|
+
An approximate specification for Packer File generator is in PackerFile.rb file at the root directory
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'PackerFiles'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install PackerFiles
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
# Create Rake Task for running all the test cases
|
5
|
+
RSpec::Core::RakeTask.new('test/all') do |test|
|
6
|
+
end
|
7
|
+
|
8
|
+
# Create Rake Task for running all the Core Test cases
|
9
|
+
RSpec::Core::RakeTask.new('test/core') do |test|
|
10
|
+
test.pattern = 'spec/core/*_spec.rb'
|
11
|
+
end
|
12
|
+
|
13
|
+
# Create Rake Task for running all the OS Test cases
|
14
|
+
RSpec::Core::RakeTask.new('test/os') do |test|
|
15
|
+
test.pattern = 'spec/os/**/**_spec.rb'
|
16
|
+
end
|
17
|
+
|
18
|
+
# Create Rake Task for running all the Hypervisor Test cases
|
19
|
+
RSpec::Core::RakeTask.new('test/virtual') do |test|
|
20
|
+
test.pattern = 'spec/virtual/**/**_spec.rb'
|
21
|
+
end
|
data/bin/pkf
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Requires
|
2
|
+
require 'thor'
|
3
|
+
require 'OS/Finder'
|
4
|
+
require 'OS/DocGenerator'
|
5
|
+
|
6
|
+
# Implement the CLI sub-commands for OS.
|
7
|
+
module PackerFiles
|
8
|
+
module CLI
|
9
|
+
class OS < Thor
|
10
|
+
|
11
|
+
# List all supported Operating systems.
|
12
|
+
desc "list", "list all supported operating systems"
|
13
|
+
def list
|
14
|
+
Finder.new.class_names.each do |cl|
|
15
|
+
name = cl.name.gsub('PackerFiles::','')
|
16
|
+
if cl.versions.empty?
|
17
|
+
versions = 'Any'
|
18
|
+
else
|
19
|
+
versions = cl.versions.to_s
|
20
|
+
end
|
21
|
+
puts "#{name} => #{versions}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Generate the documentation needed for a given class name
|
26
|
+
desc "init", "Create a Template file for the specified OS"
|
27
|
+
option :name, :required => true, :desc => 'OS Name', :type => :string
|
28
|
+
option :force, :desc => 'Overwrite existing File, if any', :type => :boolean,
|
29
|
+
:default => false
|
30
|
+
option :file, :desc => 'Output file name', :default => 'PackerFile',
|
31
|
+
:type => :string
|
32
|
+
def init
|
33
|
+
klass = Finder.new.class_name(options[:name])
|
34
|
+
if (File.exist?(options[:file]) && !options[:force])
|
35
|
+
$stderr.puts "Cannot overwrite #{options[:file]} w/o --force"
|
36
|
+
return 1
|
37
|
+
end
|
38
|
+
DocGenerator.new(klass, options[:file]).Generate
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Requires
|
2
|
+
require 'thor'
|
3
|
+
require_relative 'OS'
|
4
|
+
|
5
|
+
# The ROOT of all the CLI commands. Other Sub commands are
|
6
|
+
# declared as they go.
|
7
|
+
module PackerFiles
|
8
|
+
module CLI
|
9
|
+
class Root < Thor
|
10
|
+
|
11
|
+
# define sub-command for OS
|
12
|
+
desc "os SUBCOMMAND ...ARGS", "Commands on Supported OS"
|
13
|
+
subcommand "os", OS
|
14
|
+
|
15
|
+
# define the default task as generate
|
16
|
+
default_task :generate
|
17
|
+
|
18
|
+
# Default command that generates various artificats for Packer to
|
19
|
+
# work correctly.
|
20
|
+
desc "generate", "Generate Artificats for packer to work correctly"
|
21
|
+
option :defaults, :desc => 'Use Defaults for missing values',
|
22
|
+
:type => :boolean,
|
23
|
+
:default => false
|
24
|
+
option :file, :desc => 'OS Spec. File', :default => 'PackerFile',
|
25
|
+
:type => :string
|
26
|
+
def generate
|
27
|
+
if !File.exist?options[:file]
|
28
|
+
puts "File not found #{options[:file]}"
|
29
|
+
exit(1)
|
30
|
+
end
|
31
|
+
begin
|
32
|
+
load(options[:file])
|
33
|
+
rescue PackerFiles::Core::Error => e
|
34
|
+
puts "Error: #{e.message}"
|
35
|
+
exit(1)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
# Requires
|
3
|
+
require 'PackerFiles'
|
4
|
+
|
5
|
+
# Top level Module for this gem.
|
6
|
+
module PackerFiles
|
7
|
+
|
8
|
+
# Contains the Core classes/methods and everthing else.
|
9
|
+
module Core
|
10
|
+
|
11
|
+
# The Base class which defines interfaces that all PackerFile
|
12
|
+
# classes must adhere to
|
13
|
+
class Base
|
14
|
+
|
15
|
+
# Do nothing.
|
16
|
+
def normalize; end
|
17
|
+
|
18
|
+
# Return the name of the documentation file, for this class.
|
19
|
+
def self.doc_file; end
|
20
|
+
end
|
21
|
+
|
22
|
+
end # Core
|
23
|
+
end # PackerFiles
|
@@ -0,0 +1,185 @@
|
|
1
|
+
# Requires
|
2
|
+
require 'open-uri'
|
3
|
+
require 'uri'
|
4
|
+
require 'Core/Base'
|
5
|
+
require 'Core/Exceptions'
|
6
|
+
require 'Utils/FastestURL'
|
7
|
+
|
8
|
+
module PackerFiles
|
9
|
+
|
10
|
+
module Core
|
11
|
+
|
12
|
+
# Base class for CDImage implmentation
|
13
|
+
class CDImageImpl
|
14
|
+
|
15
|
+
# Return back the ISO name (It can be a regex pattern)
|
16
|
+
def get_iso_name_pattern
|
17
|
+
'.*'
|
18
|
+
end
|
19
|
+
|
20
|
+
# Return back the Checksum File Pattern (It can be a regex pattern)
|
21
|
+
def get_check_sum_pattern
|
22
|
+
'MD5SUM'
|
23
|
+
end
|
24
|
+
|
25
|
+
# Return back the Checksum File Pattern (It can be a regex pattern)
|
26
|
+
def get_check_sum_type
|
27
|
+
'md5'
|
28
|
+
end
|
29
|
+
|
30
|
+
# Return the list of index URLs.
|
31
|
+
def get_index_urls
|
32
|
+
[]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Used for figuring out the URLs and Checksum values for the installer images
|
37
|
+
# of debian.
|
38
|
+
class CDImage < Base
|
39
|
+
|
40
|
+
# Accessors that can be set.
|
41
|
+
attr_accessor :arch
|
42
|
+
attr_accessor :release
|
43
|
+
attr_accessor :iso_name_pattern
|
44
|
+
attr_accessor :check_sum_pattern
|
45
|
+
attr_accessor :check_sum_type
|
46
|
+
|
47
|
+
# Accessors that can be derived if not set
|
48
|
+
attr_accessor :index_urls
|
49
|
+
attr_accessor :iso_url
|
50
|
+
attr_accessor :check_sum
|
51
|
+
|
52
|
+
# Implementation class for CD Image.
|
53
|
+
attr_writer :impl
|
54
|
+
|
55
|
+
# Documentation for this class
|
56
|
+
def self.doc_file
|
57
|
+
PackerFiles.DirPath('Core/example/CDImage.txt').first
|
58
|
+
end
|
59
|
+
|
60
|
+
# Constructor that yields self for accessor settings.
|
61
|
+
def initialize
|
62
|
+
yield self if block_given?
|
63
|
+
end
|
64
|
+
|
65
|
+
# Overriden normalize
|
66
|
+
def normalize
|
67
|
+
|
68
|
+
# Do some basic checks.
|
69
|
+
raise NilException.new(self, 'arch') if @arch.nil?
|
70
|
+
raise NilException.new(self, 'release') if @release.nil?
|
71
|
+
|
72
|
+
# Get everything else.
|
73
|
+
set_iso_url_and_checksum
|
74
|
+
end
|
75
|
+
|
76
|
+
# Compute the ISO URL and Check SUM for the CD Image, but only if it is
|
77
|
+
# not defined already.
|
78
|
+
private
|
79
|
+
def set_iso_url_and_checksum
|
80
|
+
if @iso_url.nil? || @check_sum.nil?
|
81
|
+
set_iso_name_checksum_pattern
|
82
|
+
index_url, valid = fastest_url
|
83
|
+
if (valid)
|
84
|
+
(@iso_url, ck_url) = get_iso_checksum_url(index_url)
|
85
|
+
@check_sum = get_check_sum(ck_url)
|
86
|
+
else
|
87
|
+
@iso_url = URI::join(index_url, @iso_name_pattern).to_s
|
88
|
+
@check_sum_type = 'none'
|
89
|
+
@check_sum = ''
|
90
|
+
end
|
91
|
+
end
|
92
|
+
raise NilException.new(self, 'check_sum_type') if @check_sum_type.nil?
|
93
|
+
end
|
94
|
+
|
95
|
+
# Compute the ISO name of the CD Image from other variables, but only
|
96
|
+
# if it is not defined already.
|
97
|
+
def set_iso_name_checksum_pattern
|
98
|
+
if @iso_name_pattern.nil? && !@impl.nil?
|
99
|
+
name = @impl.get_iso_name_pattern
|
100
|
+
@iso_name_pattern = name.gsub('@release@', @release).gsub('@arch@', @arch)
|
101
|
+
end
|
102
|
+
if @check_sum_pattern.nil? && !@impl.nil?
|
103
|
+
name = @impl.get_check_sum_pattern
|
104
|
+
@check_sum_pattern = name.gsub('@release@', @release).gsub('@arch@', @arch)
|
105
|
+
end
|
106
|
+
if @check_sum_type.nil? && !@impl.nil?
|
107
|
+
@check_sum_type = @impl.get_check_sum_type
|
108
|
+
end
|
109
|
+
|
110
|
+
# Raise more errors if implementation does not fill values.
|
111
|
+
raise NilException.new(self, 'iso_name_pattern') if @iso_name_pattern.nil?
|
112
|
+
raise NilException.new(self, 'check_sum_pattern') if @check_sum_pattern.nil?
|
113
|
+
raise NilException.new(self, 'check_sum_type') if @check_sum_type.nil?
|
114
|
+
end
|
115
|
+
|
116
|
+
# Return the MD5 Checksum for the ISO URL
|
117
|
+
def get_check_sum(ck_url)
|
118
|
+
name = URI::parse(@iso_url).path.split('/').last
|
119
|
+
begin
|
120
|
+
open(ck_url) {|f|
|
121
|
+
f.each_line do |line|
|
122
|
+
if match = line.match(name)
|
123
|
+
return line.split(' ').first
|
124
|
+
end
|
125
|
+
end
|
126
|
+
}
|
127
|
+
rescue OpenURI::HTTPError => e
|
128
|
+
raise URLException.new(ck_url, e)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Return the full URL for the CD Image.
|
133
|
+
private
|
134
|
+
def get_iso_checksum_url(index_url)
|
135
|
+
iso_regex = "href=\"(#{@iso_name_pattern})\""
|
136
|
+
ck_regex = "href=\"(#{@check_sum_pattern})\""
|
137
|
+
iso_url = ''
|
138
|
+
ck_url = ''
|
139
|
+
open(index_url) {|f|
|
140
|
+
f.each_line do |line|
|
141
|
+
if match = line.match(iso_regex)
|
142
|
+
iso_url = URI::join(index_url, match[1]).to_s
|
143
|
+
end
|
144
|
+
if match = line.match(ck_regex)
|
145
|
+
ck_url = URI::join(index_url, match[1]).to_s
|
146
|
+
end
|
147
|
+
end
|
148
|
+
}
|
149
|
+
raise "Cannot find file matching #{@iso_name_pattern}" if iso_url.empty?
|
150
|
+
raise "Cannot find file matching #{@check_sum_pattern}" if ck_url.empty?
|
151
|
+
return iso_url, ck_url
|
152
|
+
end
|
153
|
+
|
154
|
+
# Get the Fastest Index URL from the list of curated index URLs
|
155
|
+
def fastest_url
|
156
|
+
|
157
|
+
# Slow URL = 5 seconds latency with a trial = 1
|
158
|
+
f = Utils::FastestURL.new(5.0, 1)
|
159
|
+
urls = curated_index_urls
|
160
|
+
raise EmptyArrayException.new(self, 'index_urls') if urls.empty?
|
161
|
+
all = f.best_urls(urls)
|
162
|
+
if all.empty?
|
163
|
+
return urls.first, false
|
164
|
+
else
|
165
|
+
return all.flatten.first, true
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Curate the URL list by replacing '@release@' with @release and '@arch'
|
170
|
+
# with @arch.
|
171
|
+
def curated_index_urls
|
172
|
+
@index_urls ||= @impl.index_urls if !@impl.nil?
|
173
|
+
raise NilException.new(self, 'index_urls') if @index_urls.nil?
|
174
|
+
raise EmptyArrayException.new(self, 'index_urls') if @index_urls.empty?
|
175
|
+
@index_urls.map! {|url|
|
176
|
+
url.gsub('@release@', @release).gsub('@arch@', @arch)
|
177
|
+
}
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
|
183
|
+
end # Core
|
184
|
+
|
185
|
+
end # PackerFiles
|
@@ -0,0 +1,135 @@
|
|
1
|
+
|
2
|
+
# Requires
|
3
|
+
require 'Utils/Size'
|
4
|
+
require_relative 'Base'
|
5
|
+
require_relative 'Partition'
|
6
|
+
require_relative 'VolumeGroup'
|
7
|
+
require_relative 'Exceptions'
|
8
|
+
|
9
|
+
module PackerFiles
|
10
|
+
|
11
|
+
module Core
|
12
|
+
|
13
|
+
# Define the Disk class that can handle disks specified in a Packerfile.
|
14
|
+
# Just the barebones attributes that are required for this class are specified
|
15
|
+
# here. The conversion of these attributes into a OS build specific file is
|
16
|
+
# done by derived classes in the OS specific directories.
|
17
|
+
class Disk < Base
|
18
|
+
|
19
|
+
# Include MiB as a method inside Disk
|
20
|
+
include Utils::Size
|
21
|
+
|
22
|
+
# Specify attributes
|
23
|
+
attr_accessor :name
|
24
|
+
attr_accessor :size
|
25
|
+
attr_accessor :partitions
|
26
|
+
attr_accessor :vg
|
27
|
+
|
28
|
+
# Documentation for this class
|
29
|
+
def self.doc_file
|
30
|
+
PackerFiles.DirPath('Core/example/Disk.txt').first
|
31
|
+
end
|
32
|
+
|
33
|
+
# Constructor to just specify accessor varibales
|
34
|
+
def initialize
|
35
|
+
@partitions = []
|
36
|
+
yield self if block_given?
|
37
|
+
end
|
38
|
+
|
39
|
+
# Tells if the disk is a raw disk that contains no partitions
|
40
|
+
# and Volume group
|
41
|
+
def is_raw?
|
42
|
+
return true if @partitions.empty? && @vg.nil?
|
43
|
+
false
|
44
|
+
end
|
45
|
+
|
46
|
+
# Tells if the disk has only custom partition modifiers and no
|
47
|
+
# volume group.
|
48
|
+
def only_partitions?
|
49
|
+
return true if !@partitions.empty? && @vg.nil?
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
# Tells if there is just a custom VG specification on a
|
54
|
+
# disk w/o any partitions.
|
55
|
+
def only_vg?
|
56
|
+
return true if @partitions.empty? && !@vg.nil?
|
57
|
+
false
|
58
|
+
end
|
59
|
+
|
60
|
+
# Tells if there is both a custom VG specification on a
|
61
|
+
# disk and partitions.
|
62
|
+
def vg_with_partitions?
|
63
|
+
return true if !@partitions.empty? && !@vg.nil?
|
64
|
+
end
|
65
|
+
|
66
|
+
# Adds a volume group to this disk by doing an instance-eval
|
67
|
+
def VolumeGroup(&block)
|
68
|
+
if block_given?
|
69
|
+
vg = VolumeGroup.new
|
70
|
+
vg.instance_eval &block
|
71
|
+
@vg = vg
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Adds a Partition on this disk by doing an instance-eval
|
76
|
+
def Partition(&block)
|
77
|
+
if block_given?
|
78
|
+
part = Partition.new
|
79
|
+
part.instance_eval &block
|
80
|
+
if (part.name.nil?)
|
81
|
+
part.name = @partitions.size
|
82
|
+
end
|
83
|
+
@partitions.push(part)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Normalize the various values into something useful. Usually
|
88
|
+
# this means adding UTF-8 into the default string. if desired
|
89
|
+
def normalize
|
90
|
+
raise NilException.new(self, 'name') if @name.nil?
|
91
|
+
raise NilException.new(self, 'size') if @size.nil?
|
92
|
+
raise NilException.new(self, 'partitions') if @partitions.nil?
|
93
|
+
|
94
|
+
# Convert given size into MiB
|
95
|
+
@size = MiB(@size)
|
96
|
+
|
97
|
+
# Re-create the object by converting the given size into MiB
|
98
|
+
@partitions.each {|p|
|
99
|
+
p.size = MiB(p.size)
|
100
|
+
p.normalize
|
101
|
+
}
|
102
|
+
|
103
|
+
# Add all partition sizes and if they exceed disk size, cry...
|
104
|
+
part_size = @partitions.inject(0) {|val, p| val + p.size}
|
105
|
+
raise SizeException.new(@partitions.first, self) if (@size < part_size)
|
106
|
+
|
107
|
+
# Normalize the embedded VG, if it is present
|
108
|
+
return if @vg.nil?
|
109
|
+
@vg.normalize
|
110
|
+
|
111
|
+
# Calculate sum of all LVs
|
112
|
+
lv_size = @vg.lvs.inject(0) { |val, lv| val + lv.size }
|
113
|
+
|
114
|
+
# Calculate the size of the Physical Volumes. It is either
|
115
|
+
# the whole disk or the list of partitions that match the
|
116
|
+
# disk names
|
117
|
+
if @partitions.nil? || @partitions.empty?
|
118
|
+
total_size = @size
|
119
|
+
else
|
120
|
+
total_size = @vg.disk_names.inject(0) {|val,name|
|
121
|
+
match = @partitions.select {|part| (part.name.to_s == name.to_s) }
|
122
|
+
raise "Disk name #{name} doesn't match partition names" if match.empty?
|
123
|
+
raise "Multiple matches for #{name} in Partitions" if match.size > 1
|
124
|
+
val + match.first.size
|
125
|
+
}
|
126
|
+
end
|
127
|
+
raise SizeException.new(@vg.lvs.first, @vg) if lv_size > total_size
|
128
|
+
end
|
129
|
+
|
130
|
+
end # Disk
|
131
|
+
|
132
|
+
end # Core
|
133
|
+
|
134
|
+
end # PackerFiles
|
135
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Requires
|
2
|
+
|
3
|
+
|
4
|
+
# Exceptions generated by the PackerFile generator.
|
5
|
+
module PackerFiles
|
6
|
+
|
7
|
+
module Core
|
8
|
+
|
9
|
+
# The top level class for all exceptions shown by this gem.
|
10
|
+
class Error < Exception
|
11
|
+
attr_accessor :message
|
12
|
+
end
|
13
|
+
|
14
|
+
# The Nil exception is generated when a particular class member is nil.
|
15
|
+
class NilException < Error
|
16
|
+
|
17
|
+
# Constructor.
|
18
|
+
def initialize(obj, member_name)
|
19
|
+
@super
|
20
|
+
class_name = obj.class.name.gsub(/.*::/, '')
|
21
|
+
self.message = "#{class_name}.#{member_name} is not set"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# The EmptyArray Exception is generated when a particular class member array
|
26
|
+
# is empty.
|
27
|
+
class EmptyArrayException < Error
|
28
|
+
|
29
|
+
# Constructor.
|
30
|
+
def initialize(obj, member_name)
|
31
|
+
@super
|
32
|
+
class_name = obj.class.name.gsub(/.*::/, '')
|
33
|
+
self.message = "#{class_name}.#{member_name} is empty"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# The Size Exception is generated when child object sizes are greater than
|
38
|
+
# that of Parent objects.
|
39
|
+
class SizeException < Error
|
40
|
+
|
41
|
+
# Constructor.
|
42
|
+
def initialize(parent_obj, child_obj)
|
43
|
+
@super
|
44
|
+
parent = parent_obj.class.name.gsub(/.*::/, '')
|
45
|
+
child = child_obj.class.name.gsub(/.*::/, '')
|
46
|
+
self.message = "Sum of #{child} sizes are greater than #{parent} size"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# The URL Exception is generated if a URL cannot be opened and it's contents
|
51
|
+
# cannot be read.
|
52
|
+
class URLException < Error
|
53
|
+
|
54
|
+
# Constructor
|
55
|
+
def initialize(url, inner_obj)
|
56
|
+
@super
|
57
|
+
self.message = "URL #{url} could not be opened! HTTP Error: #{inner_obj.to_s}"
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end # Core
|
63
|
+
|
64
|
+
end # PackerFiles
|
65
|
+
|