comfy 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +46 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +13 -0
  7. data/README.md +131 -0
  8. data/Rakefile +18 -0
  9. data/bin/comfy +4 -0
  10. data/comfy.gemspec +36 -0
  11. data/config/comfy.yml +20 -0
  12. data/lib/comfy/command_executioner.rb +225 -0
  13. data/lib/comfy/creator.rb +200 -0
  14. data/lib/comfy/errors/invalid_distribution_version_error.rb +1 -0
  15. data/lib/comfy/errors/no_such_distribution_version_error.rb +1 -0
  16. data/lib/comfy/errors/packer_error.rb +1 -0
  17. data/lib/comfy/errors/packer_execution_error.rb +1 -0
  18. data/lib/comfy/errors/packer_validation_error.rb +1 -0
  19. data/lib/comfy/errors.rb +4 -0
  20. data/lib/comfy/extensions/yell.rb +8 -0
  21. data/lib/comfy/settings.rb +15 -0
  22. data/lib/comfy/templater.rb +62 -0
  23. data/lib/comfy/version.rb +3 -0
  24. data/lib/comfy.rb +18 -0
  25. data/lib/templates/centos/centos.cfg.erb +47 -0
  26. data/lib/templates/centos/centos.description +20 -0
  27. data/lib/templates/centos/files/10-ipv6.conf +5 -0
  28. data/lib/templates/centos/files/check-mk-agent-meta-checks-2.0-1.noarch.rpm +0 -0
  29. data/lib/templates/centos/files/check-mk-agent-meta-key-1.0-1.noarch.rpm +0 -0
  30. data/lib/templates/centos/files/cloud.cfg +101 -0
  31. data/lib/templates/centos/files/fail2ban.local +3 -0
  32. data/lib/templates/centos/files/getty@ttyS0.service +47 -0
  33. data/lib/templates/centos/files/grub +11 -0
  34. data/lib/templates/centos/files/iptables-multiport.local +6 -0
  35. data/lib/templates/centos/files/jail.local +17 -0
  36. data/lib/templates/centos/files/krb5.conf +181 -0
  37. data/lib/templates/centos/files/ntp.conf +61 -0
  38. data/lib/templates/centos/files/pakiti-2.1.5-1.noarch.rpm +0 -0
  39. data/lib/templates/centos/files/sshd_config +152 -0
  40. data/lib/templates/centos/files/xen-domU.conf +1 -0
  41. data/lib/templates/centos/scripts/init.sh +83 -0
  42. data/lib/templates/debian/debian.cfg.erb +80 -0
  43. data/lib/templates/debian/debian.description +28 -0
  44. data/lib/templates/debian/files/.bashrc +112 -0
  45. data/lib/templates/debian/files/.gitconfig +7 -0
  46. data/lib/templates/debian/files/10-ipv6.conf +5 -0
  47. data/lib/templates/debian/files/DEPOT-GPG-KEY.cfg +32 -0
  48. data/lib/templates/debian/files/RPM-GPG-KEY-CERIT-SC.cfg +30 -0
  49. data/lib/templates/debian/files/backports.list +2 -0
  50. data/lib/templates/debian/files/cerit-cloudinit.list +2 -0
  51. data/lib/templates/debian/files/cloud.cfg +102 -0
  52. data/lib/templates/debian/files/depot.list +4 -0
  53. data/lib/templates/debian/files/depot_all.pref +6 -0
  54. data/lib/templates/debian/files/depot_check_mk.pref +5 -0
  55. data/lib/templates/debian/files/fail2ban.local +3 -0
  56. data/lib/templates/debian/files/getty@ttyS0.service +47 -0
  57. data/lib/templates/debian/files/grub +34 -0
  58. data/lib/templates/debian/files/inittab +69 -0
  59. data/lib/templates/debian/files/interfaces +15 -0
  60. data/lib/templates/debian/files/iptables-multiport.local +6 -0
  61. data/lib/templates/debian/files/jail.local +17 -0
  62. data/lib/templates/debian/files/krb5.conf +181 -0
  63. data/lib/templates/debian/files/meta-misc.list +2 -0
  64. data/lib/templates/debian/files/modules +15 -0
  65. data/lib/templates/debian/files/ntp.conf +61 -0
  66. data/lib/templates/debian/files/pakiti_2.1.5-2_all.deb +0 -0
  67. data/lib/templates/debian/files/sshd_config +131 -0
  68. data/lib/templates/debian/scripts/debian_cloud_script.sh +80 -0
  69. data/lib/templates/docker/docker.cfg.erb +87 -0
  70. data/lib/templates/docker/docker.description +21 -0
  71. data/lib/templates/docker/files/10-ipv6.conf +5 -0
  72. data/lib/templates/docker/files/DEPOT-GPG-KEY.cfg +32 -0
  73. data/lib/templates/docker/files/RPM-GPG-KEY-CERIT-SC.cfg +30 -0
  74. data/lib/templates/docker/files/cloud.cfg +109 -0
  75. data/lib/templates/docker/files/depot.list +4 -0
  76. data/lib/templates/docker/files/depot_all.pref +6 -0
  77. data/lib/templates/docker/files/depot_check_mk.pref +5 -0
  78. data/lib/templates/docker/files/docker.list +1 -0
  79. data/lib/templates/docker/files/fail2ban.local +3 -0
  80. data/lib/templates/docker/files/grub +34 -0
  81. data/lib/templates/docker/files/interfaces +15 -0
  82. data/lib/templates/docker/files/iptables-multiport.local +6 -0
  83. data/lib/templates/docker/files/jail.local +17 -0
  84. data/lib/templates/docker/files/krb5.conf +181 -0
  85. data/lib/templates/docker/files/meta-misc.list +2 -0
  86. data/lib/templates/docker/files/modules +15 -0
  87. data/lib/templates/docker/files/ntp.conf +61 -0
  88. data/lib/templates/docker/files/pakiti_2.1.5-2_all.deb +0 -0
  89. data/lib/templates/docker/files/sshd_config +131 -0
  90. data/lib/templates/docker/files/ttyS0.conf +11 -0
  91. data/lib/templates/docker/scripts/init.sh +65 -0
  92. data/lib/templates/packer.erb +93 -0
  93. data/lib/templates/scientificlinux/files/10-ipv6.conf +5 -0
  94. data/lib/templates/scientificlinux/files/check-mk-agent-meta-checks-2.0-1.noarch.rpm +0 -0
  95. data/lib/templates/scientificlinux/files/check-mk-agent-meta-key-1.0-1.noarch.rpm +0 -0
  96. data/lib/templates/scientificlinux/files/cloud.cfg +101 -0
  97. data/lib/templates/scientificlinux/files/fail2ban.local +3 -0
  98. data/lib/templates/scientificlinux/files/getty@ttyS0.service +47 -0
  99. data/lib/templates/scientificlinux/files/grub +10 -0
  100. data/lib/templates/scientificlinux/files/iptables-multiport.local +6 -0
  101. data/lib/templates/scientificlinux/files/jail.local +17 -0
  102. data/lib/templates/scientificlinux/files/krb5.conf +181 -0
  103. data/lib/templates/scientificlinux/files/ntp.conf +61 -0
  104. data/lib/templates/scientificlinux/files/pakiti-2.1.5-1.noarch.rpm +0 -0
  105. data/lib/templates/scientificlinux/files/sshd_config +150 -0
  106. data/lib/templates/scientificlinux/files/xen-domU.conf +1 -0
  107. data/lib/templates/scientificlinux/scientificlinux.cfg.erb +57 -0
  108. data/lib/templates/scientificlinux/scientificlinux.description +19 -0
  109. data/lib/templates/scientificlinux/scripts/init.sh +92 -0
  110. data/lib/templates/ubuntu/files/10-ipv6.conf +5 -0
  111. data/lib/templates/ubuntu/files/DEPOT-GPG-KEY.cfg +32 -0
  112. data/lib/templates/ubuntu/files/RPM-GPG-KEY-CERIT-SC.cfg +30 -0
  113. data/lib/templates/ubuntu/files/cloud.cfg +109 -0
  114. data/lib/templates/ubuntu/files/depot.list +4 -0
  115. data/lib/templates/ubuntu/files/depot_all.pref +6 -0
  116. data/lib/templates/ubuntu/files/depot_check_mk.pref +5 -0
  117. data/lib/templates/ubuntu/files/fail2ban.local +3 -0
  118. data/lib/templates/ubuntu/files/grub +34 -0
  119. data/lib/templates/ubuntu/files/interfaces +15 -0
  120. data/lib/templates/ubuntu/files/iptables-multiport.local +6 -0
  121. data/lib/templates/ubuntu/files/jail.local +17 -0
  122. data/lib/templates/ubuntu/files/krb5.conf +181 -0
  123. data/lib/templates/ubuntu/files/meta-misc.list +2 -0
  124. data/lib/templates/ubuntu/files/modules +15 -0
  125. data/lib/templates/ubuntu/files/ntp.conf +61 -0
  126. data/lib/templates/ubuntu/files/pakiti_2.1.5-2_all.deb +0 -0
  127. data/lib/templates/ubuntu/files/sshd_config +131 -0
  128. data/lib/templates/ubuntu/files/ttyS0.conf +11 -0
  129. data/lib/templates/ubuntu/scripts/init.sh +54 -0
  130. data/lib/templates/ubuntu/ubuntu.cfg.erb +87 -0
  131. data/lib/templates/ubuntu/ubuntu.description +21 -0
  132. data/schema/distribution_descriptor.schema +241 -0
  133. metadata +374 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1a00d600ac242d01ee397d5e77b0740cc3a9361b
4
+ data.tar.gz: 21f394dae54301c46756ca44e45f68fb02713ab0
5
+ SHA512:
6
+ metadata.gz: d45c8ea2ba75e6801a0dfc4f8487976ad34c04508d73ff479d7cd823697d84d48d647c6e501527c2e5911f44d8ff4b634bbb0122219264599022a4a142ad19d3
7
+ data.tar.gz: 4b0bf525e8079fff89367ea160c09cb26ea9451b1c2fee1ac1e9723a30594059ff84d45c96535b4a79083331285c398ac849ef8602c7b188209371c230ae5307
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
11
+ /.idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,46 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1
7
+ - 2.2.1
8
+ - ruby-head
9
+ - jruby-19mode
10
+ - jruby-head
11
+
12
+ jdk:
13
+ - openjdk7
14
+ - oraclejdk7
15
+ - openjdk6
16
+
17
+ matrix:
18
+ allow_failures:
19
+ - rvm: ruby-head
20
+ - rvm: jruby-head
21
+ exclude:
22
+ - rvm: 1.9.3
23
+ jdk: openjdk7
24
+ - rvm: 1.9.3
25
+ jdk: oraclejdk7
26
+ - rvm: 2.0.0
27
+ jdk: openjdk7
28
+ - rvm: 2.0.0
29
+ jdk: oraclejdk7
30
+ - rvm: 2.1
31
+ jdk: openjdk7
32
+ - rvm: 2.1
33
+ jdk: oraclejdk7
34
+ - rvm: 2.2.1
35
+ jdk: openjdk7
36
+ - rvm: 2.2.1
37
+ jdk: oraclejdk7
38
+ - rvm: ruby-head
39
+ jdk: openjdk7
40
+ - rvm: ruby-head
41
+ jdk: oraclejdk7
42
+ fast_finish: true
43
+
44
+ branches:
45
+ only:
46
+ - master
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in comfy.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2015 Michal Kimle and Lubomir Kosaristan
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # COMFY - ClOud iMage FactorY
2
+ COMFY is a tool for building virtual machine images from scratch.
3
+
4
+ [![Build Status](https://secure.travis-ci.org/CESNET/comfy.png)](http://travis-ci.org/CESNET/comfy)
5
+ [![Dependency Status](https://gemnasium.com/CESNET/comfy.png)](https://gemnasium.com/CESNET/comfy)
6
+ [![Gem Version](https://fury-badge.herokuapp.com/rb/comfy.png)](https://badge.fury.io/rb/comfy)
7
+ [![Code Climate](https://codeclimate.com/github/CESNET/comfy.png)](https://codeclimate.com/github/CESNET/comfy)
8
+
9
+ ##Requirements
10
+ * Ruby >= 1.9.3
11
+ * Rubygems
12
+ * [Packer] >= 0.8.6 (https://www.packer.io/) (used for the image creation process)
13
+ * VirtualBox (if you want to create `ova` images)
14
+ * QEMU/KVM (if you want to create `qcow2` images)
15
+
16
+ ## Installation
17
+ **Unfortunately, neither gem nor packages are available for COMFY right now. To try COMFY, please use the [From source](#from-source-dev) guide below.**
18
+
19
+ ###From source (dev)
20
+ **Installation from source should never be your first choice! Especially, if you are not
21
+ familiar with RVM, Bundler, Rake and other dev tools for Ruby!**
22
+
23
+ **However, if you wish to contribute to our project, this is the right way to start.**
24
+
25
+ To build and install the bleeding edge version from master
26
+
27
+ ```bash
28
+ git clone git://github.com/CESNET/comfy.git
29
+ cd comfy
30
+ gem install bundler
31
+ bundle install
32
+ bundle exec rake spec
33
+ ```
34
+
35
+ ##Configuration
36
+ ###Create a configuration file for COMFY
37
+ Configuration file can be read by COMFY from these
38
+ three locations:
39
+
40
+ * `~/.comfy/comfy.yml`
41
+ * `/etc/comfy/comfy.yml`
42
+ * `PATH_TO_GEM_DIR/config/comfy.yml`
43
+
44
+ The example configuration file can be found at the last location
45
+ `PATH_TO_GEM_DIR/config/comfy.yml`. When editing a configuration
46
+ file you have to follow the division into three environments: `production`,
47
+ `development` and `test`. All the configuration options are described
48
+ in the example configuration file.
49
+
50
+ ##Usage
51
+ COMFY is run with executable `comfy`. For further assistance run `comfy help`:
52
+ ```bash
53
+ $ comfy help
54
+
55
+ Commands:
56
+ comfy DISTRIBUTION # Builds VM with selected distribution
57
+ comfy <DISTRIBUTION>-versions # Lists available versions for selected destribution
58
+ comfy clean-cache -c, --cache-dir=CACHE-DIR # Cleans packer's cache containing distributions' installation media
59
+ comfy distributions # Lists all available distributions and their versions
60
+ comfy export -d, --destination=DESTINATION # Exports files for building virtual machines. Helps with the customization of the build process.
61
+ comfy help [COMMAND] # Describe available commands or one specific command
62
+ comfy version # Prints COMFY's version
63
+
64
+ Options:
65
+ --logging-level=LOGGING-LEVEL
66
+ # Possible values: DEBUG, INFO, WARN, ERROR, FATAL, UNKNOWN
67
+ [--logging-file=LOGGING-FILE] # File to write log to
68
+ [--debug], [--no-debug] # Runs COMFY in debug mode
69
+ ```
70
+
71
+ Building process of selected VM can be customized. To list all the options for one of the distributions run `comfy help DISTRIBUTION`:
72
+ ```bash
73
+ $ comfy help ubuntu
74
+
75
+ Usage:
76
+ comfy ubuntu -c, --cache-dir=CACHE-DIR -f, --formats=one two three -o, --output-dir=OUTPUT-DIR -s, --size=N -v, --version=VERSION
77
+
78
+ Options:
79
+ -v, --version=VERSION # Version of distribution to build
80
+ -f, --formats=one two three # Output format of the virtual machine image (qemu - qcow2, virtualbox - ova)
81
+ # Possible values: qemu, virtualbox
82
+ -s, --size=N # Disk size for created virtual machines (in MB)
83
+ -o, --output-dir=OUTPUT-DIR # Directory to which COMFY will produce virtual machine files
84
+ -c, --cache-dir=CACHE-DIR # Directory for packer's cache e.g. distribution installation images
85
+ -g, [--groups=one two three] # Groups VM belongs to. For automatic processing purposes
86
+ -i, [--identifier=IDENTIFIER] # VM identifier. For automatic processing purposes
87
+ -d, [--description], [--no-description] # Generates VM description file. For automatic processing purposes
88
+ -t, [--template-dir=TEMPLATE-DIR] # Directory COMFY uses templates from to build a VM
89
+ --logging-level=LOGGING-LEVEL
90
+ # Possible values: DEBUG, INFO, WARN, ERROR, FATAL, UNKNOWN
91
+ [--logging-file=LOGGING-FILE] # File to write log to
92
+ [--debug], [--no-debug] # Runs COMFY in debug mode
93
+
94
+ Builds VM with distribution Ubuntu
95
+ ```
96
+
97
+ COMFY currently supports building of these distributions:
98
+ * CentOS 7.1.1503
99
+ * Debian 7.9.0
100
+ * Debian 8.2.0
101
+ * ScientificLinux 7.1
102
+ * Ubuntu 14.04
103
+
104
+ ##Example
105
+ To start a building process for example for debian simply run:
106
+ ```bash
107
+ $ comfy debian
108
+ ```
109
+ When not specified, COMFY will build the newest version of selected distribution. If you want to select a specific version run:
110
+ ```bash
111
+ $ comfy debian -v 7.9.0
112
+ ```
113
+ COMFY uses by default a QEMU supervisor for image creation. If you want to use VirtualBox you can do it with:
114
+ ```bash
115
+ $ comfy debian -f virtualbox
116
+ ```
117
+ Or if you want to use both:
118
+ ```bash
119
+ $ comfy debian -f qemu virtualbox
120
+ ```
121
+ This will create virtual machine images in both `qcow2` and `ovf` formats. Since QEMU and VirtualBox can't run simultaneously, images are created in two sequential runs.
122
+
123
+ ##Continuous integration
124
+ [Continuous integration for COMFY by Travis-CI](http://travis-ci.org/CESNET/comfy/)
125
+
126
+ ## Contributing
127
+ 1. Fork it ( https://github.com/CESNET/comfy/fork )
128
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
129
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
130
+ 4. Push to the branch (`git push origin my-new-feature`)
131
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubygems/tasks'
3
+
4
+ task default: 'test'
5
+
6
+ desc 'Run all tests; includes rspec and coverage reports'
7
+ task test: 'rcov:rspec'
8
+
9
+ desc 'Run all tests; includes rspec and coverage reports'
10
+ task spec: 'test'
11
+
12
+ Gem::Tasks.new(build: { tar: true, zip: true }, sign: { checksum: true, pgp: false })
13
+
14
+ namespace :rcov do
15
+ require 'rspec/core/rake_task'
16
+
17
+ RSpec::Core::RakeTask.new(:rspec)
18
+ end
data/bin/comfy ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'comfy'
3
+
4
+ Comfy::CommandExecutioner.start(ARGV)
data/comfy.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 'comfy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'comfy'
8
+ spec.version = Comfy::VERSION
9
+ spec.authors = ['Michal Kimle', 'Ľubomír Košarišťan']
10
+ spec.email = ['kimle.michal@gmail.com', 'kosoburak@gmail.com']
11
+
12
+ spec.summary = 'Tool for building virtual machine images from scratch.'
13
+ spec.description = 'Tool for building virtual machine images from scratch.'
14
+ spec.homepage = 'https://github.com/Misenko/comfy'
15
+ spec.license = 'Apache License 2.0'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.0.0'
24
+ spec.add_development_dependency 'simplecov', '~> 0.9.0'
25
+ spec.add_development_dependency 'rubygems-tasks', '~> 0.2.4'
26
+ spec.add_development_dependency 'rubocop', '~> 0.32'
27
+
28
+ spec.add_runtime_dependency 'syslogger', '~> 1.6.0'
29
+ spec.add_runtime_dependency 'settingslogic', '~> 2.0.9'
30
+ spec.add_runtime_dependency 'mixlib-shellout', '~> 2.0.1'
31
+ spec.add_runtime_dependency 'json-schema', '~> 2.5'
32
+ spec.add_runtime_dependency 'activesupport', '~> 4.2'
33
+ spec.add_runtime_dependency 'cloud-appliance-descriptor', '~> 0.2'
34
+ spec.add_runtime_dependency 'thor', '~> 0.19'
35
+ spec.add_runtime_dependency 'yell', '~> 2.0'
36
+ end
data/config/comfy.yml ADDED
@@ -0,0 +1,20 @@
1
+ ---
2
+ production:
3
+ output-dir: /opt/comfy/virtualmachines/ # Directory to which COMFY will produce virtual machine files
4
+ cache-dir: /opt/comfy/packer_cache/ # Directory for packer's cache e.g. distribution installation images
5
+ #template-dir: /opt/comfy/templates/ # When used COMFY uses templates from this directory to create virtual machines
6
+ formats:
7
+ - qemu
8
+ size: 10000
9
+ description: true
10
+ groups: # groups VM belongs to, used when creating cloud-appliance-descriptor
11
+ - comfy
12
+ # $t - timestamp
13
+ # $v - distribution version, consisting of major, minor, and patch version if possible
14
+ # $n - distribution name
15
+ # $g - groups the VM belongs to, separated by commas
16
+ identifier: METACLOUD-$n-$v # vm identifier, used in multiple places
17
+ logging:
18
+ level: ERROR
19
+ file: /var/log/comfy/comfy.log # File to write log to
20
+ debug: false
@@ -0,0 +1,225 @@
1
+ require 'thor'
2
+ require 'yell'
3
+ require 'json-schema'
4
+ require 'fileutils'
5
+
6
+ class Comfy::CommandExecutioner < Thor
7
+ class << self
8
+
9
+ # Method listing available distributions from template directory.
10
+ #
11
+ # @return [Hash] distributions structure containing info about them
12
+ def available_distributions
13
+ dir = Comfy::TEMPLATE_DIR
14
+ return {} unless File.exist? dir
15
+
16
+ description_files = Dir.glob(File.join(dir, '*', '*.description')).sort
17
+ distributions = {}
18
+ description_files.each do |description_file|
19
+ unless JSON::Validator.validate(Comfy::DESCRIPTION_SCHEMA_FILE, description_file)
20
+ puts "Invalid distribution description #{description_file.inspect}, skipping."
21
+ next
22
+ end
23
+
24
+ description = File.read(description_file)
25
+ json = JSON.parse(description)
26
+ name = json['name']
27
+ distributions[name] = []
28
+ json['versions'].each do |version|
29
+ version_string = []
30
+ version_string << version['major_version']
31
+ version_string << version['minor_version']
32
+ version_string << version['patch_version']
33
+
34
+ distributions[name] << version_string.compact.join('.')
35
+ distributions[name].sort!
36
+ end
37
+ end
38
+
39
+ distributions
40
+ end
41
+ end
42
+
43
+ class_option :"logging-level",
44
+ :required => true,
45
+ :default => Comfy::Settings['logging']['level'],
46
+ :type => :string,
47
+ :enum => Yell::Severities
48
+ class_option :"logging-file",
49
+ :default => Comfy::Settings['logging']['file'],
50
+ :type => :string,
51
+ :desc => 'File to write log to'
52
+ class_option :debug,
53
+ :default => Comfy::Settings['debug'],
54
+ :type => :boolean,
55
+ :desc => 'Runs COMFY in debug mode'
56
+
57
+ desc 'version', 'Prints COMFY\'s version'
58
+ def version
59
+ $stdout.puts Comfy::VERSION
60
+ end
61
+
62
+ desc 'distributions', 'Lists all available distributions and their versions'
63
+ def distributions
64
+ self.class.available_distributions.each do |distribution, versions|
65
+ versions.each { |version| $stdout.puts "#{distribution} #{version}" }
66
+ end
67
+ end
68
+
69
+ method_option :destination,
70
+ type: :string,
71
+ required: true,
72
+ aliases: '-d',
73
+ desc: 'Destination of exported files'
74
+ desc 'export', 'Exports files for building virtual machines. Helps with the customization of the build process.'
75
+ def export
76
+ dir = options['destination']
77
+ FileUtils.mkdir_p dir unless File.exist?(dir) && File.directory?(dir)
78
+
79
+ FileUtils.cp_r(File.join(Comfy::Settings['template-dir'], '.'), dir)
80
+ $stdout.puts 'Template files copied successfully.'
81
+ $stdout.puts "In order to use the new template directory change setting 'vm_templates_dir' in your configuration file to:"
82
+ $stdout.puts "template-dir: #{dir}"
83
+ end
84
+
85
+ method_option :"cache-dir",
86
+ type: :string,
87
+ required: true,
88
+ default: Comfy::Settings['cache-dir'],
89
+ aliases: '-c',
90
+ desc: 'Directory for packer\'s cache e.g. distribution installation images'
91
+ desc 'clean-cache', 'Cleans packer\'s cache containing distributions\' installation media'
92
+ def clean_cache
93
+ dir = options['cache-dir']
94
+ FileUtils.rm_r Dir.glob(File.join(dir, '*'))
95
+ puts 'Cache cleaned successfully.'
96
+ end
97
+
98
+ available_distributions.each do |name, versions|
99
+ plain_name = name.downcase
100
+ method_option :version,
101
+ type: :string,
102
+ aliases: '-v',
103
+ default: versions.first,
104
+ required: true,
105
+ desc: 'Version of distribution to build'
106
+ method_option :formats,
107
+ type: :array,
108
+ aliases: '-f',
109
+ default: Comfy::Settings['formats'],
110
+ enum: ['qemu', 'virtualbox'],
111
+ required: true,
112
+ desc: 'Output format of the virtual machine image (qemu - qcow2, virtualbox - ova)'
113
+ method_option :size,
114
+ type: :numeric,
115
+ aliases: '-s',
116
+ default: Comfy::Settings['size'],
117
+ required: true,
118
+ desc: 'Disk size for created virtual machines (in MB)'
119
+ method_option :"output-dir",
120
+ type: :string,
121
+ required: true,
122
+ default: Comfy::Settings['output-dir'],
123
+ aliases: '-o',
124
+ desc: 'Directory to which COMFY will produce virtual machine files'
125
+ method_option :"cache-dir",
126
+ type: :string,
127
+ required: true,
128
+ default: Comfy::Settings['cache-dir'],
129
+ aliases: '-c',
130
+ desc: 'Directory for packer\'s cache e.g. distribution installation images'
131
+ method_option :groups,
132
+ type: :array,
133
+ aliases: '-g',
134
+ default: Comfy::Settings['groups'],
135
+ desc: 'Groups VM belongs to. For automatic processing purposes'
136
+ method_option :identifier,
137
+ type: :string,
138
+ aliases: '-i',
139
+ default: Comfy::Settings['identifier'],
140
+ desc: 'VM identifier. For automatic processing purposes'
141
+ method_option :description,
142
+ type: :boolean,
143
+ aliases: '-d',
144
+ default: Comfy::Settings['description'],
145
+ desc: 'Generates VM description file. For automatic processing purposes'
146
+ method_option :'template-dir',
147
+ type: :string,
148
+ aliases: '-t',
149
+ default: Comfy::TEMPLATE_DIR,
150
+ desc: 'Directory COMFY uses templates from to build a VM'
151
+
152
+ class_eval %Q^
153
+ desc '#{plain_name}', 'Builds VM with distribution #{name}'
154
+ def #{plain_name}
155
+ start('#{plain_name}', options)
156
+ end
157
+
158
+ desc '#{plain_name}-versions', 'Lists all available versions of #{name}'
159
+ def #{plain_name}_versions
160
+ #{versions}.each { |version| $stdout.puts version }
161
+ end
162
+ ^
163
+ end
164
+
165
+ private
166
+
167
+ def start(distribution_name, options)
168
+ parameters = options.to_hash.deep_symbolize_keys
169
+ parameters[:distribution] = distribution_name
170
+ parameters[:headless] = !parameters[:debug]
171
+ ENV['PACKER_CACHE_DIR'] = parameters[:'cache-dir']
172
+
173
+ init_log parameters
174
+ check_distribution_files distribution_name
175
+
176
+ logger.debug "Parameters: #{parameters}"
177
+
178
+ begin
179
+ creator = Comfy::Creator.new(parameters)
180
+ creator.create
181
+ ensure
182
+ creator.clean
183
+ end
184
+ end
185
+
186
+ # Inits logging according to the settings
187
+ #
188
+ # @param [Hash] parameters
189
+ # @option parameters [String] logging-level
190
+ # @option parameters [String] logging-file file to log to
191
+ # @option parameters [TrueClass, FalseClass] debug debug mode
192
+ # @return [Type] description of returned object
193
+ def init_log(parameters)
194
+ if parameters[:debug]
195
+ parameters[:'logging-level'] = 'DEBUG'
196
+ ENV['PACKER_LOG'] = '1'
197
+ end
198
+
199
+ Yell.new :stdout, :name => Object, :level => parameters[:'logging-level'].downcase, :format => Yell::DefaultFormat
200
+ Object.send :include, Yell::Loggable
201
+
202
+ if parameters[:'logging-file']
203
+ unless (File.exist?(parameters[:'logging-file']) && File.writable?(parameters[:'logging-file'])) || (File.writable?(File.dirname(parameters[:'logging-file'])))
204
+ logger.error "File #{parameters[:'logging-file']} isn't writable"
205
+ return
206
+ end
207
+
208
+ logger.adapter :file, parameters[:'logging-file']
209
+ end
210
+ end
211
+
212
+ def check_distribution_files(distribution_name)
213
+ distribution_cfg = File.join(Comfy::TEMPLATE_DIR, distribution_name, "#{distribution_name}.cfg.erb")
214
+ unless File.exist?(distribution_cfg)
215
+ logger.error "Missing distribution configuration #{distribution_cfg.inspect}, cannot build VM"
216
+ exit
217
+ end
218
+
219
+ distribution_desc = File.join(Comfy::TEMPLATE_DIR, distribution_name, "#{distribution_name}.description")
220
+ unless File.exist?(distribution_desc)
221
+ logger.error "Missing distribution description #{distribution_desc.inspect}, cannot build VM"
222
+ exit
223
+ end
224
+ end
225
+ end