itchy 0.0.1

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 (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +38 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +16 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE +203 -0
  7. data/README.md +16 -0
  8. data/Rakefile +25 -0
  9. data/bin/itchy +142 -0
  10. data/config/itchy.yml +32 -0
  11. data/itchy.gemspec +41 -0
  12. data/lib/itchy/errors/abstract_env_error.rb +4 -0
  13. data/lib/itchy/errors/env_lookup_error.rb +4 -0
  14. data/lib/itchy/errors/event_processing_error.rb +4 -0
  15. data/lib/itchy/errors/file_inspecting_error.rb +4 -0
  16. data/lib/itchy/errors/format_converting_error.rb +4 -0
  17. data/lib/itchy/errors/image_transforming_error.rb +4 -0
  18. data/lib/itchy/errors/not_found_error.rb +4 -0
  19. data/lib/itchy/errors/not_implemented_error.rb +4 -0
  20. data/lib/itchy/errors/unknown_event_error.rb +4 -0
  21. data/lib/itchy/errors/working_with_files_error.rb +4 -0
  22. data/lib/itchy/errors/wrong_state_error.rb +4 -0
  23. data/lib/itchy/errors.rb +5 -0
  24. data/lib/itchy/event_handlers/available_postfix_event_handler.rb +43 -0
  25. data/lib/itchy/event_handlers/available_prefix_event_handler.rb +10 -0
  26. data/lib/itchy/event_handlers/base_event_handler.rb +82 -0
  27. data/lib/itchy/event_handlers/expire_postfix_event_handler.rb +30 -0
  28. data/lib/itchy/event_handlers/expire_prefix_event_handler.rb +9 -0
  29. data/lib/itchy/event_handlers/process_postfix_event_handler.rb +9 -0
  30. data/lib/itchy/event_handlers/process_prefix_event_handler.rb +10 -0
  31. data/lib/itchy/event_handlers/subscription_image_new_event_handler.rb +9 -0
  32. data/lib/itchy/event_handlers.rb +8 -0
  33. data/lib/itchy/event_processer.rb +103 -0
  34. data/lib/itchy/format_converter.rb +43 -0
  35. data/lib/itchy/helpers/vmcatcher_env_helper.rb +44 -0
  36. data/lib/itchy/helpers.rb +5 -0
  37. data/lib/itchy/image_transformer.rb +220 -0
  38. data/lib/itchy/log.rb +78 -0
  39. data/lib/itchy/metadata_archiver.rb +59 -0
  40. data/lib/itchy/settings.rb +35 -0
  41. data/lib/itchy/version.rb +3 -0
  42. data/lib/itchy/vmcatcher_configuration.rb +62 -0
  43. data/lib/itchy/vmcatcher_env.rb +58 -0
  44. data/lib/itchy/vmcatcher_event.rb +71 -0
  45. data/lib/itchy.rb +26 -0
  46. data/spec/itchy/event_handlers/available_postfix_event_handler_spec.rb +0 -0
  47. data/spec/itchy/event_handlers/expire_postfix_event_handler_spec.rb +0 -0
  48. data/spec/itchy/event_processer_spec.rb +0 -0
  49. data/spec/itchy/format_converter_spec.rb +0 -0
  50. data/spec/itchy/image_transformer_spec.rb +0 -0
  51. data/spec/itchy/metadata_archiver_spec.rb +0 -0
  52. data/spec/itchy/vmcatcher_configuration_spec.rb +0 -0
  53. data/spec/itchy/vmcatcher_env_spec.rb +1 -0
  54. data/spec/itchy/vmcatcher_event_spec.rb +0 -0
  55. data/spec/spec_helper.rb +11 -0
  56. metadata +379 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d5cddf33b94091a5668066bfd1c185ffd25e287
4
+ data.tar.gz: 18c28ce3ee803506b115d361933df4b0ee76597a
5
+ SHA512:
6
+ metadata.gz: 12590cb87e2e4ee7332081a536f1d7b693147411727045cc32777fdf7027e5dfba70c390cbf300444b10068a0a967beb84eec98e94ede083f50138ed8c9c44c0
7
+ data.tar.gz: 60e737dae10ad1a2b38aae0ada2dacc1a3b810070f172015eff4f7bc2723869d209845942a58c5871ddc87e7aea704b64da4ba505e7d718b3ed4f81ae4ef2267
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+ /cache
12
+ /lib/onevmcatcher/vmcatcher.db
13
+ stderr.log
14
+ vmcatcher.db
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+
21
+ ## Documentation cache and generated files:
22
+ /.yardoc/
23
+ /_yardoc/
24
+ /doc/
25
+ /rdoc/
26
+
27
+ ## Environment normalisation:
28
+ /.bundle/
29
+ /lib/bundler/man/
30
+
31
+ # for a library or gem, you might want to ignore these files since the code is
32
+ # intended to run in multiple environments; otherwise, check them in:
33
+ Gemfile.lock
34
+ .ruby-version
35
+ .ruby-gemset
36
+
37
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
38
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper --color --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1
7
+ - ruby-head
8
+
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: ruby-head
12
+ fast_finish: true
13
+
14
+ branches:
15
+ only:
16
+ - master
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org/'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,203 @@
1
+ Apache License
2
+
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "{}"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2015 Lubomir Kosaristan and Boris Parak
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
203
+
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ [![Build Status](https://secure.travis-ci.org/arax/onevmcatcher.png)](http://travis-ci.org/kosoburak/itchy)
2
+ [![Dependency Status](https://gemnasium.com/arax/onevmcatcher.png)](https://gemnasium.com/kosoburak/itchy)
3
+ [![Gem Version](https://fury-badge.herokuapp.com/rb/onevmcatcher.png)](https://badge.fury.io/rb/itchy)
4
+ [![Code Climate](https://codeclimate.com/github/arax/onevmcatcher.png)](https://codeclimate.com/github/kosoburak/itchy)
5
+
6
+ # Itchy
7
+
8
+ Handling images from HEPIX vmcatcher for Nifty.
9
+
10
+ ## Contributing
11
+
12
+ 1. Fork it ( https://github.com/kosoburak/itchy/fork )
13
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
14
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
15
+ 4. Push to the branch (`git push origin my-new-feature`)
16
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ require 'rubygems/tasks'
2
+
3
+ task default: 'test'
4
+
5
+ desc 'Run all tests; includes rspec and coverage reports'
6
+ task test: 'rcov:all'
7
+
8
+ desc 'Run all tests; includes rspec and coverage reports'
9
+ task spec: 'test'
10
+
11
+ Gem::Tasks.new(build: { tar: true, zip: true }, sign: { checksum: true, pgp: false })
12
+
13
+ namespace :rcov do
14
+ require 'rspec/core/rake_task'
15
+
16
+ RSpec::Core::RakeTask.new(:rspec) do |_t|
17
+ ENV['COVERAGE'] = 'true'
18
+ end
19
+
20
+ desc 'Run rspec to generate aggregated coverage'
21
+ task :all do |_t|
22
+ rm 'coverage/coverage.data' if File.exist?('coverage/coverage.data')
23
+ Rake::Task['rcov:rspec'].invoke
24
+ end
25
+ end
data/bin/itchy ADDED
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # -------------------------------------------------------------------------- #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # a copy of the License at #
7
+ # #
8
+ # http://www.apache.org/licenses/LICENSE-2.0 #
9
+ # #
10
+ # Unless required by applicable law or agreed to in writing, software #
11
+ # distributed under the License is distributed on an "AS IS" BASIS, #
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
+ # See the License for the specific language governing permissions and #
14
+ # limitations under the License. #
15
+ #--------------------------------------------------------------------------- #
16
+
17
+ # add local dirs to load path if necessary
18
+ lib = File.expand_path(File.join('..', '..', 'lib'), __FILE__)
19
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
20
+
21
+ require 'rubygems'
22
+ require 'thor'
23
+ require 'itchy'
24
+ require 'openssl'
25
+
26
+ # Executable wrapper around itchy's libraries.
27
+ # Parses and validates user input and triggers internal
28
+ # logic.
29
+ class ItchyRunnable < Thor
30
+ include Thor::Actions
31
+
32
+ AVAILABLE_LOG_LEVELS = %w(debug info warn error fatal unknown).freeze
33
+ AVAILABLE_AUTH_METHODS = %w(none basic).freeze
34
+
35
+ shared_option_log_to = [:log_to, { type: :string, default: Itchy::Settings.log_to,
36
+ aliases: '-l', desc: 'Logging output, file path or stderr/stdout' }]
37
+
38
+ shared_option_log_level = [:log_level, { enum: AVAILABLE_LOG_LEVELS,
39
+ default: Itchy::Settings.log_level,
40
+ aliases: '-b', desc: 'Logging level' }]
41
+
42
+ shared_option_debug = [:debug, { type: :boolean, default: Itchy::Settings.debug,
43
+ aliases: '-d', desc: 'Enable debugging' }]
44
+
45
+ # Static method required by Thor to make certain
46
+ # actions work.
47
+ def self.source_root
48
+ File.expand_path(File.join('..', '..', 'templates'), __FILE__)
49
+ end
50
+
51
+ desc 'archive', 'Handle an incoming vmcatcher event and store it for further processing'
52
+ method_option :metadata_dir, type: :string, default: Itchy::Settings.metadata_dir,
53
+ aliases: '-m', desc: 'Path to a metadata directory for storing events, must be writable'
54
+ method_option *shared_option_log_to
55
+ method_option *shared_option_log_level
56
+ method_option *shared_option_debug
57
+
58
+ def archive
59
+ check_restrictions
60
+ opts = normalize_options
61
+ logger = init_logger(opts)
62
+
63
+ Itchy::Log.info "[#{self.class.name}] Archiver started"
64
+ Itchy::Log.debug "[#{self.class.name}] With options: #{opts.inspect}"
65
+
66
+ Itchy::MetadataArchiver.new(
67
+ Itchy::VmcatcherConfiguration.new(ENV),
68
+ opts
69
+ ).archive!(Itchy::VmcatcherEvent.new(ENV))
70
+ end
71
+
72
+ desc 'process', 'Process stored events'
73
+ method_option :metadata_dir, type: :string, default: Itchy::Settings.metadata_dir,
74
+ aliases: '-m', desc: 'Path to a metadata directory for stored events'
75
+ method_option :required_format, type: :string, default: Itchy::Settings.output_image_format,
76
+ aliases: '-f', desc: 'Required output format of converted images'
77
+ method_option :output_dir, type: :string, default: Itchy::Settings.metadata_dir,
78
+ aliases: '-o', desc: 'Path to a directory where processed events descriptors will be stored'
79
+ method_option :descriptor_dir, type: :string, default: Itchy::Settings.descriptor_dir,
80
+ aliases: '-e', desc: 'Path to a directory where appliance descriptors will be stored'
81
+ method_option :input_image_formats, type: :array, default: Itchy::Settings.input_image_formats,
82
+ aliases: '-i', desc: 'Known input image formats'
83
+ method_option *shared_option_log_to
84
+ method_option *shared_option_log_level
85
+ method_option *shared_option_debug
86
+
87
+ def process
88
+ check_restrictions
89
+ opts = normalize_options
90
+ logger = init_logger(opts)
91
+
92
+ Itchy::Log.info "[#{self.class.name}] Processing started"
93
+ Itchy::Log.debug "[#{self.class.name}] With options: #{opts.inspect}"
94
+
95
+ Itchy::EventProcesser.new(Itchy::VmcatcherConfiguration.new(ENV), opts).process!
96
+ end
97
+
98
+ private
99
+
100
+ # Converts Thor options into a Hashie::Mash instance
101
+ # with some additional conversions and modifications.
102
+ # Helps with integration later on.
103
+ #
104
+ # @return [Hashie::Mash] hash-like structure with options
105
+ def normalize_options
106
+ opts = ::Hashie::Mash.new(options)
107
+
108
+ opts.log_to = case options[:log_to]
109
+ when 'stdout'
110
+ STDOUT
111
+ when 'stderr'
112
+ STDERR
113
+ else
114
+ options[:log_to]
115
+ end
116
+ opts.log_level = Itchy::Log.const_get(options[:log_level].upcase)
117
+ opts.log_level = Itchy::Log::DEBUG if options[:debug]
118
+
119
+ opts
120
+ end
121
+
122
+ # Checks additional restrictions not enforced by thor.
123
+ # Mostly stuff broken by using SettingsLogic with thor.
124
+ def check_restrictions
125
+ fail "Logging target #{options[:log_to].inspect} " \
126
+ 'is not allowed!' if options[:log_to].nil? || options[:log_to].empty?
127
+ fail "Logging level #{options[:log_level].inspect} " \
128
+ 'is not allowed!' unless AVAILABLE_LOG_LEVELS.include?(options[:log_level])
129
+ end
130
+
131
+ # Initializes logging for Itchy::Log.
132
+ #
133
+ # @param opts [Hashie::Mash] hash-like structure with options
134
+ # @return [Itchy::Log] logger instance
135
+ def init_logger(opts)
136
+ logger = Itchy::Log.new(opts.log_to)
137
+ logger.level = opts.log_level
138
+ logger
139
+ end
140
+ end
141
+
142
+ ItchyRunnable.start
data/config/itchy.yml ADDED
@@ -0,0 +1,32 @@
1
+ ---
2
+ defaults: &defaults
3
+ metadata_dir: /var/spool/onevmcatcher
4
+ template_dir:
5
+ output_dir:
6
+ descriptor_dir: /tmp/vmcatcher/descriptors
7
+ log_to: stderr
8
+ log_level: error
9
+ ca_path: /etc/grid-security/certificates
10
+ ca_file:
11
+ debug: false
12
+ skip_ca_check: false
13
+ input_image_formats:
14
+ - raw
15
+ - ova
16
+ output_image_format: qcow2
17
+ qemu_img_binary: /usr/bin/qemu-img
18
+
19
+ ###############################################
20
+ ####### DO NOT EDIT AFTER THIS POINT ########
21
+ ###############################################
22
+
23
+ production:
24
+ <<: *defaults
25
+
26
+ development:
27
+ <<: *defaults
28
+ log_level: debug
29
+
30
+ test:
31
+ <<: *defaults
32
+ log_level: debug
data/itchy.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'itchy/version'
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = 'itchy'
9
+ gem.version = Itchy::VERSION
10
+ gem.authors = ['Lubomir Kosaristan', 'Boris Parak']
11
+ gem.email = ['436322@mail.muni.cz', 'parak@cesnet.cz']
12
+ gem.description = 'Handler integrating nifty with vmcatcher (HEPIX)'
13
+ gem.summary = 'Event handler for vmcatcher'
14
+ gem.homepage = 'https://github.com/kosoburak/itchy'
15
+ gem.license = 'Apache License, Version 2.0'
16
+
17
+ gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
+ gem.files = `git ls-files`.split("\n")
19
+ gem.test_files = `git ls-files -- {test,spec}/*`.split("\n")
20
+ gem.require_paths = ['lib']
21
+
22
+ gem.add_dependency 'opennebula', '~> 4.4', '>= 4.4.0'
23
+ gem.add_dependency 'multi_json', '~> 1.10', '>= 1.10.1'
24
+ gem.add_dependency 'mixlib-shellout', '~> 1.6', '>= 1.6.0'
25
+ gem.add_dependency 'ox', '~> 2.1', '>= 2.1.3'
26
+ gem.add_dependency 'oj', '~> 2.10', '>= 2.10.4'
27
+ gem.add_dependency 'activesupport', '~> 4.0', '>= 4.0.0'
28
+ gem.add_dependency 'settingslogic', '~> 2.0', '>= 2.0.9'
29
+ gem.add_dependency 'hashie', '~> 3.3', '>= 3.3.1'
30
+ gem.add_dependency 'thor', '~> 0.19', '>= 0.19.1'
31
+ gem.add_dependency 'cloud-appliance-descriptor', '~> 0.2'
32
+
33
+ gem.add_development_dependency 'bundler', '~> 1.6'
34
+ gem.add_development_dependency 'rake', '~> 10.0'
35
+ gem.add_development_dependency 'rspec', '~> 3.3.0'
36
+ gem.add_development_dependency 'simplecov', '~> 0.10.0'
37
+ gem.add_development_dependency 'rubygems-tasks', '~> 0.2.4'
38
+ gem.add_development_dependency 'rubocop', '~> 0.32'
39
+
40
+ gem.required_ruby_version = '>= 1.9.3'
41
+ end
@@ -0,0 +1,4 @@
1
+ module Itchy::Errors
2
+ # Covers errors caused by abstract components.
3
+ class AbstractEnvError < RuntimeError; end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Itchy::Errors
2
+ # Covers errors during environment handling and look-up.
3
+ class EnvLookupError < RuntimeError; end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Itchy::Errors
2
+ # Covers errors related to whole event processing.
3
+ class EventProcessingError < RuntimeError; end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Itchy::Errors
2
+ # Covers errors with shellout inspecting files and archives
3
+ class FileInspectingError < Itchy::Errors::ImageTransformingErrors; end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Itchy::Errors
2
+ # Covers errors related to image format converting.
3
+ class FormatConvertingError < Itchy::Errors::ImageTransformingError; end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Itchy::Errors
2
+ # Covers errors during transforming images (converting. copying..)
3
+ class ImageTransformingError < Itchy::Errors::EventProcessingError; end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Itchy::Errors
2
+ # Covers errors caused by missing objects.
3
+ class NotFoundError < StandardError; end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Itchy::Errors
2
+ # Covers errors related to missing implementations.
3
+ class NotImplementedError < RuntimeError; end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Itchy::Errors
2
+ # Covers errors caused by missing event handlers and unknown events.
3
+ class UnknownEventError < NameError; end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Itchy::Errors
2
+ #Covers errors with unpacking, copying, creating dirs.
3
+ class WorkingWithFilesError < Itchy::Errors::ImageTransformingError; end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Itchy::Errors
2
+ # Covers errors caused by a wrong object state.
3
+ class WrongStateError < StandardError; end
4
+ end
@@ -0,0 +1,5 @@
1
+ # Wrapper for all available errors.
2
+ module Itchy::Errors; end
3
+
4
+ # Load all available errors
5
+ Dir.glob(File.join(File.dirname(__FILE__), 'errors', '*.rb')) { |error_file| require error_file.chomp('.rb') }
@@ -0,0 +1,43 @@
1
+ module Itchy::EventHandlers
2
+ # Handler for AvailablePostfix event (image available).
3
+ class AvailablePostfixEventHandler < BaseEventHandler
4
+ # Handles an AvailablePostfix event.
5
+ #
6
+ # @param vmcatcher_event [Itchy::VmcatcherEvent] vmcatcher event to handle
7
+ # @param event_name [String] name of the event
8
+ def handle!(vmcatcher_event, event_name)
9
+ super
10
+ Itchy::Log.info "[#{self.class.name}] Handling updated image " \
11
+ "for #{vmcatcher_event.dc_identifier.inspect}"
12
+ save_descriptor(create_descriptor(vmcatcher_event), event_name)
13
+ image_transformer_instance = Itchy::ImageTransformer.new(@options)
14
+ image_transformer_instance.transform!(vmcatcher_event, vmcatcher_configuration)
15
+ end
16
+
17
+ private
18
+
19
+ # Create appliance descriptor from VMCATCHER_EVENT metadata.
20
+ #
21
+ # @param metadata [Itchy::VmcatcherEvent] vmcatcher event to get metadata from
22
+ # @return [String] json form of created descriptor
23
+ def create_descriptor(metadata)
24
+ os = ::Cloud::Appliance::Descriptor::Os.new(distribution: metadata.sl_osversion,
25
+ version: metadata.sl_osversion)
26
+ disk = ::Cloud::Appliance::Descriptor::Disk.new(type: :os,
27
+ format: @options.required_format,
28
+ path: "#{@options.output_dir}/#{metadata.dc_identifier}")
29
+
30
+ appliance = ::Cloud::Appliance::Descriptor::Appliance.new action: :registration
31
+ appliance.title = metadata.dc_title
32
+ appliance.version = metadata.hv_version
33
+ appliance.os = os
34
+ appliance.add_disk disk
35
+ appliance.add_group metadata.vo
36
+ appliance.description = metadata.dc_title
37
+ appliance.identifier = metadata.dc_identifier
38
+ appliance.attributes = metadata.to_hash
39
+
40
+ appliance.to_json
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,10 @@
1
+ module Itchy::EventHandlers
2
+ # Handler for AvailablePrefix event (image will be available).
3
+ class AvailablePrefixEventHandler < BaseEventHandler
4
+ def handle!(vmcatcher_event, event_file)
5
+ super
6
+ Itchy::Log.info "[#{self.class.name}] Handling #{vmcatcher_event.type.inspect}" \
7
+ 'This kind of event is just logged, nothing to process.'
8
+ end
9
+ end
10
+ end