Class: ConfCtl::Cli::Generation
Instance Attribute Summary
Attributes inherited from Command
#args, #gopts, #opts
Instance Method Summary
collapse
Methods inherited from Command
#ask_action, #ask_confirmation, #ask_confirmation!, #initialize, #require_args!, run, #run_method, #use_color?, #use_pager?
Instance Method Details
#collect_garbage ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/confctl/cli/generation.rb', line 84
def collect_garbage
machines = select_machines(args[0]).runnable
raise 'No machines to collect garbage on' if machines.empty?
ask_confirmation! do
puts 'Collect garbage on the following machines:'
list_machines(machines)
end
run_gc(machines)
end
|
#list ⇒ Object
5
6
7
8
9
|
# File 'lib/confctl/cli/generation.rb', line 5
def list
machines = select_machines(args[0])
gens = select_generations(machines, args[1])
list_generations(gens)
end
|
#remove ⇒ Object
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
|
# File 'lib/confctl/cli/generation.rb', line 11
def remove
machines = select_machines(args[0])
gens = select_generations(machines, args[1])
if gens.empty?
puts 'No generations found'
return
end
ask_confirmation! do
puts 'The following generations will be removed:'
list_generations(gens)
puts
puts "Garbage collection: #{opts[:remote] && opts[:gc] ? 'yes' : 'no'}"
end
gens.each do |gen|
puts "Removing #{gen.presence_str} generation #{gen.host}@#{gen.name}"
gen.destroy
end
return unless opts[:remote] && opts[:gc]
machines_gc = machines.runnable.select do |host, _machine|
gens.detect { |gen| gen.host == host }
end
run_gc(machines_gc)
end
|
#rotate ⇒ Object
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
76
77
78
79
80
81
82
|
# File 'lib/confctl/cli/generation.rb', line 41
def rotate
machines = select_machines(args[0])
to_delete = []
to_delete.concat(host_generations_rotate(machines)) if opts[:remote]
to_delete.concat(build_generations_rotate(machines)) if opts[:local] || (!opts[:local] && !opts[:remote])
if to_delete.empty?
puts 'No generations to delete'
return
end
ask_confirmation! do
puts 'The following generations will be removed:'
OutputFormatter.print(to_delete, %i[host name type id], layout: :columns)
puts
puts "Garbage collection: #{opts[:remote] ? 'when enabled in configuration' : 'no'}"
end
to_delete.each do |gen|
puts "Removing #{gen[:type]} generation #{gen[:host]}@#{gen[:name]}"
gen[:generation].destroy
end
return unless opts[:remote]
global = ConfCtl::Settings.instance.host_generations
machines_gc = machines.runnable.select do |_host, machine|
gc = machine['buildGenerations']['collectGarbage']
if gc.nil?
global['collectGarbage']
else
gc
end
end
run_gc(machines_gc) if machines_gc.any?
end
|