Module: HostExt::Proxmox::Interfaces

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/host_ext/proxmox/interfaces.rb

Instance Method Summary collapse

Instance Method Details

#add_interface_to_compute_attributes(index, interface_attributes, compute_attributes) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'app/models/concerns/host_ext/proxmox/interfaces.rb', line 50

def add_interface_to_compute_attributes(index, interface_attributes, compute_attributes)
  compute_attributes[index] = {}
  compute_attributes[index].store('id', interface_attributes['identifier'])
  compute_attributes[index].store('_delete', interface_attributes['_destroy'])
  compute_attributes[index].store('macaddr', interface_attributes['mac'])
  compute_attributes[index].store('ip', cidr_ip(interface_attributes))
  compute_attributes[index].store('ip6', cidr_ip(interface_attributes, 6))
  compute_attributes[index].merge!(interface_attributes['compute_attributes'].reject { |k, _v| k == 'id' })
end

#add_interfaces_to_compute_attributes(attributes) ⇒ Object



33
34
35
36
37
38
39
# File 'app/models/concerns/host_ext/proxmox/interfaces.rb', line 33

def add_interfaces_to_compute_attributes(attributes)
  attributes['compute_attributes'].store('interfaces_attributes', {})
  attributes['interfaces_attributes'].each do |index, interface_attributes|
    add_interface_to_compute_attributes(index, interface_attributes,
      attributes['compute_attributes']['interfaces_attributes'])
  end
end

#cidr_ip(interface_attributes, v = 4) ⇒ Object



41
42
43
44
45
46
47
48
# File 'app/models/concerns/host_ext/proxmox/interfaces.rb', line 41

def cidr_ip(interface_attributes, v = 4)
  key_ip = 'ip'
  key_ip += '6' if v == 6
  key_cidr = 'cidr'
  key_cidr += '6' if v == 6
  Fog::Proxmox::IpHelper.to_cidr(interface_attributes[key_ip],
    interface_attributes['compute_attributes'][key_cidr])
end

#update(attributes = {}) ⇒ Object



26
27
28
29
30
31
# File 'app/models/concerns/host_ext/proxmox/interfaces.rb', line 26

def update(attributes = {})
  if provider == 'Proxmox' && !attributes.nil? && attributes.key?('compute_attributes')
    add_interfaces_to_compute_attributes(attributes)
  end
  super(attributes)
end