Class: Bcome::Orchestrator::Loader

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

Instance Method Summary collapse

Constructor Details

#initialize(machines, registry_for_context) ⇒ Loader

Returns a new instance of Loader.



4
5
6
7
8
9
10
11
# File 'lib/orchestrator/loader.rb', line 4

def initialize(machines, registry_for_context)
  config_path = "#{Dir.pwd}/bcome/config/orchestration"
  @recipes_path = "#{config_path}/recipes.yml"
  @machine_targets_path = "#{config_path}/node_target_selectors.yml"
  @direct_commands_path = "#{config_path}/direct_command_sets.yml"
  @machines = machines
  @registry_for_context = registry_for_context
end

Instance Method Details

#direct_commandsObject



21
22
23
# File 'lib/orchestrator/loader.rb', line 21

def direct_commands
  @direct_commands ||= ::Bcome::Orchestrator::Factory.create_direct_commands_from_json(do_load_direct_commands)
end

#do_load_direct_commandsObject



29
30
31
# File 'lib/orchestrator/loader.rb', line 29

def do_load_direct_commands
  return json_from_file(@direct_commands_path)
end

#do_load_machine_targetsObject



33
34
35
# File 'lib/orchestrator/loader.rb', line 33

def do_load_machine_targets
  return json_from_file(@machine_targets_path)
end

#do_load_recipesObject



25
26
27
# File 'lib/orchestrator/loader.rb', line 25

def do_load_recipes
  return json_from_file(@recipes_path).select{|r| @registry_for_context.include?(r[:recipe_identifier]) }
end

#json_from_file(file_path) ⇒ Object



37
38
39
40
41
# File 'lib/orchestrator/loader.rb', line 37

def json_from_file(file_path)
  raise "Cannot load file #{file_path}" unless File.exist?(file_path)
  file_contents = File.read(file_path)
  return  YAML.load(file_contents)
end

#node_targetsObject



17
18
19
# File 'lib/orchestrator/loader.rb', line 17

def node_targets
  @node_targets ||= ::Bcome::Orchestrator::Factory.create_node_targets_from_json(do_load_machine_targets, @machines)
end

#recipesObject



13
14
15
# File 'lib/orchestrator/loader.rb', line 13

def recipes
  @recipes ||= ::Bcome::Orchestrator::Factory.create_recipes_from_json(do_load_recipes, node_targets, @machines, direct_commands)
end