Module: Cloudkeeper::Utils::Appliance
- Included in:
- Managers::ApplianceManager
- Defined in:
- lib/cloudkeeper/utils/appliance.rb
Instance Method Summary collapse
- #clean_image_file(filename) ⇒ Object
- #clean_image_files(appliance) ⇒ Object
- #convert_image!(appliance, image_file) ⇒ Object
- #log_expired(expirable, message) ⇒ Object
- #prepare_image!(appliance) ⇒ Object
- #update_image?(image_list_appliance, backend_appliance) ⇒ Boolean
- #update_metadata?(image_list_appliance, backend_appliance) ⇒ Boolean
Instance Method Details
#clean_image_file(filename) ⇒ Object
17 18 19 |
# File 'lib/cloudkeeper/utils/appliance.rb', line 17 def clean_image_file(filename) File.delete(filename) if File.exist?(filename) end |
#clean_image_files(appliance) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/cloudkeeper/utils/appliance.rb', line 8 def clean_image_files(appliance) return unless appliance && appliance.image logger.debug "Cleaning downloaded image files for appliance #{appliance.identifier.inspect}" appliance.image.image_files.each { |image_file| clean_image_file image_file.file } rescue ::IOError => ex logger.warn "Appliance cleanup error: #{ex.}" end |
#convert_image!(appliance, image_file) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cloudkeeper/utils/appliance.rb', line 37 def convert_image!(appliance, image_file) format = acceptable_formats.find { |acceptable_format| image_file.respond_to? "to_#{acceptable_format}".to_sym } unless format raise Cloudkeeper::Errors::Image::Format::NoRequiredFormatAvailableError, "image #{image_file.inspect} cannot be converted to any acceptable format" end appliance.image.add_image_file image_file.send("to_#{format}".to_sym) rescue Cloudkeeper::Errors::Image::Format::NoRequiredFormatAvailableError, Cloudkeeper::Errors::CommandExecutionError, Cloudkeeper::Errors::ArgumentError, ::IOError, ::SystemCallError => ex raise Cloudkeeper::Errors::Image::ConversionError, "Image #{appliance.image.uri.inspect} conversion error: #{ex.}" end |
#log_expired(expirable, message) ⇒ Object
4 5 6 |
# File 'lib/cloudkeeper/utils/appliance.rb', line 4 def log_expired(expirable, ) logger.info "#{} #{expirable.identifier.inspect}" end |
#prepare_image!(appliance) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/cloudkeeper/utils/appliance.rb', line 29 def prepare_image!(appliance) image_file = Cloudkeeper::Managers::ImageManager.secure_download_image(appliance.image.uri, appliance.image.checksum) appliance.image.add_image_file image_file return if acceptable_formats.include? image_file.format convert_image! appliance, image_file end |
#update_image?(image_list_appliance, backend_appliance) ⇒ Boolean
21 22 23 |
# File 'lib/cloudkeeper/utils/appliance.rb', line 21 def update_image?(image_list_appliance, backend_appliance) image_list_appliance.image.digest != backend_appliance.image.digest end |
#update_metadata?(image_list_appliance, backend_appliance) ⇒ Boolean
25 26 27 |
# File 'lib/cloudkeeper/utils/appliance.rb', line 25 def (image_list_appliance, backend_appliance) image_list_appliance.digest != backend_appliance.digest end |