# frozen_string_literal: true # Copyright 2018 Tristan Robert # This file is part of Fog::Proxmox. # Fog::Proxmox 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. # Fog::Proxmox 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 Fog::Proxmox. If not, see . require 'fog/compute/proxmox/models/server' require 'fog/compute/proxmox/models/container_config' module Fog module Compute class Proxmox # Container model class Container < Fog::Compute::Proxmox::Server identity :vmid attribute :lock attribute :maxswap attribute :swap attribute :config def initialize(attributes = {}) prepare_service_value(attributes) set_config(attributes) super end def type(attributes = {}) @type ||= 'lxc' unless attributes[:type] || attributes['type'] @type end def restore(backup, options = {}) requires :node, :vmid path_params = { node: node, type: type } body_params = options.merge(vmid: vmid, ostemplate: backup.volid, force: 1, restore: 1) task_upid = service.create_server(path_params, body_params) tasks.wait_for(task_upid) end def move(volume, storage, options = {}) requires :vmid, :node path_params = { node: node, vmid: vmid } body_params = options.merge(volume: volume, storage: storage) task_upid = service.move_volume(path_params, body_params) tasks.wait_for(task_upid) end def update(config = {}) requires :node, :vmid path_params = { node: node, type: type, vmid: vmid } body_params = config service.update_server(path_params, body_params) end def set_config(attributes = {}) @config = Fog::Compute::Proxmox::ContainerConfig.new({ service: service }.merge(attributes)) end def config path_params = { node: node, type: type, vmid: vmid } set_config(service.get_server_config(path_params)) if uptime @config end def detach(mpid) update(delete: mpid) end def extend(disk, size, options = {}) requires :vmid, :node path_params = { node: node, vmid: vmid } body_params = options.merge(disk: disk, size: size) task_upid = service.resize_container(path_params, body_params) tasks.wait_for(task_upid) end def action(action, options = {}) raise Fog::Errors::Error, "Action #{action} not implemented" unless %w[start stop shutdown].include? action super end end end end end