Module: Fog::Proxmox::ControllerHelper

Defined in:
lib/fog/proxmox/helpers/controller_helper.rb

Overview

module ControllerHelper mixins

Constant Summary collapse

CONTROLLERS =
%w[ide sata scsi virtio mp rootfs].freeze

Class Method Summary collapse

Class Method Details

.collect_controllers(attributes) ⇒ Object


57
58
59
60
61
# File 'lib/fog/proxmox/helpers/controller_helper.rb', line 57

def self.collect_controllers(attributes)
  controllers = {}
  CONTROLLERS.each { |controller| controllers.merge!(select(attributes, controller)) }
  controllers
end

.extract(name, controller_value) ⇒ Object


27
28
29
30
31
# File 'lib/fog/proxmox/helpers/controller_helper.rb', line 27

def self.extract(name, controller_value)
  values = controller_value.scan(/#{name}=(\w+)/)
  name_value = values.first if values
  name_value&.first
end

.extract_index(name, key) ⇒ Object


33
34
35
36
# File 'lib/fog/proxmox/helpers/controller_helper.rb', line 33

def self.extract_index(name, key)
  idx_a = key.to_s.scan(/#{name}(\d+)/).first
  idx_a.first.to_i if idx_a
end

.last_index(name, values) ⇒ Object


42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/proxmox/helpers/controller_helper.rb', line 42

def self.last_index(name, values)
  return -1 if values.empty?
  indexes = []
  values.each do |value|
    index = extract_index(name, value)
    indexes.push(index) if index
  end
  indexes.sort
  indexes.empty? ? -1 : indexes.last
end

.select(hash, name) ⇒ Object


53
54
55
# File 'lib/fog/proxmox/helpers/controller_helper.rb', line 53

def self.select(hash,name)
  hash.select { |key| valid?(name, key.to_s) }
end

.valid?(name, key) ⇒ Boolean

Returns:

  • (Boolean)

38
39
40
# File 'lib/fog/proxmox/helpers/controller_helper.rb', line 38

def self.valid?(name, key)
  key.to_s.match(/^#{name}(\d*)$/)
end