class VirtualMachineDevice::Disk
Disk class
Attributes
size[R]
Public Class Methods
one_disk(id, one_res)
click to toggle source
Create the OpenNebula disk representation Allow us to create the class without vCenter representation example: attached disks not synced with vCenter
# File lib/vm_disk.rb, line 26 def self.one_disk(id, one_res) new(id, one_res, nil) end
vc_disk(vc_res)
click to toggle source
Create the vCenter disk representation Allow us to create the class without OpenNebula representation example: detached disks that not exists in OpenNebula
# File lib/vm_disk.rb, line 33 def self.vc_disk(vc_res) new(nil, nil, vc_res) end
Public Instance Methods
boot_dev()
click to toggle source
# File lib/vm_disk.rb, line 140 def boot_dev if cd? RbVmomi::VIM.VirtualMachineBootOptionsBootableCdromDevice() else RbVmomi::VIM.VirtualMachineBootOptionsBootableDiskDevice( :deviceKey => device.key ) end end
cd?()
click to toggle source
# File lib/vm_disk.rb, line 86 def cd? raise_if_no_exists_in_vcenter @vc_res[:type] == 'CDROM' end
change_size(size)
click to toggle source
# File lib/vm_disk.rb, line 150 def change_size(size) size = size.to_i if @one_res['ORIGINAL_SIZE'] && @one_res['ORIGINAL_SIZE'].to_i >= size raise "'disk-resize' cannot decrease the disk's size" end @size = size end
cloned?()
click to toggle source
# File lib/vm_disk.rb, line 130 def cloned? raise_if_no_exists_in_one @one_res['SOURCE'] != @vc_res[:path_wo_ds] end
config(action)
click to toggle source
# File lib/vm_disk.rb, line 91 def config(action) raise_if_no_exists_in_vcenter config = {} case action when :delete if managed? key = "opennebula.mdisk.#{@id}" else key = "opennebula.disk.#{@id}" end config[:key] = key config[:value] = '' when :resize if new_size d = device d.capacityInKB = new_size config[:device] = d config[:operation] = :edit end when :attach puts 'not supported' end config end
connected?()
click to toggle source
# File lib/vm_disk.rb, line 135 def connected? raise_if_no_exists_in_vcenter @vc_res[:device].connectable.connected end
destroy()
click to toggle source
# File lib/vm_disk.rb, line 172 def destroy return if cd? raise_if_no_exists_in_vcenter ds = VCenterDriver::Datastore.new(self.ds) img_path = path begin img_dir = File.dirname(img_path) search_params = ds.get_search_params( ds['name'], img_dir, File.basename(img_path) ) search_task = ds['browser'] .SearchDatastoreSubFolders_Task(search_params) search_task.wait_for_completion ds.delete_virtual_disk(img_path) ds.rm_directory(img_dir) if ds.dir_empty?(img_dir) rescue StandardError => e if !e.message.start_with?('FileNotFound') # Ignore FileNotFound raise e.message end end end
device()
click to toggle source
# File lib/vm_disk.rb, line 42 def device raise_if_no_exists_in_vcenter @vc_res[:device] end
ds()
click to toggle source
# File lib/vm_disk.rb, line 57 def ds raise_if_no_exists_in_vcenter @vc_res[:datastore] end
file()
click to toggle source
# File lib/vm_disk.rb, line 82 def file path.split('/').last end
image_ds_ref()
click to toggle source
# File lib/vm_disk.rb, line 62 def image_ds_ref raise_if_no_exists_in_one @one_res['VCENTER_DS_REF'] end
key()
click to toggle source
# File lib/vm_disk.rb, line 67 def key raise_if_no_exists_in_vcenter @vc_res[:key] end
new_size()
click to toggle source
Shrink not supported (nil). Size is in KB
# File lib/vm_disk.rb, line 162 def new_size return @size * 1024 if @size return unless @one_res['ORIGINAL_SIZE'] osize = @one_res['ORIGINAL_SIZE'].to_i nsize = @one_res['SIZE'].to_i nsize > osize ? nsize * 1024 : nil end
node()
click to toggle source
# File lib/vm_disk.rb, line 47 def node raise_if_no_exists_in_vcenter @vc_res[:tag] end
path()
click to toggle source
# File lib/vm_disk.rb, line 52 def path raise_if_no_exists_in_vcenter @vc_res[:path_wo_ds] end
persistent?()
click to toggle source
# File lib/vm_disk.rb, line 120 def persistent? raise_if_no_exists_in_one @one_res['PERSISTENT'] == 'YES' end
prefix()
click to toggle source
# File lib/vm_disk.rb, line 72 def prefix raise_if_no_exists_in_vcenter @vc_res[:prefix] end
storpod?()
click to toggle source
# File lib/vm_disk.rb, line 37 def storpod? raise_if_no_exists_in_one @one_res['VCENTER_DS_REF'].start_with?('group-') end
type()
click to toggle source
# File lib/vm_disk.rb, line 77 def type raise_if_no_exists_in_vcenter @vc_res[:type] end
volatile?()
click to toggle source
# File lib/vm_disk.rb, line 125 def volatile? raise_if_no_exists_in_one @one_res['TYPE'] && @one_res['TYPE'].downcase == 'fs' end