class Fog::Proxmox::Compute::ServerConfig

ServerConfig model

Public Class Methods

new(new_attributes = {}) click to toggle source
Calls superclass method
# File lib/fog/proxmox/compute/models/server_config.rb, line 81
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 101
def flatten
  flat_hash = attributes.reject { |attribute| [: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 90
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 94
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 116
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 137
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 { |attribute| [:id, :size, :storage, :volid].include? attribute }
    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 122
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 { |attribute| [:id, :macaddr, :model].include? attribute }
    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 110
def interfaces_flatten
  flat_hash = {}
  interfaces.each { |interface| flat_hash.merge(interface.flatten) }
  flat_hash
end