Revision 933f4a61 share/hooks/image.rb
share/hooks/image.rb | ||
---|---|---|
28 | 28 |
|
29 | 29 |
$: << RUBY_LIB_LOCATION |
30 | 30 |
|
31 |
require 'fileutils' |
|
32 |
|
|
33 | 31 |
require 'OpenNebula' |
34 | 32 |
include OpenNebula |
35 | 33 |
|
... | ... | |
44 | 42 |
client) |
45 | 43 |
vm.info |
46 | 44 |
|
47 |
if vm['TEMPLATE/DISK'] |
|
48 |
vm.each('TEMPLATE/DISK') do |disk| |
|
49 |
|
|
50 |
disk_id = disk["DISK_ID"] |
|
51 |
source_path = VMDIR+"/#{vm_id}/disk.#{disk_id}" |
|
52 |
|
|
53 |
image_id = nil |
|
54 |
if disk["SAVE_AS"] |
|
55 |
image_id = disk["SAVE_AS"] |
|
56 |
end |
|
57 |
|
|
58 |
if image_id and source_path |
|
59 |
image=Image.new( |
|
60 |
Image.build_xml(image_id), |
|
61 |
client) |
|
62 |
|
|
63 |
result = image.info |
|
64 |
exit -1 if !is_successful?(result) |
|
65 |
|
|
66 |
# Disable the Image for a safe overwriting |
|
67 |
image.disable |
|
68 |
|
|
69 |
# Save the image file |
|
70 |
result = image.move(source_path, image['SOURCE']) |
|
71 |
exit -1 if !is_successful?(result) |
|
45 |
vm.each('TEMPLATE/DISK') do |disk| |
|
46 |
disk_id = disk["DISK_ID"] |
|
47 |
source_path = VMDIR+"/#{vm_id}/disk.#{disk_id}" |
|
48 |
|
|
49 |
image_id = nil |
|
50 |
if disk["SAVE_AS"] |
|
51 |
image_id = disk["SAVE_AS"] |
|
52 |
end |
|
53 |
|
|
54 |
if image_id and source_path |
|
55 |
image=Image.new( |
|
56 |
Image.build_xml(image_id), |
|
57 |
client) |
|
58 |
|
|
59 |
result = image.info |
|
60 |
exit -1 if !is_successful?(result) |
|
72 | 61 |
|
73 |
image.enable |
|
74 |
end |
|
62 |
# Disable the Image for a safe overwriting |
|
63 |
image.disable |
|
64 |
|
|
65 |
# Save the image file |
|
66 |
result = image.move(source_path, image['SOURCE']) |
|
67 |
exit -1 if !is_successful?(result) |
|
68 |
|
|
69 |
image.enable |
|
75 | 70 |
end |
76 |
end |
|
71 |
end |
Also available in: Unified diff