Class: ConfCtl::Machine
- Inherits:
-
Object
- Object
- ConfCtl::Machine
- Defined in:
- lib/confctl/machine.rb
Defined Under Namespace
Classes: CarriedMachine
Instance Attribute Summary collapse
-
#carried_alias ⇒ String
readonly
Alias for this machine on the carrier.
- #carrier_name ⇒ String readonly
- #cluster_name ⇒ String readonly
- #managed ⇒ Boolean readonly
-
#meta ⇒ Hash
readonly
Machine metadata.
- #name ⇒ String readonly
-
#safe_carried_alias ⇒ String
readonly
Alias for this machine on the carrier.
- #safe_cluster_name ⇒ String readonly
- #safe_name ⇒ String readonly
- #spin ⇒ String readonly
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#carried? ⇒ Boolean
True if this machine is on a carrier.
- #carried_machines ⇒ Array<CarriedMachine>
-
#carrier? ⇒ Boolean
True if this machine carries other machines.
-
#carrier_machine ⇒ Machine
Carrier.
- #health_checks ⇒ Object
-
#initialize(opts, machine_list:) ⇒ Machine
constructor
A new instance of Machine.
- #localhost? ⇒ Boolean
- #nix_paths ⇒ Object
-
#profile ⇒ String
Path to nix-env managed profile.
- #target_host ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(opts, machine_list:) ⇒ Machine
Returns a new instance of Machine.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/confctl/machine.rb', line 45 def initialize(opts, machine_list:) @meta = opts['metaConfig'] @name = opts['name'] @safe_name = name.gsub('/', ':') @managed = ['managed'] @spin = ['spin'] @is_carrier = .fetch('carrier', {}).fetch('enable', false) @carrier_name = opts['carrier'] @cluster_name = opts['clusterName'] @safe_cluster_name = cluster_name.gsub('/', ':') @carried_alias = opts['alias'] || @cluster_name @safe_carried_alias = @carried_alias.gsub('/', ':') @machine_list = machine_list end |
Instance Attribute Details
#carried_alias ⇒ String (readonly)
Alias for this machine on the carrier
34 35 36 |
# File 'lib/confctl/machine.rb', line 34 def carried_alias @carried_alias end |
#carrier_name ⇒ String (readonly)
24 25 26 |
# File 'lib/confctl/machine.rb', line 24 def carrier_name @carrier_name end |
#cluster_name ⇒ String (readonly)
27 28 29 |
# File 'lib/confctl/machine.rb', line 27 def cluster_name @cluster_name end |
#managed ⇒ Boolean (readonly)
18 19 20 |
# File 'lib/confctl/machine.rb', line 18 def managed @managed end |
#meta ⇒ Hash (readonly)
Returns machine metadata.
41 42 43 |
# File 'lib/confctl/machine.rb', line 41 def @meta end |
#name ⇒ String (readonly)
12 13 14 |
# File 'lib/confctl/machine.rb', line 12 def name @name end |
#safe_carried_alias ⇒ String (readonly)
Alias for this machine on the carrier
38 39 40 |
# File 'lib/confctl/machine.rb', line 38 def safe_carried_alias @safe_carried_alias end |
#safe_cluster_name ⇒ String (readonly)
30 31 32 |
# File 'lib/confctl/machine.rb', line 30 def safe_cluster_name @safe_cluster_name end |
#safe_name ⇒ String (readonly)
15 16 17 |
# File 'lib/confctl/machine.rb', line 15 def safe_name @safe_name end |
#spin ⇒ String (readonly)
21 22 23 |
# File 'lib/confctl/machine.rb', line 21 def spin @spin end |
Instance Method Details
#[](key) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/confctl/machine.rb', line 165 def [](key) if key.index('.') get(, key.split('.')) elsif key == 'name' name elsif key == 'checks' health_checks.length else [key] end end |
#carried? ⇒ Boolean
True if this machine is on a carrier
78 79 80 |
# File 'lib/confctl/machine.rb', line 78 def carried? !@carrier_name.nil? end |
#carried_machines ⇒ Array<CarriedMachine>
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/confctl/machine.rb', line 66 def carried_machines .fetch('carrier', {}).fetch('machines', []).map do |m| CarriedMachine.new( carrier: self, name: m['machine'], alias: m['alias'] || m['machine'], attribute: m['attribute'] ) end end |
#carrier? ⇒ Boolean
True if this machine carries other machines
61 62 63 |
# File 'lib/confctl/machine.rb', line 61 def carrier? @is_carrier end |
#carrier_machine ⇒ Machine
Returns carrier.
83 84 85 86 87 88 89 90 91 |
# File 'lib/confctl/machine.rb', line 83 def carrier_machine carrier = @machine_list[@carrier_name] if carrier.nil? raise "Carrier #{@carrier_name} not found in machine list" end carrier end |
#health_checks ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/confctl/machine.rb', line 119 def health_checks return @health_checks if @health_checks @health_checks = [] ['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
97 98 99 |
# File 'lib/confctl/machine.rb', line 97 def localhost? target_host == 'localhost' end |
#nix_paths ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/confctl/machine.rb', line 110 def nix_paths ['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 |
#profile ⇒ String
Returns path to nix-env managed profile.
102 103 104 105 106 107 108 |
# File 'lib/confctl/machine.rb', line 102 def profile if carried? "/nix/var/nix/profiles/confctl-#{safe_carried_alias}" else '/nix/var/nix/profiles/system' end end |
#target_host ⇒ Object
93 94 95 |
# File 'lib/confctl/machine.rb', line 93 def target_host .fetch('host', {}).fetch('target', name) end |
#to_s ⇒ Object
177 178 179 |
# File 'lib/confctl/machine.rb', line 177 def to_s name end |