module Fog::Proxmox::NicHelper
module NicHelper mixins
Constants
- NICS_REGEXP
Public Class Methods
collect_nics(attributes)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 91 def self.collect_nics(attributes) attributes.select { |key| nic?(key.to_s) } end
extract_mac_address(nic_value)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 28 def self.extract_mac_address(nic_value) nic_value[/([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})/] end
extract_nic_id(nic_value)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 52 def self.extract_nic_id(nic_value) if self.has_model?(nic_value) nic_value.scan(self.model_regexp).first.first elsif self.has_name?(nic_value) nic_value.scan(self.name_regexp).first.first else nic_value.scan(self.nic_update_regexp).first.first end end
flatten(nic_hash)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 78 def self.flatten(nic_hash) nic_id = nic_hash[self.nic_name(nic_hash).to_sym] if nic_hash.has_key?(:macaddr) nic_value = nic_id + "=" + nic_hash[:macaddr] else nic_value = self.nic_name(nic_hash) + "=" + nic_id end options = nic_hash.reject { |key, _value| [self.nic_name(nic_hash).to_sym,:id,:macaddr].include? key.to_sym } nic_value += ',' unless options.empty? nic_value += Fog::Proxmox::Hash.stringify(options) unless options.empty? { "#{nic_hash[:id]}": nic_value } end
has_model?(nic_value)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 44 def self.has_model?(nic_value) nic_value.match(self.model_regexp) end
has_name?(nic_value)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 48 def self.has_name?(nic_value) nic_value.match(self.name_regexp) end
model_regexp()
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 32 def self.model_regexp /^model=(\w+)[,].+/ end
name_regexp()
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 36 def self.name_regexp /^name=(\w+)[,].+/ end
nic?(id)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 95 def self.nic?(id) NICS_REGEXP.match?(id) end
nic_name(nic)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 68 def self.nic_name(nic) if nic.has_key?(:model) "model" elsif nic.has_key?(:name) "name" else "" end end
nic_update_regexp()
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 40 def self.nic_update_regexp /^(\w+)[=]{1}([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2}).+/ end
to_mac_adresses_array(nics)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 62 def self.to_mac_adresses_array(nics) addresses = [] nics.each { |nic| addresses.push(nic.macaddr) } addresses end