Class: Fleet::Unit
- Inherits:
-
Object
- Object
- Fleet::Unit
- Defined in:
- lib/fleet/unit.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded.
-
#controller ⇒ Object
readonly
linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded.
-
#desc ⇒ Object
readonly
linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded.
-
#load ⇒ Object
readonly
linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded.
-
#machine ⇒ Object
readonly
linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded.
-
#name ⇒ Object
readonly
linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded.
-
#state ⇒ Object
readonly
linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded.
-
#sub ⇒ Object
readonly
linuxrackers.com/doku.php?id=fedora_systemd_services LOAD = Reflects whether the unit definition was properly loaded.
Instance Method Summary collapse
- #==(other_unit) ⇒ Object (also: #eql?)
- #creating? ⇒ Boolean
-
#docker_inspect(container_name = name) ⇒ Object
returns a JSON object representing the container assumes that this unit corresponds to a docker container.
-
#docker_port(internal_port, container_name = name) ⇒ Object
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.
- #failed? ⇒ Boolean
-
#initialize(controller:, name:, state:, load:, active:, sub:, desc:, machine:) ⇒ Unit
constructor
A new instance of Unit.
- #ip ⇒ Object
- #running? ⇒ Boolean
-
#ssh(*command, port: 22) ⇒ Object
run the command on host (string, array of command + args, whatever) and return stdout.
Constructor Details
#initialize(controller:, name:, state:, load:, active:, sub:, desc:, machine:) ⇒ Unit
Returns a new instance of Unit.
9 10 11 12 13 14 15 16 17 |
# 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 |
Instance Attribute Details
#active ⇒ Object (readonly)
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.
7 8 9 |
# File 'lib/fleet/unit.rb', line 7 def active @active end |
#controller ⇒ Object (readonly)
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.
7 8 9 |
# File 'lib/fleet/unit.rb', line 7 def controller @controller end |
#desc ⇒ Object (readonly)
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.
7 8 9 |
# File 'lib/fleet/unit.rb', line 7 def desc @desc end |
#load ⇒ Object (readonly)
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.
7 8 9 |
# File 'lib/fleet/unit.rb', line 7 def load @load end |
#machine ⇒ Object (readonly)
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.
7 8 9 |
# File 'lib/fleet/unit.rb', line 7 def machine @machine end |
#name ⇒ Object (readonly)
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.
7 8 9 |
# File 'lib/fleet/unit.rb', line 7 def name @name end |
#state ⇒ Object (readonly)
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.
7 8 9 |
# File 'lib/fleet/unit.rb', line 7 def state @state end |
#sub ⇒ Object (readonly)
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.
7 8 9 |
# File 'lib/fleet/unit.rb', line 7 def sub @sub end |
Instance Method Details
#==(other_unit) ⇒ Object Also known as: eql?
79 80 81 |
# File 'lib/fleet/unit.rb', line 79 def ==(other_unit) name == other_unit.name end |
#creating? ⇒ Boolean
31 32 33 |
# File 'lib/fleet/unit.rb', line 31 def creating? active == 'activating' && sub == 'start-pre' end |
#docker_inspect(container_name = name) ⇒ Object
returns a JSON object representing the container assumes that this unit corresponds to a docker container
74 75 76 77 |
# 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) ⇒ Object
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
53 54 55 56 57 58 59 60 61 |
# 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 |
#failed? ⇒ Boolean
35 36 37 |
# File 'lib/fleet/unit.rb', line 35 def failed? active == 'failed' && sub == 'failed' end |
#ip ⇒ Object
27 28 29 |
# File 'lib/fleet/unit.rb', line 27 def ip machine && machine.ip end |
#running? ⇒ Boolean
39 40 41 |
# File 'lib/fleet/unit.rb', line 39 def running? active == 'active' && sub == 'running' end |
#ssh(*command, port: 22) ⇒ Object
run the command on host (string, array of command + args, whatever) and return stdout
44 45 46 47 48 |
# 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 |