Class: HybridPlatformsConductor::HpcPlugins::PlatformHandler::YamlInventory
- Inherits:
-
PlatformHandler
- Object
- Plugin
- PlatformHandler
- HybridPlatformsConductor::HpcPlugins::PlatformHandler::YamlInventory
- Defined in:
- lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/yaml_inventory.rb
Overview
Basic platform handler, reading inventory and metadata from simple Yaml files.
Constant Summary
Constants included from LoggerHelpers
LoggerHelpers::LEVELS_MODIFIERS, LoggerHelpers::LEVELS_TO_STDERR
Instance Attribute Summary
Attributes inherited from PlatformHandler
#actions_executor, #nodes_handler, #platform_type, #repository_path
Instance Method Summary collapse
-
#actions_to_deploy_on(node, service, use_why_run: true) ⇒ Object
Get the list of actions to perform to deploy on a given node.
-
#deployable_services ⇒ Object
Get the list of services we can deploy [API] - This method is mandatory.
-
#init ⇒ Object
Initialize a new instance of this platform handler.
-
#known_nodes ⇒ Object
Get the list of known nodes.
-
#metadata_for(node) ⇒ Object
Get the metadata of a given node.
-
#parse_deploy_output(stdout, stderr) ⇒ Object
Parse stdout and stderr of a given deploy run and get the list of tasks with their status [API] - This method is mandatory.
-
#services_for(node) ⇒ Object
Return the services for a given node [API] - This method is mandatory.
Methods inherited from PlatformHandler
#<=>, #impacts_from, #info, inherited, #initialize, #name
Methods inherited from Plugin
extend_config_dsl_with, #initialize, valid?
Methods included from LoggerHelpers
#err, #init_loggers, #log_component=, #log_debug?, #log_level=, #out, #section, #set_loggers_format, #stderr_device, #stderr_device=, #stderr_displayed?, #stdout_device, #stdout_device=, #stdout_displayed?, #stdouts_to_s, #with_progress_bar
Constructor Details
This class inherits a constructor from HybridPlatformsConductor::PlatformHandler
Instance Method Details
#actions_to_deploy_on(node, service, use_why_run: true) ⇒ Object
Get the list of actions to perform to deploy on a given node. Those actions can be executed in parallel with other deployments on other nodes. They must be thread safe.
- API
-
This method is mandatory.
-
- API
-
@cmd_runner is accessible.
-
- API
-
@actions_executor is accessible.
-
- Parameters
-
node (String): Node to deploy on
-
service (String): Service to be deployed
-
use_why_run (Boolean): Do we use a why-run mode? [default = true]
- Result
-
Array< Hash<Symbol,Object> >: List of actions to be done
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/yaml_inventory.rb', line 74 def actions_to_deploy_on(node, service, use_why_run: true) # Load the check and deploy methods in a temporary class for encapsulation service_file = "#{@repository_path}/service_#{service}.rb" Class.new do include LoggerHelpers # Constructor # # Parameters:: # * *platform_handler* (PlatformHandler): PlatformHandler needing this service to be deployed # * *logger* (Logger): Logger to be used [default: Logger.new(STDOUT)] # * *logger_stderr* (Logger): Logger to be used for stderr [default: Logger.new(STDERR)] # * *config* (Config): Config to be used. [default: Config.new] # * *nodes_handler* (NodesHandler): NodesHandler to be used [default: NodesHandler.new] # * *cmd_runner* (CmdRunner): CmdRunner to be used [default: CmdRunner.new] def initialize( platform_handler, logger: Logger.new(STDOUT), logger_stderr: Logger.new(STDERR), config: Config.new, nodes_handler: NodesHandler.new, cmd_runner: CmdRunner.new ) init_loggers(logger, logger_stderr) @platform_handler = platform_handler @config = config @nodes_handler = nodes_handler @cmd_runner = cmd_runner end class_eval(File.read(service_file)) end.new( self, logger: @logger, logger_stderr: @logger_stderr, config: @config, nodes_handler: @nodes_handler, cmd_runner: @cmd_runner ).send(use_why_run ? :check : :deploy, node) end |
#deployable_services ⇒ Object
Get the list of services we can deploy
- API
-
This method is mandatory.
-
- Result
-
Array<String>: The corresponding services
58 59 60 |
# File 'lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/yaml_inventory.rb', line 58 def deployable_services Dir.glob("#{@repository_path}/service_*.rb").map { |file| File.basename(file).match(/^service_(.*)\.rb$/)[1] } end |
#init ⇒ Object
Initialize a new instance of this platform handler.
- API
-
This method is optional.
-
- API
-
@cmd_runner is accessible.
-
16 17 18 19 20 |
# File 'lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/yaml_inventory.rb', line 16 def init # This method is called when initializing a new instance of this platform handler, for a given repository. inv_file = "#{@repository_path}/inventory.yaml" @inventory = File.exist?(inv_file) ? YAML.load(File.read(inv_file)) : {} end |
#known_nodes ⇒ Object
Get the list of known nodes.
- API
-
This method is mandatory.
-
- Result
-
Array<String>: List of node names
27 28 29 |
# File 'lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/yaml_inventory.rb', line 27 def known_nodes @inventory.keys end |
#metadata_for(node) ⇒ Object
Get the metadata of a given node.
- API
-
This method is mandatory.
-
- Parameters
-
node (String): Node to read metadata from
- Result
-
Hash<Symbol,Object>: The corresponding metadata
38 39 40 |
# File 'lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/yaml_inventory.rb', line 38 def (node) (@inventory[node]['metadata'] || {}).transform_keys(&:to_sym) end |
#parse_deploy_output(stdout, stderr) ⇒ Object
Parse stdout and stderr of a given deploy run and get the list of tasks with their status
- API
-
This method is mandatory.
-
- Parameters
-
stdout (String): stdout to be parsed
-
stderr (String): stderr to be parsed
- Result
-
Array< Hash<Symbol,Object> >: List of task properties. The following properties should be returned, among free ones:
-
name (String): Task name
-
status (Symbol): Task status. Should be one of:
-
:changed: The task has been changed
-
:identical: The task has not been changed
-
-
diffs (String): Differences, if any
-
130 131 132 |
# File 'lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/yaml_inventory.rb', line 130 def parse_deploy_output(stdout, stderr) [] end |
#services_for(node) ⇒ Object
Return the services for a given node
- API
-
This method is mandatory.
-
- Parameters
-
node (String): node to read configuration from
- Result
-
Array<String>: The corresponding services
49 50 51 |
# File 'lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/yaml_inventory.rb', line 49 def services_for(node) @inventory[node]['services'] || [] end |