Class: ConfCtl::Generation::Build
- Inherits:
-
Object
- Object
- ConfCtl::Generation::Build
- Defined in:
- lib/confctl/generation/build.rb
Instance Attribute Summary collapse
- #auto_rollback ⇒ String readonly
- #current ⇒ Boolean
- #date ⇒ Time readonly
- #host ⇒ String readonly
- #kernel_version ⇒ String? readonly
- #name ⇒ String readonly
- #swpin_names ⇒ Array<String> readonly
- #swpin_paths ⇒ Hash readonly
- #swpin_specs ⇒ Hash readonly
- #toplevel ⇒ String readonly
Instance Method Summary collapse
- #add_gcroot ⇒ Object
- #create(toplevel, auto_rollback, swpin_paths, swpin_specs, date: nil) ⇒ Object
- #destroy ⇒ Object
- #dir ⇒ Object
-
#initialize(host) ⇒ Build
constructor
A new instance of Build.
- #load(name) ⇒ Object
- #remove_gcroot ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(host) ⇒ Build
Returns a new instance of Build.
39 40 41 |
# File 'lib/confctl/generation/build.rb', line 39 def initialize(host) @host = host end |
Instance Attribute Details
#auto_rollback ⇒ String (readonly)
20 21 22 |
# File 'lib/confctl/generation/build.rb', line 20 def auto_rollback @auto_rollback end |
#current ⇒ Boolean
33 34 35 |
# File 'lib/confctl/generation/build.rb', line 33 def current @current end |
#date ⇒ Time (readonly)
14 15 16 |
# File 'lib/confctl/generation/build.rb', line 14 def date @date end |
#host ⇒ String (readonly)
8 9 10 |
# File 'lib/confctl/generation/build.rb', line 8 def host @host end |
#kernel_version ⇒ String? (readonly)
36 37 38 |
# File 'lib/confctl/generation/build.rb', line 36 def kernel_version @kernel_version end |
#name ⇒ String (readonly)
11 12 13 |
# File 'lib/confctl/generation/build.rb', line 11 def name @name end |
#swpin_names ⇒ Array<String> (readonly)
23 24 25 |
# File 'lib/confctl/generation/build.rb', line 23 def swpin_names @swpin_names end |
#swpin_paths ⇒ Hash (readonly)
26 27 28 |
# File 'lib/confctl/generation/build.rb', line 26 def swpin_paths @swpin_paths end |
#swpin_specs ⇒ Hash (readonly)
29 30 31 |
# File 'lib/confctl/generation/build.rb', line 29 def swpin_specs @swpin_specs end |
#toplevel ⇒ String (readonly)
17 18 19 |
# File 'lib/confctl/generation/build.rb', line 17 def toplevel @toplevel end |
Instance Method Details
#add_gcroot ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/confctl/generation/build.rb', line 125 def add_gcroot GCRoot.add(gcroot_name('toplevel'), toplevel_path) GCRoot.add(gcroot_name('auto_rollback'), auto_rollback_path) swpin_paths.each_key do |name| GCRoot.add(gcroot_name("swpin.#{name}"), toplevel_path) end end |
#create(toplevel, auto_rollback, swpin_paths, swpin_specs, date: nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/confctl/generation/build.rb', line 48 def create(toplevel, auto_rollback, swpin_paths, swpin_specs, date: nil) @toplevel = toplevel @auto_rollback = auto_rollback @swpin_names = swpin_paths.keys @swpin_paths = swpin_paths @swpin_specs = swpin_specs @date = date || Time.now @name = date.strftime('%Y-%m-%d--%H-%M-%S') @kernel_version = extract_kernel_version end |
#destroy ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/confctl/generation/build.rb', line 110 def destroy remove_gcroot File.unlink(toplevel_path) begin File.unlink(auto_rollback_path) rescue Errno::ENOENT # Older generations might not have auto_rollback end swpin_paths.each_key { |name| File.unlink(swpin_path(name)) } File.unlink(config_path) Dir.rmdir(dir) end |
#dir ⇒ Object
141 142 143 |
# File 'lib/confctl/generation/build.rb', line 141 def dir @dir ||= File.join(ConfDir.generation_dir, escaped_host, name) end |
#load(name) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/confctl/generation/build.rb', line 60 def load(name) @name = name cfg = JSON.parse(File.read(config_path)) @toplevel = cfg['toplevel'] @auto_rollback = cfg['auto_rollback'] @swpin_names = [] @swpin_paths = {} @swpin_specs = {} cfg['swpins'].each do |swpin_name, swpin| @swpin_names << swpin_name @swpin_paths[swpin_name] = swpin['path'] @swpin_specs[swpin_name] = Swpins::Spec.for(swpin['spec']['type'].to_sym).new( swpin_name, swpin['spec']['nix_options'], swpin['spec'] ) end @date = Time.iso8601(cfg['date']) @kernel_version = extract_kernel_version rescue StandardError => e raise Error, "invalid generation '#{name}': #{e.}" end |
#remove_gcroot ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/confctl/generation/build.rb', line 133 def remove_gcroot GCRoot.remove(gcroot_name('toplevel')) GCRoot.remove(gcroot_name('auto_rollback')) swpin_paths.each_key do |name| GCRoot.remove(gcroot_name("swpin.#{name}")) end end |
#save ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/confctl/generation/build.rb', line 87 def save FileUtils.mkdir_p(dir) File.symlink(toplevel, toplevel_path) File.symlink(auto_rollback, auto_rollback_path) swpin_paths.each do |name, path| File.symlink(path, swpin_path(name)) end File.open(config_path, 'w') do |f| f.puts(JSON.pretty_generate({ date: date.iso8601, toplevel:, auto_rollback:, swpins: swpin_paths.to_h do |name, path| [name, { path:, spec: swpin_specs[name].as_json }] end })) end add_gcroot end |