mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-28 14:50:08 +03:00
Added onevm saveas and save
This commit is contained in:
parent
10bd3b4e39
commit
c8d4f054da
@ -342,7 +342,15 @@ Commands:
|
||||
|
||||
* resume (Resumes the execution of a saved VM)
|
||||
onevm resume <vm_id>
|
||||
|
||||
|
||||
* saveas (Set the specified vm's disk to be saved in a new image (image_name)
|
||||
when the vm shutdowns)
|
||||
onevm saveas <vm_id> <disk_id> <image_name>
|
||||
|
||||
* save (Set the specified vm's disk to be saved, overwriting the original image
|
||||
when the vm shutdowns)
|
||||
onevm saveas <vm_id> <disk_id>
|
||||
|
||||
* delete (Deletes a VM from the pool and DB)
|
||||
onevm delete <vm_id>
|
||||
|
||||
@ -670,7 +678,81 @@ when "delete"
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
when "saveas"
|
||||
check_parameters("saveas", 3)
|
||||
vm_id = get_vm_id(ARGV[0])
|
||||
disk_id = ARGV[1]
|
||||
image_name = ARGV[2]
|
||||
|
||||
# Get the Image ID for this disk
|
||||
vm = OpenNebula::VirtualMachine.new(
|
||||
OpenNebula::VirtualMachine.build_xml(vm_id),
|
||||
get_one_client)
|
||||
|
||||
result = vm.info
|
||||
if !is_successful?(result)
|
||||
puts result.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
image_id = vm["TEMPLATE/DISK[DISK_ID=\"#{disk_id}\"]/IMAGE_ID"]
|
||||
|
||||
# Get the image type
|
||||
image = OpenNebula::Image.new(
|
||||
OpenNebula::Image.build_xml(image_id),
|
||||
get_one_client)
|
||||
|
||||
result = image.info
|
||||
if !is_successful?(result)
|
||||
puts result.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
if ops[:type]
|
||||
image_type = ops[:type]
|
||||
else
|
||||
image_type = image.type_str
|
||||
end
|
||||
|
||||
# Build the template and allocate the new Image
|
||||
template = "NAME=#{image_name}\n"
|
||||
template << "TYPE=#{image_type}\n" if type
|
||||
|
||||
|
||||
image = OpenNebula::Image.new(
|
||||
OpenNebula::Image.build_xml,
|
||||
get_one_client)
|
||||
|
||||
result = image.allocate(template)
|
||||
|
||||
if !is_successful?(result)
|
||||
puts result.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
result = vm.save_disk(disk_id.to_i, image.id)
|
||||
|
||||
when "save"
|
||||
check_parameters("save", 2)
|
||||
vm_id = get_vm_id(ARGV[0])
|
||||
disk_id = ARGV[1]
|
||||
|
||||
# Get the Image ID for this disk
|
||||
vm = OpenNebula::VirtualMachine.new(
|
||||
OpenNebula::VirtualMachine.build_xml(vm_id),
|
||||
get_one_client)
|
||||
|
||||
result = vm.info
|
||||
if !is_successful?(result)
|
||||
puts result.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
image_id = vm["TEMPLATE/DISK[DISK_ID=\"#{disk_id}\"]/IMAGE_ID"]
|
||||
|
||||
result = vm.save_disk(disk_id.to_i, image_id)
|
||||
|
||||
when "show"
|
||||
check_parameters("get_info", 1)
|
||||
args=expand_args(ARGV)
|
||||
|
@ -10,7 +10,8 @@ module OpenNebula
|
||||
:allocate => "vm.allocate",
|
||||
:action => "vm.action",
|
||||
:migrate => "vm.migrate",
|
||||
:deploy => "vm.deploy"
|
||||
:deploy => "vm.deploy",
|
||||
:savedisk => "vm.savedisk"
|
||||
}
|
||||
|
||||
VM_STATE=%w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED}
|
||||
@ -167,6 +168,15 @@ module OpenNebula
|
||||
|
||||
return rc
|
||||
end
|
||||
|
||||
def save_as(disk_id, image_id)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
||||
rc = @client.call(VM_METHODS[:savedisk], @pe_id, disk_id, image_id)
|
||||
rc = nil if !OpenNebula.is_error?(rc)
|
||||
|
||||
return rc
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Helpers to get VirtualMachine information
|
||||
|
Loading…
x
Reference in New Issue
Block a user