Module: ForemanFogProxmox::ProxmoxImages
- Included in:
- Proxmox
- Defined in:
- app/models/foreman_fog_proxmox/proxmox_images.rb
Instance Method Summary collapse
- #available_images ⇒ Object
- #clone_from_image(image_id, vmid) ⇒ Object
- #image_exists?(image) ⇒ Boolean
- #images_by_storage(node_id, storage_id, type = 'iso') ⇒ Object
- #template(uuid) ⇒ Object
- #template_name(template) ⇒ Object
- #template_uuid(template) ⇒ Object
- #templates ⇒ Object
Instance Method Details
#available_images ⇒ Object
43 44 45 |
# File 'app/models/foreman_fog_proxmox/proxmox_images.rb', line 43 def available_images templates.collect { |template| OpenStruct.new(id: template_uuid(template), name: template_name(template)) } end |
#clone_from_image(image_id, vmid) ⇒ Object
61 62 63 64 65 66 |
# File 'app/models/foreman_fog_proxmox/proxmox_images.rb', line 61 def clone_from_image(image_id, vmid) logger.debug("create_vm(): clone #{image_id} in #{vmid}") image = find_vm_by_uuid(image_id) image.clone(vmid) find_vm_by_uuid(id.to_s + '_' + vmid.to_s) end |
#image_exists?(image) ⇒ 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(node_id, storage_id, type = 'iso') ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/models/foreman_fog_proxmox/proxmox_images.rb', line 26 def images_by_storage(node_id, storage_id, type = 'iso') node = client.nodes.get node_id node ||= default_node storage = node.storages.get storage_id if storage_id logger.debug("images_by_storage(): node_id #{node_id} storage_id #{storage_id} type #{type}") storage.volumes.list_by_content_type(type).sort_by(&:volid) if storage end |
#template(uuid) ⇒ Object
57 58 59 |
# File 'app/models/foreman_fog_proxmox/proxmox_images.rb', line 57 def template(uuid) find_vm_by_uuid(uuid) end |
#template_name(template) ⇒ Object
34 35 36 37 |
# File 'app/models/foreman_fog_proxmox/proxmox_images.rb', line 34 def template_name(template) image = find_vm_by_uuid(template_uuid(template)) image&.name end |
#template_uuid(template) ⇒ Object
39 40 41 |
# File 'app/models/foreman_fog_proxmox/proxmox_images.rb', line 39 def template_uuid(template) id.to_s + '_' + template.vmid.to_s end |
#templates ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'app/models/foreman_fog_proxmox/proxmox_images.rb', line 47 def templates volumes = [] nodes.each do |node| storages(node.node).each do |storage| volumes += storage.volumes.list_by_content_type('images') end end volumes.select(&:template?) end |