Module: ForemanFogProxmox::ProxmoxImages

Included in:
Proxmox
Defined in:
app/models/foreman_fog_proxmox/proxmox_images.rb

Instance Method Summary collapse

Instance Method Details

#available_imagesObject



31
32
33
# File 'app/models/foreman_fog_proxmox/proxmox_images.rb', line 31

def available_images
  templates.collect { |template| OpenStruct.new(id: template.vmid) }
end

#clone_from_image(image_id, args, vmid) ⇒ Object



45
46
47
48
49
50
51
# File 'app/models/foreman_fog_proxmox/proxmox_images.rb', line 45

def clone_from_image(image_id, args, vmid)
  logger.debug(format(_('create_vm(): clone %<image_id>s in %<vmid>s'), image_id: image_id, vmid: vmid))
  image = node.servers.get image_id
  image.clone(vmid)
  clone = node.servers.get vmid
  clone.update(name: args[:name])
end

#image_exists?(image) ⇒ Boolean

Returns:

  • (Boolean)


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

def image_exists?(image)
  !find_vm_by_uuid(image).nil?
end

#images_by_storage(storage_id, type = 'iso') ⇒ Object



26
27
28
29
# File 'app/models/foreman_fog_proxmox/proxmox_images.rb', line 26

def images_by_storage(storage_id, type = 'iso')
  storage = node.storages.get storage_id if storage_id
  storage.volumes.list_by_content_type(type).sort_by(&:volid) if storage
end

#template(vmid) ⇒ Object



41
42
43
# File 'app/models/foreman_fog_proxmox/proxmox_images.rb', line 41

def template(vmid)
  find_vm_by_uuid(vmid)
end

#templatesObject



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

def templates
  storage = storages.first
  images = storage.volumes.list_by_content_type('images')
  images.select(&:templated?)
end