module Fog::Proxmox::NicHelper
module NicHelper mixins
Public Class Methods
collect_nics(attributes)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 87 def self.collect_nics(attributes) attributes.select { |key| valid?(key.to_s) } end
extract_mac_address(nic_value)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 26 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 50 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_creation_regexp).first.first end end
flatten(nic)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 76 def self.flatten(nic) nic_id = self.nic_name(nic) + "=" + nic[self.nic_name(nic).to_sym] options = nic.reject { |key, _value| [self.nic_name(nic).to_sym, :id].include? key } nic_id += ',' + Fog::Proxmox::Hash.stringify(options) unless options.empty? { "#{nic[:id]}": nic_id } end
has_model?(nic_value)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 42 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 46 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 30 def self.model_regexp /^model=(\w+)[,].+/ end
name_regexp()
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 34 def self.name_regexp /^name=(\w+)[,].+/ end
nic_creation_regexp()
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 38 def self.nic_creation_regexp /^(\w+)[=]{1}([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2}).+/ end
nic_name(nic)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 66 def self.nic_name(nic) if nic.has_key?(:model) "model" elsif nic.has_key?(:name) "name" else "" end end
to_mac_adresses_array(nics)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 60 def self.to_mac_adresses_array(nics) addresses = [] nics.each { |nic| addresses.push(nic.mac) } addresses end
valid?(key)
click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 83 def self.valid?(key) key.to_s.match(/^net(\d+)$/) end