class Fog::Proxmox::Compute::ServerConfig

ServerConfig model: pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/{qemu|lxc}/{vmid}/config memory, balloon, shares and swap are in Mb

Public Class Methods

new(new_attributes = {}) click to toggle source
Calls superclass method
# File lib/fog/proxmox/compute/models/server_config.rb, line 82
def initialize(new_attributes = {})
  prepare_service_value(new_attributes)
  Fog::Proxmox::Attributes.set_attr_and_sym('vmid', attributes, new_attributes)
  requires :vmid
  initialize_interfaces(new_attributes)
  initialize_disks(new_attributes)
  super(new_attributes)
end

Public Instance Methods

flatten() click to toggle source
# File lib/fog/proxmox/compute/models/server_config.rb, line 102
def flatten
  flat_hash = attributes.reject { |attribute| %i[node_id type vmid disks interfaces].include? attribute }
  flat_hash.merge(interfaces_flatten)
  flat_hash.merge(disks_flatten)
  flat_hash
end
mac_addresses() click to toggle source
# File lib/fog/proxmox/compute/models/server_config.rb, line 91
def mac_addresses
  Fog::Proxmox::NicHelper.to_mac_adresses_array(interfaces)
end
type_console() click to toggle source
# File lib/fog/proxmox/compute/models/server_config.rb, line 95
def type_console
  console = 'vnc' if %w[std cirrus vmware].include?(vga)
  console = 'spice' if %w[qxl qxl2 qxl3 qxl4].include?(vga)
  console = 'term' if %w[serial0 serial1 serial2 serial3].include?(vga)
  console
end

Private Instance Methods

disks_flatten() click to toggle source
# File lib/fog/proxmox/compute/models/server_config.rb, line 117
def disks_flatten
  flat_hash = {}
  disks.each { |disk| flat_hash.merge(disk.flatten) }
  flat_hash
end
initialize_disks(new_attributes) click to toggle source
# File lib/fog/proxmox/compute/models/server_config.rb, line 140
def initialize_disks(new_attributes)
  controllers = Fog::Proxmox::ControllerHelper.collect_controllers(new_attributes)
  attributes[:disks] = Fog::Proxmox::Compute::Disks.new
  controllers.each do |key, value|
    storage, volid, size = Fog::Proxmox::DiskHelper.extract_storage_volid_size(value)
    disk_hash = {
      id: key.to_s,
      size: size,
      volid: volid,
      storage: storage
    }
    names = Fog::Proxmox::Compute::Disk.attributes.reject do |attribute|
      %i[id size storage volid].include? attribute
    end
    names.each { |name| disk_hash.store(name.to_sym, Fog::Proxmox::ControllerHelper.extract(name, value)) }
    attributes[:disks] << Fog::Proxmox::Compute::Disk.new(disk_hash)
  end
end
initialize_interfaces(new_attributes) click to toggle source
# File lib/fog/proxmox/compute/models/server_config.rb, line 123
def initialize_interfaces(new_attributes)
  nets = Fog::Proxmox::NicHelper.collect_nics(new_attributes)
  attributes[:interfaces] = Fog::Proxmox::Compute::Interfaces.new
  nets.each do |key, value|
    nic_hash = {
      id: key.to_s,
      model: Fog::Proxmox::NicHelper.extract_nic_id(value),
      macaddr: Fog::Proxmox::NicHelper.extract_mac_address(value)
    }
    names = Fog::Proxmox::Compute::Interface.attributes.reject do |attribute|
      %i[id macaddr model].include? attribute
    end
    names.each { |name| nic_hash.store(name.to_sym, Fog::Proxmox::ControllerHelper.extract(name, value)) }
    attributes[:interfaces] << Fog::Proxmox::Compute::Interface.new(nic_hash)
  end
end
interfaces_flatten() click to toggle source
# File lib/fog/proxmox/compute/models/server_config.rb, line 111
def interfaces_flatten
  flat_hash = {}
  interfaces.each { |interface| flat_hash.merge(interface.flatten) }
  flat_hash
end