forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rm_evm_snapshots.rb
executable file
·47 lines (40 loc) · 1.13 KB
/
rm_evm_snapshots.rb
1
2
3
4
5
6
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
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)
require 'rubygems'
require 'VMwareWebService/MiqVim'
if ARGV.length != 1
warn "Usage: #{$0} ems_name"
exit 1
end
ems_name = ARGV[0]
# server = ARGV[0]
# username = ARGV[1]
# password = ARGV[2]
begin
ems = ExtManagementSystem.find_by(:name => ems_name)
puts "Connecting to #{ems.hostname}..."
vim = ems.connect
puts "Done."
puts "vim.class: #{vim.class}"
puts "#{vim.server} is #{vim.isVirtualCenter? ? 'VC' : 'ESX'}"
puts "API version: #{vim.apiVersion}"
puts
vim.virtualMachinesByMor.each_value do |vm|
miqVm = vim.getVimVmByMor(vm['MOR'])
next unless miqVm.hasSnapshot?(MiqVimVm::EVM_SNAPSHOT_NAME)
sso = miqVm.searchSsTree(miqVm.snapshotInfo['rootSnapshotList'], 'name', MiqVimVm::EVM_SNAPSHOT_NAME)
unless sso
warn "#{miqVm.name}: could not determine the MOR of the EVM snapshot. Skipping."
next
end
puts "Deleting EVM snapshot for #{miqVm.name}..."
miqVm.removeSnapshot(sso['snapshot'])
puts "done."
puts
end
rescue => err
puts err
puts err.backtrace.join("\n")
ensure
vim.disconnect
end