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
- .collect_controllers(attributes) ⇒ Object
- .extract(name, controller_value) ⇒ Object
- .extract_index(name, key) ⇒ Object
- .last_index(name, values) ⇒ Object
- .select(hash, name) ⇒ Object
- .valid?(name, key) ⇒ Boolean
Class Method Details
.collect_controllers(attributes) ⇒ Object
56 57 58 59 60 |
# File 'lib/fog/proxmox/helpers/controller_helper.rb', line 56 def self.collect_controllers(attributes) controllers = {} CONTROLLERS.each { |controller| controllers.merge!(select(attributes, controller)) } controllers end |
.extract(name, controller_value) ⇒ Object
26 27 28 29 |
# File 'lib/fog/proxmox/helpers/controller_helper.rb', line 26 def self.extract(name, controller_value) matches = controller_value.match(/[,]{0,1}#{name}[=]{1}(?<name_value>[\w\/\.\:]+)/) matches ? matches[:name_value] : matches end |
.extract_index(name, key) ⇒ Object
31 32 33 34 35 |
# File 'lib/fog/proxmox/helpers/controller_helper.rb', line 31 def self.extract_index(name, key) matches = key.to_s.match(/#{name}(?<index>\d+)/) index = matches ? matches[:index] : matches index ? index.to_i : -1 end |
.last_index(name, values) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fog/proxmox/helpers/controller_helper.rb', line 41 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
52 53 54 |
# File 'lib/fog/proxmox/helpers/controller_helper.rb', line 52 def self.select(hash,name) hash.select { |key| valid?(name, key.to_s) } end |
.valid?(name, key) ⇒ Boolean
37 38 39 |
# File 'lib/fog/proxmox/helpers/controller_helper.rb', line 37 def self.valid?(name, key) key.to_s.match(/^#{name}(\d*)$/) end |