Sha256: 1e31277bcf703eaeffb4fda93e95116062c9723685735e32c7c12a7adbc3c342

Contents?: true

Size: 1.8 KB

Versions: 5

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

# Copyright 2019 Tristan Robert

# This file is part of ForemanFogProxmox.

# ForemanFogProxmox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# ForemanFogProxmox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.

module ForemanFogProxmox
  module ProxmoxImages
    def image_exists?(image)
      !find_vm_by_uuid(image).nil?
    end

    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

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

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

    def template(vmid)
      find_vm_by_uuid(vmid)
    end

    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)
      options = {}
      options.store(:name, args[:name]) unless clone.container?
      options.store(:hostname, args[:name]) if clone.container?
      clone.update(options)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_fog_proxmox-0.9.4 app/models/foreman_fog_proxmox/proxmox_images.rb
foreman_fog_proxmox-0.9.3 app/models/foreman_fog_proxmox/proxmox_images.rb
foreman_fog_proxmox-0.9.2 app/models/foreman_fog_proxmox/proxmox_images.rb
foreman_fog_proxmox-0.9.1 app/models/foreman_fog_proxmox/proxmox_images.rb
foreman_fog_proxmox-0.9.0 app/models/foreman_fog_proxmox/proxmox_images.rb