using Newtonsoft.Json;
using System;
namespace PSProxmox.Models
{
///
/// Represents a virtual machine template in Proxmox VE.
///
public class ProxmoxVMTemplate
{
///
/// Gets or sets the template ID.
///
[JsonProperty("vmid")]
public int VMID { get; set; }
///
/// Gets or sets the template name.
///
[JsonProperty("name")]
public string Name { get; set; }
///
/// Gets or sets the template node.
///
[JsonProperty("node")]
public string Node { get; set; }
///
/// Gets or sets the template CPU count.
///
[JsonProperty("cpus")]
public int CPUs { get; set; }
///
/// Gets or sets the template memory in bytes.
///
[JsonProperty("maxmem")]
public long MaxMemory { get; set; }
///
/// Gets or sets the template disk size in bytes.
///
[JsonProperty("maxdisk")]
public long MaxDisk { get; set; }
///
/// Gets or sets the template type (qemu, lxc, etc.).
///
[JsonProperty("type")]
public string Type { get; set; }
///
/// Gets or sets the template description.
///
[JsonProperty("description")]
public string Description { get; set; }
///
/// Gets or sets the template creation time.
///
[JsonProperty("ctime")]
public long CreationTime { get; set; }
///
/// Gets or sets the template tags.
///
[JsonProperty("tags")]
public string Tags { get; set; }
///
/// Gets the template memory in megabytes.
///
[JsonIgnore]
public int MemoryMB => (int)(MaxMemory / 1024 / 1024);
///
/// Gets the template disk size in gigabytes.
///
[JsonIgnore]
public int DiskGB => (int)(MaxDisk / 1024 / 1024 / 1024);
///
/// Gets the template creation date.
///
[JsonIgnore]
public DateTime CreationDate => DateTimeOffset.FromUnixTimeSeconds(CreationTime).DateTime;
///
/// Creates a new instance of the class from a object.
///
/// The VM object.
/// A new template object.
public static ProxmoxVMTemplate FromVM(ProxmoxVM vm)
{
return new ProxmoxVMTemplate
{
VMID = vm.VMID,
Name = vm.Name,
Node = vm.Node,
CPUs = vm.CPUs,
MaxMemory = vm.MaxMemory,
MaxDisk = vm.MaxDisk,
Type = vm.Type,
Tags = vm.Tags,
CreationTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
};
}
}
}