class Nifty::Event::Loader

Takes care of loading appliance descriptors

@author Michal Kimle

Public Class Methods

load_appliance(filename) click to toggle source

Loads appliance from the file

@param [String] filename @raise [Nifty::Errors::Event::LoaderError] when appliance descriptor is invalid @return [Cloud::Appliance::Descriptor::Appliance] loaded appliance

# File lib/nifty/event/loader.rb, line 13
def self.load_appliance(filename)
  logger.debug "Loading appliance from file #{filename.inspect}..."
  fail Nifty::Errors::Event::LoaderError, "Descriptor file #{filename.inspect} is not readable" unless File.readable?(filename)

  JSON::Validator.validate!(Nifty::APPLIANCE_SCHEMA, filename)

  file = File.read(filename)
  appliance = Cloud::Appliance::Descriptor::Appliance.from_json(file)
  logger.debug "Loaded appliance: #{appliance.inspect}"

  appliance
rescue JSON::Schema::ValidationError => ex
  fail Nifty::Errors::Event::LoaderError, ex
end