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, args, vmid) ⇒ Object
- #image_exists?(image) ⇒ Boolean
- #images_by_storage(node_id, storage_id, type = 'iso') ⇒ Object
- #template(vmid) ⇒ Object
- #templates ⇒ Object
Instance Method Details
#available_images ⇒ Object
33 34 35 |
# File 'app/models/foreman_fog_proxmox/proxmox_images.rb', line 33 def available_images templates.collect { |template| OpenStruct.new(id: template.vmid.to_s) } end |
#clone_from_image(image_id, args, vmid) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/foreman_fog_proxmox/proxmox_images.rb', line 50 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 = find_vm_by_uuid(image_id) image.clone(vmid) clone = find_vm_by_uuid(vmid) = {} .store(:name, args[:name]) unless clone.container? .store(:hostname, args[:name]) if clone.container? clone.update() 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 |
# 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 storage.volumes.list_by_content_type(type).sort_by(&:volid) if storage end |
#template(vmid) ⇒ Object
46 47 48 |
# File 'app/models/foreman_fog_proxmox/proxmox_images.rb', line 46 def template(vmid) find_vm_by_uuid(vmid) end |
#templates ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'app/models/foreman_fog_proxmox/proxmox_images.rb', line 37 def templates volumes = [] nodes.each do |node| storage = storages(node.node).first volumes += storage.volumes.list_by_content_type('images') end volumes.select(&:templated?) end |