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 72
def self.collect_nics(attributes)        
  attributes.select { |key| valid?(key.to_s) }
end
container_flatten(nic) click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 61
def self.container_flatten(nic)
  name = "name=#{nic[:name]}"
  options = nic.reject { |key, _value| %i[name id].include? key }
  name += ',' + Fog::Proxmox::Hash.stringify(options) unless options.empty?
  { "#{nic[:id]}": name }
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_model(nic_value) click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 30
def self.extract_model(nic_value)
  creation = nic_value.match(/^model=(\w+)[,].+/)
  if creation
    nic_value.scan(/^model=(\w+)[,].+/).first.first
  else
    nic_value.scan(/^(\w+)[=]{1}([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2}).+/).first.first
  end
end
extract_name(nic_value) click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 39
def self.extract_name(nic_value)
  creation = nic_value.match(/^name=(\w+)[,].+/)
  if creation
    nic_value.scan(/^name=(\w+)[,].+/).first.first
  else
    nic_value.scan(/^(\w+)[=]{1}([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2}).+/).first.first
  end
end
flatten(nic) click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 54
def self.flatten(nic)
  model = "model=#{nic[:model]}"
  options = nic.reject { |key, _value| %i[model id].include? key }
  model += ',' + Fog::Proxmox::Hash.stringify(options) unless options.empty?
  { "#{nic[:id]}": model }
end
to_mac_adresses_array(nics) click to toggle source
# File lib/fog/proxmox/helpers/nic_helper.rb, line 48
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 68
def self.valid?(key)
  key.to_s.match(/^net(\d+)$/)
end