Class: OsCtld::ContainerControl::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/osctld/container_control/command.rb

Overview

Container control is used to interact with LXC containers

In order to work manipulate LXC containers, osctld has to fork and switch to the container’s system user. This class then provides an interface for various actions that manipulate the LXC containers.

Each command is a subclass of this class. It needs to define two classes: ‘Frontend` as a subclass of Frontend and `Runner` as a subclass of Runner. Command.run! invokes `Frontend` from osctld in daemon mode, where it is running as root.

The frontend initiates the runner, which is run in a forked process and as a different user, e.g. using Frontend#exec_runner or Frontend#fork_runner. The runner can return data, which the frontend can transform and return to the caller.

Class Method Summary collapse

Class Method Details

.run!(ct) ⇒ Object

Call command frontend

See the command for what arguments it accepts and what it returns.

Parameters:

  • ct (Container)
  • args (Hash)

    command arguments

  • kwargs (Hash)

    command arguments

Raises:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/osctld/container_control/command.rb', line 29

def self.run!(ct, *, **)
  f = self::Frontend.new(self, ct)
  ret = f.execute(*, **)

  if ret.is_a?(ContainerControl::Result)
    if ret.ok?
      ret.data
    elsif ret.user_runner?
      raise ContainerControl::UserRunnerError, ret.message
    else
      raise ContainerControl::Error, ret.message
    end
  else
    ret
  end
end