Revision 781a9928 src/tm_mad/vcenter/delete
src/tm_mad/vcenter/delete | ||
---|---|---|
22 | 22 |
# - vmid is the id of the VM |
23 | 23 |
# - dsid is the target datastore (0 is the system datastore) |
24 | 24 |
|
25 |
# Return if this has called for the whole directory, instead of for a specific |
|
26 |
# disk. |
|
27 |
|
|
28 |
if !ARGV[0].match(/disk\.\d+$/) |
|
29 |
exit(0) |
|
30 |
end |
|
31 |
|
|
32 |
# ---------------------------------------------------------------------------- # |
|
33 |
|
|
25 | 34 |
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION) |
26 | 35 |
|
27 | 36 |
if !ONE_LOCATION |
... | ... | |
34 | 43 |
$: << File.dirname(__FILE__) |
35 | 44 |
|
36 | 45 |
require 'vcenter_driver' |
46 |
require 'opennebula' |
|
37 | 47 |
|
38 | 48 |
hostname, img_path = ARGV[0].split(":") |
39 | 49 |
vmid = ARGV[1] |
40 | 50 |
dsid = ARGV[2] |
41 | 51 |
|
52 |
client = OpenNebula::Client.new |
|
53 |
vm = OpenNebula::VirtualMachine.new_with_id(vmid, client) |
|
54 |
vm.info |
|
55 |
|
|
56 |
disk_id = img_path.split(".")[-1] |
|
57 |
|
|
58 |
persistent = vm["TEMPLATE/DISK[DISK_ID=#{disk_id}]/PERSISTENT"] |
|
59 |
|
|
60 |
if persistent != "YES" |
|
61 |
img_path = "one_#{vmid}_#{disk_id}.vmdk" |
|
62 |
end |
|
63 |
|
|
42 | 64 |
begin |
43 | 65 |
host_id = VCenterDriver::VIClient.translate_hostname(hostname) |
44 | 66 |
vi_client = VCenterDriver::VIClient.new host_id |
... | ... | |
47 | 69 |
vi_client.delete_virtual_disk(img_path, ds_name) |
48 | 70 |
rescue Exception => e |
49 | 71 |
STDERR.puts "Error delete virtual disk #{img_path} in datastore #{dsid}."\ |
50 |
" Reason: #{e.message}" |
|
72 |
" Reason: #{e.message}\n#{e.backtrace}"
|
|
51 | 73 |
exit -1 |
52 | 74 |
end |
Also available in: Unified diff