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
# File 'lib/orchestrator/loader.rb', line 4

def initialize(machines, registry_for_context)
  @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

#config_pathObject



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

def config_path
  defined?(::OrchestratorResource::CONFIG_PATH) ? ::OrchestratorResource::CONFIG_PATH : "#{Dir.pwd}/bcome/config/orchestration"
end

#direct_commandsObject



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

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

#do_load_direct_commandsObject



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

def do_load_direct_commands
  return json_from_file(@direct_commands_path)
end

#do_load_machine_targetsObject



36
37
38
# File 'lib/orchestrator/loader.rb', line 36

def do_load_machine_targets
  return json_from_file(@machine_targets_path)
end

#do_load_recipesObject



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

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



40
41
42
43
44
# File 'lib/orchestrator/loader.rb', line 40

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



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

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

#recipesObject



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

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