class Fleet::Unit

Attributes

active[R]

linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.

controller[R]

linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.

desc[R]

linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.

load[R]

linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.

machine[R]

linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.

name[R]

linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.

state[R]

linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.

sub[R]

linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.

Public Class Methods

new(controller:, name:, state:, load:, active:, sub:, desc:, machine:) click to toggle source
# File lib/fleet/unit.rb, line 9
def initialize(controller:, name:, state:, load:, active:, sub:, desc:, machine:)
  @controller = controller
  @name = name
  @state = state
  @load = load
  @active = active
  @sub = sub
  @machine = machine
end

Public Instance Methods

==(other_unit) click to toggle source
# File lib/fleet/unit.rb, line 79
def ==(other_unit)
  name == other_unit.name
end
Also aliased as: eql?
creating?() click to toggle source
# File lib/fleet/unit.rb, line 31
def creating?
  active == 'activating' && sub == 'start-pre'
end
docker_inspect(container_name = name) click to toggle source

returns a JSON object representing the container assumes that this unit corresponds to a docker container

# File lib/fleet/unit.rb, line 74
def docker_inspect(container_name = name)
  raw = ssh('docker', 'inspect', container_name)
  JSON.parse(raw)
end
docker_port(internal_port, container_name = name) click to toggle source

gets the external port corresponding to the internal port specified assumes that this unit corresponds to a docker container TODO: split this sort of docker-related functionality out into a separate class

# File lib/fleet/unit.rb, line 53
def docker_port(internal_port, container_name = name)
  docker_runner = Fleetctl::Runner::SSH.new('docker', 'port', container_name, internal_port)
  docker_runner.run(host: ip)
  output = docker_runner.output
  if output
    output.rstrip!
    output.split(':').last
  end
end
eql?(other_unit)
Alias for: ==
failed?() click to toggle source
# File lib/fleet/unit.rb, line 35
def failed?
  active == 'failed' && sub == 'failed'
end
ip() click to toggle source
# File lib/fleet/unit.rb, line 27
def ip
  machine && machine.ip
end
running?() click to toggle source
# File lib/fleet/unit.rb, line 39
def running?
  active == 'active' && sub == 'running'
end
ssh(*command, port: 22) click to toggle source

run the command on host (string, array of command + args, whatever) and return stdout

# File lib/fleet/unit.rb, line 44
def ssh(*command, port: 22)
  runner = Fleetctl::Runner::SSH.new([*command].flatten.compact.join(' '))
  runner.run(host: ip, ssh_options: { port: port })
  runner.output
end