Class: ConfCtl::Machine
- Inherits:
-
Object
- Object
- ConfCtl::Machine
- Defined in:
- lib/confctl/machine.rb
Instance Attribute Summary collapse
-
#managed ⇒ Object
readonly
Returns the value of attribute managed.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#safe_name ⇒ Object
readonly
Returns the value of attribute safe_name.
-
#spin ⇒ Object
readonly
Returns the value of attribute spin.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #health_checks ⇒ Object
-
#initialize(opts) ⇒ Machine
constructor
A new instance of Machine.
- #localhost? ⇒ Boolean
- #nix_paths ⇒ Object
- #target_host ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(opts) ⇒ Machine
Returns a new instance of Machine.
6 7 8 9 10 11 12 |
# File 'lib/confctl/machine.rb', line 6 def initialize(opts) @opts = opts @name = opts['name'] @safe_name = opts['name'].gsub('/', ':') @managed = opts['managed'] @spin = opts['spin'] end |
Instance Attribute Details
#managed ⇒ Object (readonly)
Returns the value of attribute managed.
3 4 5 |
# File 'lib/confctl/machine.rb', line 3 def managed @managed end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/confctl/machine.rb', line 3 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
3 4 5 |
# File 'lib/confctl/machine.rb', line 3 def opts @opts end |
#safe_name ⇒ Object (readonly)
Returns the value of attribute safe_name.
3 4 5 |
# File 'lib/confctl/machine.rb', line 3 def safe_name @safe_name end |
#spin ⇒ Object (readonly)
Returns the value of attribute spin.
3 4 5 |
# File 'lib/confctl/machine.rb', line 3 def spin @spin end |
Instance Method Details
#[](key) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/confctl/machine.rb', line 77 def [](key) if key.index('.') get(opts, key.split('.')) elsif key == 'checks' health_checks.length else opts[key] end end |
#health_checks ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/confctl/machine.rb', line 31 def health_checks return @health_checks if @health_checks @health_checks = [] opts['healthChecks'].each do |type, checks| case type when 'systemd' next if !checks['enable'] || spin != 'nixos' if checks['systemProperties'].any? @health_checks << HealthChecks::Systemd::Properties.new( self, property_checks: checks['systemProperties'].map do |v| HealthChecks::Systemd::PropertyCheck.new(v) end ) end checks['unitProperties'].each do |unit_name, prop_checks| health_checks << HealthChecks::Systemd::Properties.new( self, pattern: unit_name, property_checks: prop_checks.map do |v| HealthChecks::Systemd::PropertyCheck.new(v) end ) end when 'builderCommands', 'machineCommands' checks.each do |cmd| health_checks << HealthChecks::RunCommand.new( self, HealthChecks::RunCommand::Command.new(self, cmd), remote: type == 'machineCommands' ) end else raise "Unsupported health-check type #{type.inspect}" end end @health_checks end |
#localhost? ⇒ Boolean
18 19 20 |
# File 'lib/confctl/machine.rb', line 18 def localhost? target_host == 'localhost' end |
#nix_paths ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/confctl/machine.rb', line 22 def nix_paths opts['nix']['nixPath'].to_h do |v| eq = v.index('=') raise "'#{v}' is not a valid nix path entry " if eq.nil? [v[0..eq - 1], v[eq + 1..]] end end |
#target_host ⇒ Object
14 15 16 |
# File 'lib/confctl/machine.rb', line 14 def target_host (opts['host'] && opts['host']['target']) || name end |
#to_s ⇒ Object
87 88 89 |
# File 'lib/confctl/machine.rb', line 87 def to_s name end |