Class: ConfCtl::Generation::HostList
- Inherits:
-
Object
- Object
- ConfCtl::Generation::HostList
- Defined in:
- lib/confctl/generation/host_list.rb
Instance Attribute Summary collapse
- #host ⇒ String readonly
Class Method Summary collapse
Instance Method Summary collapse
- #<<(generation) ⇒ Object
- #count ⇒ Integer
- #current ⇒ Generation::Host
- #each ⇒ Object
-
#initialize(host) ⇒ HostList
constructor
A new instance of HostList.
- #sort ⇒ Object
Constructor Details
#initialize(host) ⇒ HostList
Returns a new instance of HostList.
64 65 66 67 |
# File 'lib/confctl/generation/host_list.rb', line 64 def initialize(host) @host = host @generations = [] end |
Instance Attribute Details
#host ⇒ String (readonly)
61 62 63 |
# File 'lib/confctl/generation/host_list.rb', line 61 def host @host end |
Class Method Details
.fetch(machine, mc, profile:) ⇒ Generation::HostList
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 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 |
# File 'lib/confctl/generation/host_list.rb', line 7 def self.fetch(machine, mc, profile:) out, = mc.bash_script(<<~END) realpath #{profile} for generation in `ls -d -1 #{profile}-*-link` ; do echo -n "$generation;" echo -n "$(readlink $generation);" echo -n "$(stat --format=%Y $generation);" for kernel_file in kernel bzImage ; do [ -h "$generation/$kernel_file" ] && echo -n $(readlink "$generation/$kernel_file") done echo done END list = new(machine.name) lines = out.strip.split("\n") current_path = lines.shift id_rx = /^#{Regexp.escape(profile)}-(\d+)-link$/ lines.each do |line| link, path, created_at, kernel = line.split(';') if id_rx =~ link id = ::Regexp.last_match(1).to_i else warn "Invalid profile generation link '#{link}'" next end kernel_version = if kernel && %r{\A/nix/store/[^-]+-linux-([^/]+)} =~ kernel ::Regexp.last_match(1) end list << Generation::Host.new( machine, profile, id, path, Time.at(created_at.to_i), kernel_version, current: path == current_path, mc: ) end list.sort list end |
Instance Method Details
#<<(generation) ⇒ Object
70 71 72 |
# File 'lib/confctl/generation/host_list.rb', line 70 def <<(generation) generations << generation end |
#count ⇒ Integer
83 84 85 |
# File 'lib/confctl/generation/host_list.rb', line 83 def count generations.length end |
#current ⇒ Generation::Host
88 89 90 |
# File 'lib/confctl/generation/host_list.rb', line 88 def current generations.detect(&:current) end |
#each ⇒ Object
78 79 80 |
# File 'lib/confctl/generation/host_list.rb', line 78 def each(&) generations.each(&) end |
#sort ⇒ Object
74 75 76 |
# File 'lib/confctl/generation/host_list.rb', line 74 def sort generations.sort! { |a, b| a.id <=> b.id } end |