Class: Nifty::Event::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/nifty/event/loader.rb

Overview

Takes care of loading appliance descriptors

Author:

  • Michal Kimle

Class Method Summary collapse

Class Method Details

.load_appliance(filename) ⇒ Cloud::Appliance::Descriptor::Appliance

Loads appliance from the file

Parameters:

  • filename (String)

Returns:

  • (Cloud::Appliance::Descriptor::Appliance)

    loaded appliance

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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