Sha256: d8a3ce1b4b0800993cd92f6997554ab7e11c1bd2aab7fac281218a43d22a4617

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 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 = node.servers.get image_id
      image.clone(vmid)
      clone = node.servers.get vmid
      clone.update(name: args[:name])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
foreman_fog_proxmox-0.8.2 app/models/foreman_fog_proxmox/proxmox_images.rb