mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-23 13:15:14 +09:00
F #4913: Refactor TM mkimage
This commit is contained in:
1 parent
100e7e0a00
commit
bbe7844076
2 files changed
+36
-34
No files matched your search
+31
-33
@@ -35,16 +35,13 @@ end
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'opennebula'
|
||||
require 'vcenter_driver'
|
||||
|
||||
client = OpenNebula::Client.new
|
||||
require 'vcenter_driver2'
|
||||
|
||||
################################################################################
|
||||
|
||||
def check_valid(parameter, label)
|
||||
if parameter.nil? || parameter.empty?
|
||||
STDERR.puts "Not enough information to create the volatile disk. " +
|
||||
STDERR.puts "Not enough information to create the virtual disk. " +
|
||||
"Missing '#{label}'."
|
||||
exit -1
|
||||
end
|
||||
@@ -53,46 +50,47 @@ end
|
||||
################################################################################
|
||||
|
||||
size = ARGV[0]
|
||||
fstype = ARGV[1]
|
||||
hostname, img_name = ARGV[2].split(":")
|
||||
path = ARGV[2]
|
||||
vmid = ARGV[3]
|
||||
dsid = ARGV[4]
|
||||
|
||||
check_valid size, "size"
|
||||
check_valid path, "path"
|
||||
check_valid vmid, "vmid"
|
||||
check_valid dsid, "dsid"
|
||||
|
||||
hostname, img_name = path.split(":")
|
||||
disk_id = img_name.split(".")[-1]
|
||||
img_name = "one_#{vmid}_#{disk_id}"
|
||||
img_name = "one-#{vmid}-#{disk_id}"
|
||||
|
||||
################################################################################
|
||||
# Get host ID
|
||||
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, hostname)
|
||||
host_id = host['ID']
|
||||
|
||||
vm = OpenNebula::VirtualMachine.new_with_id(vmid, client)
|
||||
# Get datastore ref
|
||||
one_ds = VCenterDriver::VIHelper.one_item(OpenNebula::Datastore, dsid)
|
||||
ds_ref = one_ds['TEMPLATE/VCENTER_DS_REF']
|
||||
|
||||
rc = vm.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
puts rc.message
|
||||
exit -1
|
||||
end
|
||||
# Get adapter and disk type
|
||||
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vmid)
|
||||
adapter_type = one_vm["/VM/TEMPLATE/DISK[DISK_ID=#{disk_id}]/ADAPTER_TYPE"]
|
||||
|
||||
adapter_type = vm["/VM/TEMPLATE/DISK[DISK_ID=#{disk_id}]/ADAPTER_TYPE"]
|
||||
check_valid adapter_type, "adapter_type"
|
||||
|
||||
# TODO get the DISK_TYPE
|
||||
# disk_type = vm["/VM/TEMPLATE/DISK[DISK_ID=#{disk_id}]/DISK_TYPE"]
|
||||
# if disk_type.nil? || disk_type.empty?
|
||||
# disk_type = "thin"
|
||||
# end
|
||||
# TODO disk_type support, that info is not coming thin, thick...
|
||||
# disk_type = one_vm["/VM/TEMPLATE/DISK[DISK_ID=#{disk_id}]/DISK_TYPE"]
|
||||
# disk_type = "thin" if disk_type.nil? || disk_type.empty?
|
||||
disk_type = "thin"
|
||||
|
||||
check_valid adapter_type, "adapter_type"
|
||||
|
||||
begin
|
||||
host_id = VCenterDriver::VIClient.translate_hostname(hostname)
|
||||
vi_client = VCenterDriver::VIClient.new host_id
|
||||
ds_name = VCenterDriver::VIClient.find_ds_name(dsid)
|
||||
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
||||
|
||||
ds_vc = VCenterDriver::Datastore.new_from_ref(ds_ref, vi_client)
|
||||
|
||||
ds_vc.create_virtual_disk(img_name, size, adapter_type, disk_type)
|
||||
|
||||
puts vi_client.create_virtual_disk(img_name,
|
||||
ds_name,
|
||||
size,
|
||||
adapter_type,
|
||||
disk_type)
|
||||
rescue Exception => e
|
||||
STDERR.puts "Error creating virtual disk in #{ds_name}."\
|
||||
" Reason: #{e.message}"
|
||||
STDERR.puts "Error creating virtual disk in #{ds_vc['name']}."\
|
||||
" Reason: #{e.message}\n#{e.backtrace}"
|
||||
exit -1
|
||||
end
|
||||
@@ -9,7 +9,11 @@ class FileHelper
|
||||
if disk["PERSISTENT"] == "YES"
|
||||
return disk["SOURCE"]
|
||||
else
|
||||
image_name = disk["SOURCE"].split(".").first
|
||||
if disk["SOURCE"]
|
||||
image_name = disk["SOURCE"].split(".").first
|
||||
else
|
||||
image_name = "one" #For volatile disks
|
||||
end
|
||||
disk_id = disk["DISK_ID"]
|
||||
return "#{image_name}-#{vm_id}-#{disk_id}.vmdk"
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user