Module: Fog::Proxmox::NicHelper

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

Overview

module NicHelper mixins

Class Method Summary collapse

Class Method Details

.collect_nics(attributes) ⇒ Object


73
74
75
# File 'lib/fog/proxmox/helpers/nic_helper.rb', line 73

def self.collect_nics(attributes)        
  attributes.select { |key| valid?(key.to_s) }
end

.container_flatten(nic) ⇒ Object


62
63
64
65
66
67
# File 'lib/fog/proxmox/helpers/nic_helper.rb', line 62

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) ⇒ Object


27
28
29
# File 'lib/fog/proxmox/helpers/nic_helper.rb', line 27

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) ⇒ Object


31
32
33
34
35
36
37
38
# File 'lib/fog/proxmox/helpers/nic_helper.rb', line 31

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) ⇒ Object


40
41
42
43
44
45
46
47
# File 'lib/fog/proxmox/helpers/nic_helper.rb', line 40

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) ⇒ Object


55
56
57
58
59
60
# File 'lib/fog/proxmox/helpers/nic_helper.rb', line 55

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) ⇒ Object


49
50
51
52
53
# File 'lib/fog/proxmox/helpers/nic_helper.rb', line 49

def self.to_mac_adresses_array(nics)
  addresses = []
  nics.each { |nic| addresses.push(nic.mac) }
  addresses
end

.valid?(key) ⇒ Boolean

Returns:

  • (Boolean)

69
70
71
# File 'lib/fog/proxmox/helpers/nic_helper.rb', line 69

def self.valid?(key)
  key.to_s.match(/^net(\d+)$/)
end