module Fog::Proxmox::DiskHelper
module Disk mixins
Public Class Methods
extract(id)
click to toggle source
# File lib/fog/proxmox/helpers/disk_helper.rb, line 48 def self.extract(id) id.scan(/(\w+)(\d+)/).first end
extract_controller(id)
click to toggle source
# File lib/fog/proxmox/helpers/disk_helper.rb, line 40 def self.extract_controller(id) extract(id)[0] end
extract_device(id)
click to toggle source
# File lib/fog/proxmox/helpers/disk_helper.rb, line 44 def self.extract_device(id) extract(id)[1].to_i end
extract_option(name, disk_value)
click to toggle source
# File lib/fog/proxmox/helpers/disk_helper.rb, line 52 def self.extract_option(name, disk_value) values = disk_value.scan(/#{name}=(\w+)/) name_value = values.first if values name_value&.first end
extract_size(disk_value)
click to toggle source
# File lib/fog/proxmox/helpers/disk_helper.rb, line 95 def self.extract_size(disk_value) size=extract_option('size', disk_value) self.to_bytes(size) end
extract_storage_volid_size(disk_value)
click to toggle source
# File lib/fog/proxmox/helpers/disk_helper.rb, line 58 def self.extract_storage_volid_size(disk_value) #volid definition: <VOULME_ID>:=<STORAGE_ID>:<storage type dependent volume name> values_a = disk_value.scan(/^(([\w-]+)[:]{0,1}([\w\/\.-]+))/) no_cdrom = !disk_value.match(/^(.+)[,]{1}(media=cdrom)$/) creation = disk_value.split(',')[0].match(/^(([\w-]+)[:]{1}([\d]+))$/) values = values_a.first if values_a if no_cdrom if creation storage = values[1] volid = nil size = values[2].to_i else storage = values[1] volid = values[0] size = extract_size(disk_value) end else volid = values[0] storage = values[1] unless %w[none cdrom].include? volid size = nil end [storage, volid, size] end
flatten(disk)
click to toggle source
# File lib/fog/proxmox/helpers/disk_helper.rb, line 25 def self.flatten(disk) volid = disk[:volid] value = if volid "#{disk[:volid]},size=#{disk[:size]}" else "#{disk[:storage]}:#{disk[:size]}" end opts = disk[:options] if disk.has_key? :options main_a = [:id,:volid,:storage,:size] opts = disk.reject { |key,_value| main_a.include? key } unless opts options = Fog::Proxmox::Hash.stringify(opts) if opts value += ",#{options}" if options { "#{disk[:id]}": value } end
to_bytes(size)
click to toggle source
# File lib/fog/proxmox/helpers/disk_helper.rb, line 82 def self.to_bytes(size) val=size.match(/\d+(\w?)/) m=0 case val[1] when "K" then m=1 when "M" then m=2 when "G" then m=3 when "T" then m=4 when "P" then m=5 end val[0].to_i*1024**m end