module Fog::Proxmox::CpuHelper
module Cpu mixins
Constants
- CPU_REGEXP
- FLAGS
Public Class Methods
extract(cpu, name)
click to toggle source
# File lib/fog/proxmox/helpers/cpu_helper.rb, line 30 def self.extract(cpu, name) captures_h = cpu ? CPU_REGEXP.match(cpu.to_s) : { cputype: '', flags: '' } captures_h[name] end
extract_cputype(cpu)
click to toggle source
# File lib/fog/proxmox/helpers/cpu_helper.rb, line 35 def self.extract_cputype(cpu) extract(cpu, :cputype) end
extract_flags(cpu)
click to toggle source
# File lib/fog/proxmox/helpers/cpu_helper.rb, line 39 def self.extract_flags(cpu) extract(cpu, :flags) end
flag_value(cpu, flag_key)
click to toggle source
# File lib/fog/proxmox/helpers/cpu_helper.rb, line 43 def self.flag_value(cpu, flag_key) flag_value = '0' raw_values = extract_flags(cpu).split(';').select { |flag| ['+' + flag_key, '-' + flag_key].include?(flag) } unless raw_values.empty? flag_value = raw_values[0].start_with?('+') ? '+1' : raw_values[0].start_with?('-') ? '-1' : '0' end flag_value end
flags()
click to toggle source
# File lib/fog/proxmox/helpers/cpu_helper.rb, line 26 def self.flags FLAGS end
flatten(cpu_h)
click to toggle source
# File lib/fog/proxmox/helpers/cpu_helper.rb, line 65 def self.flatten(cpu_h) return '' unless cpu_h['cpu_type'] cpu_type = "cputype=#{cpu_h['cpu_type']}" num_flags = 0 FLAGS.each_key { |flag_key| num_flags += 1 if hash_has_no_default_flag?(cpu_h, flag_key.to_s) } cpu_type += ',flags=' if num_flags > 0 flags_with_no_default_value = FLAGS.select { |flag_key, _flag_value| hash_has_no_default_flag?(cpu_h, flag_key.to_s) } flags_with_no_default_value.each_with_index do |(flag_key, flag_value), index| cpu_type += hash_flag(cpu_h, flag_key.to_s) + flag_value if hash_has_no_default_flag?(cpu_h, flag_key.to_s) cpu_type += ';' if num_flags > index + 1 end cpu_type end
hash_flag(cpu_h, flag_name)
click to toggle source
# File lib/fog/proxmox/helpers/cpu_helper.rb, line 56 def self.hash_flag(cpu_h, flag_name) flag = '' if cpu_h.key?(flag_name) flag = '+' if cpu_h[flag_name] == '+1' flag = '-' if cpu_h[flag_name] == '-1' end flag end
hash_has_no_default_flag?(cpu_h, flag_name)
click to toggle source
# File lib/fog/proxmox/helpers/cpu_helper.rb, line 52 def self.hash_has_no_default_flag?(cpu_h, flag_name) cpu_h.key?(flag_name) && ['-1', '+1'].include?(cpu_h[flag_name]) end