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



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

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].merge!(interface_attributes['compute_attributes'].reject { |k, _v| k == 'id' })
end

#add_interfaces_to_compute_attributes(attributes) ⇒ Object



31
32
33
34
35
36
# File 'app/models/concerns/host_ext/proxmox/interfaces.rb', line 31

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



38
39
40
# File 'app/models/concerns/host_ext/proxmox/interfaces.rb', line 38

def cidr_ip(interface_attributes)
  Fog::Proxmox::IpHelper.to_cidr(interface_attributes['ip'], interface_attributes['compute_attributes']['cidr_suffix'])
end

#update(attributes = {}) ⇒ Object



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

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