Class: HybridPlatformsConductor::HpcPlugins::Provisioner::Podman
- Inherits:
-
Provisioner
- Object
- Plugin
- Provisioner
- HybridPlatformsConductor::HpcPlugins::Provisioner::Podman
- Defined in:
- lib/hybrid_platforms_conductor/hpc_plugins/provisioner/podman.rb
Overview
Provision Podman containers
Constant Summary
Constants included from LoggerHelpers
LoggerHelpers::LEVELS_MODIFIERS, LoggerHelpers::LEVELS_TO_STDERR
Instance Method Summary collapse
-
#create ⇒ Object
Create an instance.
-
#destroy ⇒ Object
Destroy an instance Prerequisite: create has been called before [API] - This method is mandatory.
-
#ip ⇒ Object
Return the IP address of an instance.
-
#start ⇒ Object
Start an instance Prerequisite: create has been called before [API] - This method is mandatory.
-
#state ⇒ Object
Returns the state of an instance [API] - This method is mandatory.
-
#stop ⇒ Object
Stop an instance Prerequisite: create has been called before [API] - This method is mandatory.
Methods inherited from Provisioner
#default_timeout, #initialize, #wait_for_port, #wait_for_port!, #wait_for_state, #wait_for_state!, #with_running_instance
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
Methods inherited from Plugin
extend_config_dsl_with, #initialize, valid?
Constructor Details
This class inherits a constructor from HybridPlatformsConductor::Provisioner
Instance Method Details
#create ⇒ Object
Create an instance. Reuse an existing one if it already exists.
- API
-
This method is mandatory
-
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hybrid_platforms_conductor/hpc_plugins/provisioner/podman.rb', line 16 def create # Get the image name for this node image = @nodes_handler.get_image_of(@node).to_sym # Find if we have such an image registered if @config.known_os_images.include?(image) # Build the image if it does not exist image_tag = "hpc_image_#{image}" image_futex_file = "#{Dir.tmpdir}/hpc_podman_image_futexes/#{image_tag}" FileUtils.mkdir_p File.dirname(image_futex_file) Futex.new(image_futex_file).open do @cmd_runner.run_cmd "cd #{@config.os_image_dir(image)} && #{podman_cmd} build --tag #{image_tag} --security-opt seccomp=/usr/share/containers/seccomp.json --cgroup-manager=cgroupfs ." end container_name = "hpc_container_#{@node}_#{@environment}" container_futex_file = "#{Dir.tmpdir}/hpc_podman_container_futexes/#{image_tag}" FileUtils.mkdir_p File.dirname(container_futex_file) Futex.new(container_futex_file).open do _exit_status, stdout, _stderr = @cmd_runner.run_cmd "#{podman_cmd} container list --all | grep #{container_name}", expected_code: [0, 1] existing_container = !stdout.strip.empty? @cmd_runner.run_cmd "#{podman_cmd} container create --name #{container_name} #{image_tag}" unless existing_container @container = container_name end else raise "[ #{@node}/#{@environment} ] - Unknown OS image #{image} defined for node #{@node}" end end |
#destroy ⇒ Object
Destroy an instance Prerequisite: create has been called before
- API
-
This method is mandatory
-
61 62 63 64 |
# File 'lib/hybrid_platforms_conductor/hpc_plugins/provisioner/podman.rb', line 61 def destroy log_debug "[ #{@node}/#{@environment} ] - Destroy Podman Container #{@container} ..." @cmd_runner.run_cmd "#{podman_cmd} container rm #{@container}" end |
#ip ⇒ Object
Return the IP address of an instance. Prerequisite: create has been called before.
- API
-
This method is optional
-
- Result
-
String or nil: The instance IP address, or nil if this information is not relevant
98 99 100 101 102 103 104 |
# File 'lib/hybrid_platforms_conductor/hpc_plugins/provisioner/podman.rb', line 98 def ip # Get its IP that could have changed upon restart # cf https://github.com/moby/moby/issues/2801 # Make sure we refresh its info before querying it, as we could hit a cache of a previous IP. _exit_status, stdout, _stderr = @cmd_runner.run_cmd "#{podman_cmd} container inspect #{@container} | grep IPAddress" stdout.strip.match(/\d+\.\d+\.\d+\.\d+/)[0] end |
#start ⇒ Object
Start an instance Prerequisite: create has been called before
- API
-
This method is mandatory
-
45 46 47 48 |
# File 'lib/hybrid_platforms_conductor/hpc_plugins/provisioner/podman.rb', line 45 def start log_debug "[ #{@node}/#{@environment} ] - Start Podman Container #{@container} ..." @cmd_runner.run_cmd "#{podman_cmd} container start --cgroup-manager=cgroupfs #{@container}" end |
#state ⇒ Object
Returns the state of an instance
- API
-
This method is mandatory
-
- Result
-
Symbol: The state the instance is in. Possible values are:
-
:missing: The instance does not exist
-
:created: The instance has been created but is not running
-
:running: The instance is running
-
:exited: The instance has run and is now stopped
-
:error: The instance is in error
-
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/hybrid_platforms_conductor/hpc_plugins/provisioner/podman.rb', line 76 def state if !defined?(@container) || @container.nil? :missing else begin _exit_status, stdout, _stderr = @cmd_runner.run_cmd "#{podman_cmd} container inspect #{@container}" status = JSON.parse(stdout).first['State']['Status'].to_sym status = :created if status == :configured status rescue log_warn "Error while reading state of Podman container #{@container}: #{$!}" :error end end end |
#stop ⇒ Object
Stop an instance Prerequisite: create has been called before
- API
-
This method is mandatory
-
53 54 55 56 |
# File 'lib/hybrid_platforms_conductor/hpc_plugins/provisioner/podman.rb', line 53 def stop log_debug "[ #{@node}/#{@environment} ] - Stop Podman Container #{@container} ..." @cmd_runner.run_cmd "#{podman_cmd} container stop #{@container}" end |