itchy 0.0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/itchy +12 -1
- data/config/itchy.yml +1 -1
- data/lib/itchy/errors/event_handle_error.rb +4 -0
- data/lib/itchy/errors/{file_inspecting_error.rb → file_inspect_error.rb} +1 -1
- data/lib/itchy/errors/{format_converting_error.rb → format_conversion_error.rb} +1 -1
- data/lib/itchy/errors/{image_transforming_error.rb → image_transformation_error.rb} +1 -1
- data/lib/itchy/errors/{working_with_files_error.rb → prepare_env_error.rb} +1 -1
- data/lib/itchy/errors.rb +2 -0
- data/lib/itchy/event_handlers/available_postfix_event_handler.rb +11 -5
- data/lib/itchy/event_handlers/base_event_handler.rb +8 -7
- data/lib/itchy/event_handlers/expire_postfix_event_handler.rb +7 -1
- data/lib/itchy/event_processer.rb +9 -9
- data/lib/itchy/format_converter.rb +4 -2
- data/lib/itchy/image_transformer.rb +33 -26
- data/lib/itchy/metadata_archiver.rb +1 -1
- data/lib/itchy/version.rb +1 -1
- data/lib/itchy/vmcatcher_event.rb +0 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33732680739a9df7269d7b6da2617791ad106fe8
|
4
|
+
data.tar.gz: b3ec978d0f1bd1dd036474cffe4fa91d0c90782f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dcacca6d9448fbde79357291c2d58fa01f31ff00e9ac5745110ae8bd9bc62795838a9eb60b06c66bccffaa7f6acd22205c13e0abbc52681a27a13a8e24ba9f8
|
7
|
+
data.tar.gz: 95ff929be64811219debf0676cbf9fb39977c2d77a5b6f871bd831fa6b5b4be1da233d990c9a8d6b648abe2fd9a350b5f2162b371f5fed489306fe1f1548258b
|
data/bin/itchy
CHANGED
@@ -31,6 +31,7 @@ class ItchyRunnable < Thor
|
|
31
31
|
|
32
32
|
AVAILABLE_LOG_LEVELS = %w(debug info warn error fatal unknown).freeze
|
33
33
|
AVAILABLE_AUTH_METHODS = %w(none basic).freeze
|
34
|
+
ERROR_EXIT_CODE = 1
|
34
35
|
|
35
36
|
shared_option_log_to = [:log_to, { type: :string, default: Itchy::Settings.log_to,
|
36
37
|
aliases: '-l', desc: 'Logging output, file path or stderr/stdout' }]
|
@@ -91,8 +92,12 @@ class ItchyRunnable < Thor
|
|
91
92
|
|
92
93
|
Itchy::Log.info "[#{self.class.name}] Processing started"
|
93
94
|
Itchy::Log.debug "[#{self.class.name}] With options: #{opts.inspect}"
|
95
|
+
begin
|
96
|
+
Itchy::EventProcesser.new(Itchy::VmcatcherConfiguration.new(ENV), opts).process!
|
97
|
+
rescue RuntimeError
|
98
|
+
exit ERROR_EXIT_CODE
|
99
|
+
end
|
94
100
|
|
95
|
-
Itchy::EventProcesser.new(Itchy::VmcatcherConfiguration.new(ENV), opts).process!
|
96
101
|
end
|
97
102
|
|
98
103
|
private
|
@@ -137,6 +142,12 @@ class ItchyRunnable < Thor
|
|
137
142
|
logger.level = opts.log_level
|
138
143
|
logger
|
139
144
|
end
|
145
|
+
|
146
|
+
# Overrides thors method for exiting
|
147
|
+
def exit_on_failure?
|
148
|
+
true
|
149
|
+
end
|
150
|
+
|
140
151
|
end
|
141
152
|
|
142
153
|
ItchyRunnable.start
|
data/config/itchy.yml
CHANGED
data/lib/itchy/errors.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Wrapper for all available errors.
|
2
2
|
module Itchy::Errors; end
|
3
3
|
|
4
|
+
require File.join(File.dirname(__FILE__), 'errors', 'event_processing_error')
|
5
|
+
require File.join(File.dirname(__FILE__), 'errors', 'image_transformation_error')
|
4
6
|
# Load all available errors
|
5
7
|
Dir.glob(File.join(File.dirname(__FILE__), 'errors', '*.rb')) { |error_file| require error_file.chomp('.rb') }
|
@@ -9,9 +9,15 @@ module Itchy::EventHandlers
|
|
9
9
|
super
|
10
10
|
Itchy::Log.info "[#{self.class.name}] Handling updated image " \
|
11
11
|
"for #{vmcatcher_event.dc_identifier.inspect}"
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
begin
|
13
|
+
image_transformer_instance = Itchy::ImageTransformer.new(@options)
|
14
|
+
new_file_name = image_transformer_instance.transform!(vmcatcher_event, vmcatcher_configuration)
|
15
|
+
save_descriptor(create_descriptor(vmcatcher_event, new_file_name), event_name)
|
16
|
+
rescue Itchy::Errors::PrepareEnvError, ArgumentError, Itchy::Errors::ImageTransformationError => ex
|
17
|
+
Itchy::Log.error "[#{self.class.name}] Problem with handling event #{event_name}" \
|
18
|
+
"Event handling failed with #{ex.message}"
|
19
|
+
fail Itchy::Errors::EventHandleError, ex
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
private
|
@@ -20,12 +26,12 @@ module Itchy::EventHandlers
|
|
20
26
|
#
|
21
27
|
# @param metadata [Itchy::VmcatcherEvent] vmcatcher event to get metadata from
|
22
28
|
# @return [String] json form of created descriptor
|
23
|
-
def create_descriptor(metadata)
|
29
|
+
def create_descriptor(metadata, file_name)
|
24
30
|
os = ::Cloud::Appliance::Descriptor::Os.new(distribution: metadata.sl_osversion,
|
25
31
|
version: metadata.sl_osversion)
|
26
32
|
disk = ::Cloud::Appliance::Descriptor::Disk.new(type: :os,
|
27
33
|
format: @options.required_format,
|
28
|
-
path: "#{@options.output_dir}/#{
|
34
|
+
path: "#{@options.output_dir}/#{file_name}")
|
29
35
|
|
30
36
|
appliance = ::Cloud::Appliance::Descriptor::Appliance.new action: :registration
|
31
37
|
appliance.title = metadata.dc_title
|
@@ -57,17 +57,18 @@ module Itchy::EventHandlers
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
# Save created descriptor to descriptor directory.
|
61
|
-
# is stored in its own directory.
|
60
|
+
# Save created descriptor to descriptor directory.
|
62
61
|
#
|
63
62
|
# @param descriptor [String] json form of appliance descriptor
|
64
63
|
# @param name [String] name of appliance descriptor (event name)
|
65
64
|
def save_descriptor(descriptor, name)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
65
|
+
begin
|
66
|
+
File.open("#{@options.descriptor_dir}/#{File.basename(name)}", 'w') { |f| f.write(descriptor) }
|
67
|
+
rescue SystemCallError => ex
|
68
|
+
Itchy::Log.fatal "[#{self.class.name}] Failed to save a descriptor #{File.basename(name)}. " \
|
69
|
+
"Attempt failed with error #{ex.message}"
|
70
|
+
fail Itchy::Errors::PrepareEnvError, ex
|
71
|
+
end
|
71
72
|
end
|
72
73
|
|
73
74
|
protected
|
@@ -9,7 +9,13 @@ module Itchy::EventHandlers
|
|
9
9
|
super
|
10
10
|
Itchy::Log.info "[#{self.class.name}] Handling expired image " \
|
11
11
|
"for #{vmcatcher_event.dc_identifier.inspect}"
|
12
|
-
|
12
|
+
begin
|
13
|
+
save_descriptor(create_descriptor(vmcatcher_event), event_name)
|
14
|
+
rescue Itchy::Errors::PrepareEnvError => ex
|
15
|
+
Itchy::Log.error "[#{self.cass.name}] Problem with handling event #{event_name}" \
|
16
|
+
"Event handling failed with #{ex.message}"
|
17
|
+
fail Itchy::Errors::EventHandleError, ex
|
18
|
+
end
|
13
19
|
end
|
14
20
|
|
15
21
|
private
|
@@ -23,20 +23,19 @@ module Itchy
|
|
23
23
|
|
24
24
|
archived_events do |event, event_file|
|
25
25
|
begin
|
26
|
-
|
27
26
|
begin
|
28
27
|
event_handler = Itchy::EventHandlers.const_get("#{event.type}EventHandler")
|
29
28
|
event_handler = event_handler.new(vmc_configuration, options)
|
30
29
|
event_handler.handle!(event, event_file)
|
31
|
-
rescue => ex
|
32
|
-
Itchy::Log.error "[#{self.class.name}] Due to error #{ex.message} event #{event_file}" \
|
33
|
-
"was not processed!!!
|
34
|
-
|
30
|
+
rescue Itchy::Errors::EventHandleError => ex
|
31
|
+
Itchy::Log.error "[#{self.class.name}] Due to error '#{ex.message}' event '#{event_file}'" \
|
32
|
+
" was not processed!!! Aborting."
|
33
|
+
fail RuntimeError, "Unprocessed event"
|
35
34
|
end
|
36
35
|
|
37
36
|
begin
|
38
37
|
clean_event!(event, event_file)
|
39
|
-
rescue => ex
|
38
|
+
rescue SystemCallError => ex
|
40
39
|
Itchy::Log.error "[#{self.class.name}] Event #{event_file} was processed, but not cleaned!!!"
|
41
40
|
end
|
42
41
|
|
@@ -72,7 +71,7 @@ module Itchy
|
|
72
71
|
def read_event(json)
|
73
72
|
Itchy::VmcatcherEvent.new(::File.read(json))
|
74
73
|
rescue => ex
|
75
|
-
Itchy::Log.error '
|
74
|
+
Itchy::Log.error 'Failed to load event!!!'
|
76
75
|
return ex
|
77
76
|
end
|
78
77
|
|
@@ -82,11 +81,12 @@ module Itchy
|
|
82
81
|
# @param event_file [String] path to file containing event info
|
83
82
|
def clean_event!(_event, event_file)
|
84
83
|
Itchy::Log.info "[#{self.class.name}] Cleaning up"
|
84
|
+
Itchy::Log.debug "[#{self.class.name}] Deleting file #{event_file}"
|
85
85
|
|
86
86
|
begin
|
87
87
|
::FileUtils.rm_f event_file
|
88
|
-
rescue => ex
|
89
|
-
Itchy::Log.
|
88
|
+
rescue SystemCallError => ex
|
89
|
+
Itchy::Log.error 'Failed to clean up event!!!'
|
90
90
|
return ex
|
91
91
|
end
|
92
92
|
end
|
@@ -28,7 +28,8 @@ module Itchy
|
|
28
28
|
"original format: #{file_format} to " \
|
29
29
|
"required format: #{required_format}."
|
30
30
|
|
31
|
-
|
31
|
+
new_file_name = "#{::Time.now.to_i}_#{@metadata.dc_identifier}"
|
32
|
+
convert_cmd = Mixlib::ShellOut.new("qemu-img convert -f #{file_format} -O #{required_format} #{@unpacking_dir}/#{@metadata.dc_identifier} #{output_dir}/#{new_file_name}")
|
32
33
|
convert_cmd.run_command
|
33
34
|
begin
|
34
35
|
convert_cmd.error!
|
@@ -36,8 +37,9 @@ module Itchy
|
|
36
37
|
Mixlib::Shellout::InvalidCommandOption => ex
|
37
38
|
Itchy::Log.fatal "[#{self.class.name}] Converting of image failed with " \
|
38
39
|
"error messages #{convert_cmd.stderr}."
|
39
|
-
fail Itchy::Errors::
|
40
|
+
fail Itchy::Errors::FormatConversionError, ex
|
40
41
|
end
|
42
|
+
new_file_name
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
@@ -43,15 +43,16 @@ module Itchy
|
|
43
43
|
unpacking_dir = copy_unpacked!(metadata, vmcatcher_configuration)
|
44
44
|
end
|
45
45
|
if file_format == @options.required_format
|
46
|
-
copy_same_format(unpacking_dir, metadata)
|
46
|
+
new_file_name = copy_same_format(unpacking_dir, metadata)
|
47
47
|
else
|
48
48
|
converter = Itchy::FormatConverter.new(unpacking_dir, metadata, vmcatcher_configuration)
|
49
|
-
converter.convert!(file_format, @options.required_format, @options.output_dir)
|
49
|
+
new_file_name = converter.convert!(file_format, @options.required_format, @options.output_dir)
|
50
50
|
end
|
51
|
-
rescue Itchy::Errors::
|
52
|
-
Itchy::Errors::
|
53
|
-
fail Itchy::Errors::
|
51
|
+
rescue Itchy::Errors::FileInspectError, Itchy::Errors::FormatConversionError,
|
52
|
+
Itchy::Errors::PrepareEnvError => ex
|
53
|
+
fail Itchy::Errors::ImageTransformationError, ex
|
54
54
|
end
|
55
|
+
new_file_name
|
55
56
|
end
|
56
57
|
|
57
58
|
private
|
@@ -66,15 +67,16 @@ module Itchy
|
|
66
67
|
image_format_tester.run_command
|
67
68
|
begin
|
68
69
|
image_format_tester.error!
|
69
|
-
rescue
|
70
|
+
rescue Mixlib::ShellOut::ShellCommandFailed, Mixlib::ShellOut::CommandTimeout,
|
71
|
+
Mixlib::ShellOut::InvalidCommandOption => ex
|
70
72
|
Itchy::Log.error "[#{self.class.name}] Checking file format for" \
|
71
73
|
"#{file} failed!"
|
72
|
-
fail Itchy::Errors::
|
74
|
+
fail Itchy::Errors::FileInspectError, ex
|
73
75
|
end
|
74
76
|
file_format = image_format_tester.stdout.scan(FORMAT_PATTERN)[0].flatten.first
|
75
77
|
unless KNOWN_IMAGE_FORMATS.include? file_format
|
76
78
|
Itchy::Log.error "Image format #{file_format} is unknown and not supported!"
|
77
|
-
fail Itchy::Errors::
|
79
|
+
fail Itchy::Errors::FileInspectError
|
78
80
|
end
|
79
81
|
file_format
|
80
82
|
end
|
@@ -96,9 +98,10 @@ module Itchy
|
|
96
98
|
tar_cmd.run_command
|
97
99
|
begin
|
98
100
|
tar_cmd.error!
|
99
|
-
rescue
|
101
|
+
rescue Mixlib::ShellOut::ShellCommandFailed, Mixlib::ShellOut::CommandTimeout,
|
102
|
+
Mixlib::ShellOut::InvalidCommandOption => ex
|
100
103
|
Itchy::Log.error "Unpacking of archive failed with #{tar_cmd.stderr}"
|
101
|
-
fail Itchy::Errors::
|
104
|
+
fail Itchy::Errors::PrepareEnvError, ex
|
102
105
|
end
|
103
106
|
|
104
107
|
unpacking_dir
|
@@ -121,7 +124,7 @@ module Itchy
|
|
121
124
|
counter += 1
|
122
125
|
# unsupported ova content (more than one disk)
|
123
126
|
return nil if counter > 1
|
124
|
-
File.new("#{directory}/#{file}", 'r').rename(file, "#{metadata.dc_identifier}
|
127
|
+
File.new("#{directory}/#{file}", 'r').rename(file, "#{metadata.dc_identifier}")
|
125
128
|
end
|
126
129
|
end
|
127
130
|
return nil if counter == 0
|
@@ -129,25 +132,28 @@ module Itchy
|
|
129
132
|
file_format
|
130
133
|
end
|
131
134
|
|
132
|
-
#
|
135
|
+
# Method moves image files to output directory
|
133
136
|
#
|
134
137
|
# @param directory [String] name of directory where image is saved
|
135
138
|
# @param metadata [Itchy::VmcatcherEvent] event metadata
|
136
139
|
def copy_same_format(directory, metadata)
|
137
140
|
Itchy::Log.info "[#{self.class.name}] Image #{metadata.dc_identifier.inspect} " \
|
138
|
-
'is already in the required format.
|
141
|
+
'is already in the required format. Moving it to output directory.'
|
139
142
|
|
143
|
+
new_file_name = "#{::Time.now.to_i}_#{metadata.dc_identifier}"
|
140
144
|
begin
|
141
|
-
::FileUtils.
|
142
|
-
|
143
|
-
|
145
|
+
::FileUtils.mv("#{directory}/#{metadata.dc_identifier}",
|
146
|
+
"#{@options.output_dir}/#{new_file_name}")
|
147
|
+
rescue SystemCallError => ex
|
148
|
+
Itchy::Log.fatal "[#{self.class.name}] Failed to move a file " \
|
144
149
|
"for #{metadata.dc_identifier.inspect}: " \
|
145
150
|
"#{ex.message}"
|
146
|
-
fail Itchy::Errors::
|
151
|
+
fail Itchy::Errors::PrepareEnvError, ex
|
147
152
|
end
|
153
|
+
new_file_name
|
148
154
|
end
|
149
155
|
|
150
|
-
#
|
156
|
+
# Method for copying image file from vmCatcher cache to processing places
|
151
157
|
#
|
152
158
|
# @param metadata [Itchy::VmcatcherEvent] event metadata
|
153
159
|
# @param vmcatcher_configuration [Itchy::VmcatcherConfiguration] current VMC configuration
|
@@ -157,15 +163,15 @@ module Itchy
|
|
157
163
|
"for #{metadata.dc_identifier.inspect}"
|
158
164
|
unpacking_dir = prepare_image_temp_dir(metadata, vmcatcher_configuration).flatten.first
|
159
165
|
begin
|
160
|
-
::FileUtils.
|
166
|
+
::FileUtils.cp(
|
161
167
|
orig_image_file(metadata, vmcatcher_configuration),
|
162
168
|
unpacking_dir
|
163
169
|
)
|
164
|
-
rescue => ex
|
165
|
-
Itchy::Log.fatal "[#{self.class.name}] Failed to create a
|
170
|
+
rescue SystemCallError => ex
|
171
|
+
Itchy::Log.fatal "[#{self.class.name}] Failed to create a copy " \
|
166
172
|
"for #{metadata.dc_identifier.inspect}: " \
|
167
173
|
"#{ex.message}"
|
168
|
-
fail Itchy::Errors::
|
174
|
+
fail Itchy::Errors::PrepareEnvError, ex
|
169
175
|
end
|
170
176
|
|
171
177
|
unpacking_dir
|
@@ -190,11 +196,11 @@ module Itchy
|
|
190
196
|
|
191
197
|
begin
|
192
198
|
::FileUtils.mkdir_p temp_dir
|
193
|
-
rescue => ex
|
199
|
+
rescue SystemCallError => ex
|
194
200
|
Itchy::Log.fatal "[#{self.class.name}] Failed to create a directory " \
|
195
201
|
"for #{metadata.dc_identifier.inspect}: " \
|
196
202
|
"#{ex.message}"
|
197
|
-
fail Itchy::Errors::
|
203
|
+
fail Itchy::Errors::PrepareEnvError, ex
|
198
204
|
end
|
199
205
|
end
|
200
206
|
|
@@ -207,10 +213,11 @@ module Itchy
|
|
207
213
|
image_format_tester.run_command
|
208
214
|
begin
|
209
215
|
image_format_tester.error!
|
210
|
-
rescue
|
216
|
+
rescue Mixlib::ShellOut::ShellCommandFailed, Mixlib::ShellOut::CommandTimeout,
|
217
|
+
Mixlib::ShellOut::InvalidCommandOption => ex
|
211
218
|
Itchy::Log.error "[#{self.class.name}] Checking file format for" \
|
212
219
|
"#{file} failed with #{image_format_tester.stderr}"
|
213
|
-
fail Itchy::Errors::
|
220
|
+
fail Itchy::Errors::FileInspectError, ex
|
214
221
|
|
215
222
|
end
|
216
223
|
temp = image_format_tester.stdout
|
@@ -36,7 +36,7 @@ module Itchy
|
|
36
36
|
begin
|
37
37
|
event_handler = Itchy::EventHandlers.const_get("#{vmc_event.type}EventHandler")
|
38
38
|
rescue NameError => ex
|
39
|
-
|
39
|
+
fail Itchy::Errors::UnknownEventError,
|
40
40
|
"Unknown event type #{vmc_event.type.inspect} detected: #{ex.message}"
|
41
41
|
end
|
42
42
|
|
data/lib/itchy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lubomir Kosaristan
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: opennebula
|
@@ -312,14 +312,15 @@ files:
|
|
312
312
|
- lib/itchy/errors.rb
|
313
313
|
- lib/itchy/errors/abstract_env_error.rb
|
314
314
|
- lib/itchy/errors/env_lookup_error.rb
|
315
|
+
- lib/itchy/errors/event_handle_error.rb
|
315
316
|
- lib/itchy/errors/event_processing_error.rb
|
316
|
-
- lib/itchy/errors/
|
317
|
-
- lib/itchy/errors/
|
318
|
-
- lib/itchy/errors/
|
317
|
+
- lib/itchy/errors/file_inspect_error.rb
|
318
|
+
- lib/itchy/errors/format_conversion_error.rb
|
319
|
+
- lib/itchy/errors/image_transformation_error.rb
|
319
320
|
- lib/itchy/errors/not_found_error.rb
|
320
321
|
- lib/itchy/errors/not_implemented_error.rb
|
322
|
+
- lib/itchy/errors/prepare_env_error.rb
|
321
323
|
- lib/itchy/errors/unknown_event_error.rb
|
322
|
-
- lib/itchy/errors/working_with_files_error.rb
|
323
324
|
- lib/itchy/errors/wrong_state_error.rb
|
324
325
|
- lib/itchy/event_handlers.rb
|
325
326
|
- lib/itchy/event_handlers/available_postfix_event_handler.rb
|
@@ -372,7 +373,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
372
373
|
version: '0'
|
373
374
|
requirements: []
|
374
375
|
rubyforge_project:
|
375
|
-
rubygems_version: 2.
|
376
|
+
rubygems_version: 2.4.6
|
376
377
|
signing_key:
|
377
378
|
specification_version: 4
|
378
379
|
summary: Event handler for vmcatcher
|