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(" realpath \#{profile}\n\n for generation in `ls -d -1 \#{profile}-*-link` ; do\n echo -n \"$generation;\"\n echo -n \"$(readlink $generation);\"\n echo -n \"$(stat --format=%Y $generation);\"\n\n for kernel_file in kernel bzImage ; do\n [ -h \"$generation/$kernel_file\" ] && echo -n $(readlink \"$generation/$kernel_file\")\n done\n\n echo\n done\n END\n\n list = new(machine.name)\n lines = out.strip.split(\"\\n\")\n current_path = lines.shift\n id_rx = /^\#{Regexp.escape(profile)}-(\\d+)-link$/\n\n lines.each do |line|\n link, path, created_at, kernel = line.split(';')\n\n if id_rx =~ link\n id = ::Regexp.last_match(1).to_i\n else\n warn \"Invalid profile generation link '\#{link}'\"\n next\n end\n\n kernel_version =\n if kernel && %r{\\A/nix/store/[^-]+-linux-([^/]+)} =~ kernel\n ::Regexp.last_match(1)\n end\n\n list << Generation::Host.new(\n machine,\n profile,\n id,\n path,\n Time.at(created_at.to_i),\n kernel_version,\n current: path == current_path,\n mc:\n )\n end\n\n list.sort\n list\nend\n") |
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 |