Module: ForemanFogProxmox::ProxmoxPools

Included in:
ProxmoxVmCommands, ProxmoxVmQueries
Defined in:
app/models/foreman_fog_proxmox/proxmox_pools.rb

Instance Method Summary collapse

Instance Method Details

#add_vm_to_pool(poolid, vmid) ⇒ Object



35
36
37
38
39
# File 'app/models/foreman_fog_proxmox/proxmox_pools.rb', line 35

def add_vm_to_pool(poolid, vmid)
  logger.debug("add_vm_to_pool(#{poolid}, #{vmid})")
  pool = identity_client.pools.get poolid
  pool&.add_server vmid
end

#pool_owner(vm) ⇒ Object



27
28
29
30
31
32
33
# File 'app/models/foreman_fog_proxmox/proxmox_pools.rb', line 27

def pool_owner(vm)
  logger.debug("pool_owner(#{vm&.vmid})")
  pools_owners = pools.select { |pool| pool.has_server?(vm&.vmid) }
  pool = pools_owners.first
  logger.debug("found vm: #{vm&.vmid} member of pool: #{pool&.poolid}")
  vm&.config&.pool = pool&.poolid
end

#poolsObject



22
23
24
25
# File 'app/models/foreman_fog_proxmox/proxmox_pools.rb', line 22

def pools
  pools = identity_client.pools.all
  pools.sort_by(&:poolid)
end

#remove_vm_from_pool(poolid, vmid) ⇒ Object



41
42
43
44
45
# File 'app/models/foreman_fog_proxmox/proxmox_pools.rb', line 41

def remove_vm_from_pool(poolid, vmid)
  logger.debug("remove_vm_from_pool(#{poolid}, #{vmid})")
  pool = identity_client.pools.get poolid
  pool&.remove_server vmid
end

#update_pool(vm, poolid) ⇒ Object



47
48
49
50
51
52
53
54
# File 'app/models/foreman_fog_proxmox/proxmox_pools.rb', line 47

def update_pool(vm, poolid)
  pool_owner(vm)
  vm_pool = vm.config.pool || ''
  return if vm_pool.eql?(poolid)

  remove_vm_from_pool(vm_pool, vm.vmid)
  add_vm_to_pool(poolid, vm.vmid)
end