Skip to content

Commit b0e3699

Browse files
committed
Fixes #38267 - rake ovirt:drop
Rake task for removal of Ovirt compute resources and its data - Disassociate all hosts from the CR - Update host groups - Remove Compute resource & its profiles
1 parent b42ca08 commit b0e3699

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

lib/tasks/ovirt.rake

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
namespace :ovirt do
2+
desc <<~END_DESC
3+
Remove all oVirt / RHEV compute resources & profiles from Foreman.
4+
All hosts associated with these compute resources will be disassociated and kept.
5+
All host groups with oVirt compute resources & profiles will have their compute resource and compute profile removed.
6+
7+
Examples:
8+
# foreman-rake ovirt:drop
9+
END_DESC
10+
11+
task :drop => :environment do
12+
compute_resources = ComputeResource.unscoped.where(type: 'Foreman::Model::Ovirt')
13+
14+
nothing_to_do if compute_resources.empty?
15+
16+
ask_user
17+
18+
puts 'Starting Ovirt integration drop ...'
19+
compute_resources.each do |cr|
20+
puts "Processing data for '#{cr.name}' compute resource."
21+
22+
cr.hosts.unscoped.each do |host|
23+
puts "Disassociating host '#{host.name}' from the compute resource."
24+
host.disassociate!
25+
end
26+
27+
puts "Removing compute resources and compute profiles from host groups."
28+
cr.hostgroups.unscoped.update_all(compute_resource_id: nil, compute_profile_id: nil)
29+
30+
puts "Removing '#{cr.name}' compute resource."
31+
cr.destroy
32+
end
33+
34+
the_end
35+
end
36+
37+
def ask_user
38+
puts "!!! WARNING !!! This operation is irreversible."
39+
puts " - This task will remove all oVirt / RHEV compute resources from Foreman."
40+
puts " - All hosts associated with these compute resources will be disassociated and kept."
41+
puts " - All host groups with compute resources will have their compute resource and compute profile removed."
42+
puts " - Compute profiles associated with the compute resources will be removed."
43+
puts ""
44+
puts "Are you sure you want to continue? (yes/no)"
45+
46+
answer = $stdin.gets.chomp.downcase
47+
48+
unless answer == "yes"
49+
puts "Aborting task."
50+
exit 1
51+
end
52+
end
53+
54+
def nothing_to_do
55+
puts "No 'Foreman::Model::Ovirt' compute resources found."
56+
puts "Nothing to do, exiting."
57+
exit 0
58+
end
59+
60+
def the_end
61+
puts 'oVirt cleanup was successfully completed.'
62+
puts 'Exiting.'
63+
exit 0
64+
end
65+
end

0 commit comments

Comments
 (0)