Module: ForemanBootdisk::ComputeResources::Proxmox

Defined in:
app/models/concerns/foreman_bootdisk/compute_resources/proxmox.rb

Constant Summary collapse

CDROM_VOLUME =
'ide2'

Instance Method Summary collapse

Instance Method Details

#capabilitiesObject



8
9
10
# File 'app/models/concerns/foreman_bootdisk/compute_resources/proxmox.rb', line 8

def capabilities
  super + [:bootdisk]
end

#iso_attach(iso, vm_uuid) ⇒ Object



32
33
34
35
36
37
38
39
# File 'app/models/concerns/foreman_bootdisk/compute_resources/proxmox.rb', line 32

def iso_attach(iso, vm_uuid)
  server = find_vm_by_uuid(vm_uuid)
  storage = storages(server.node_id, 'iso')[0]
  volume = storage.volumes.detect { |v| v.volid.include? File.basename(iso) }
  disks = server.disks.map { |disk| disk.split(":")[0] }.join(";")
  server.update({ ide2: "#{volume.volid},media=cdrom" })
  server.update({ boot: "order=ide2;#{disks}" })
end

#iso_delete(iso, vm_uuid) ⇒ Object



23
24
25
26
27
28
29
30
# File 'app/models/concerns/foreman_bootdisk/compute_resources/proxmox.rb', line 23

def iso_delete(iso, vm_uuid)
  server = find_vm_by_uuid(vm_uuid)

  # delete the iso file from proxmox server
  storage = storages(server.node_id, 'iso')[0]
  volume = storage.volumes.detect { |v| v.volid.include? File.basename(iso) }
  volume&.destroy
end

#iso_detach(vm_uuid) ⇒ Object



41
42
43
44
45
46
47
# File 'app/models/concerns/foreman_bootdisk/compute_resources/proxmox.rb', line 41

def iso_detach(vm_uuid)
  server = find_vm_by_uuid(vm_uuid)
  server.update({ ide2: "none,media=cdrom" })

  # cdrom will be ejected on next power off
  server.detach(CDROM_VOLUME)
end

#iso_upload(iso, vm_uuid) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'app/models/concerns/foreman_bootdisk/compute_resources/proxmox.rb', line 12

def iso_upload(iso, vm_uuid)
  server = find_vm_by_uuid(vm_uuid)
  server.ssh_options = { password: fog_credentials[:proxmox_password] }
  server.ssh_ip_address = proxmox_host
  server.username = client.credentials[:current_user].split('@').first
  server.scp_upload(iso, '/var/lib/vz/template/iso/')
  server.reload
  storage = storages(server.node_id, 'iso')[0]
  storage.volumes.any? { |v| v.volid.include? File.basename(iso) }
end