mirror of
https://github.com/Grace-Solutions/PSProxmox.git
synced 2026-08-08 14:23:13 +00:00
Initial commit of PSProxmox module
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a cluster in Proxmox VE.
|
||||
/// </summary>
|
||||
public class ProxmoxCluster
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the cluster name.
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the cluster ID.
|
||||
/// </summary>
|
||||
[JsonProperty("id")]
|
||||
public string ID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the cluster nodes.
|
||||
/// </summary>
|
||||
[JsonProperty("nodes")]
|
||||
public List<ProxmoxClusterNode> Nodes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the cluster quorum.
|
||||
/// </summary>
|
||||
[JsonProperty("quorum")]
|
||||
public ProxmoxClusterQuorum Quorum { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the cluster version.
|
||||
/// </summary>
|
||||
[JsonProperty("version")]
|
||||
public string Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the cluster config version.
|
||||
/// </summary>
|
||||
[JsonProperty("config_version")]
|
||||
public int ConfigVersion { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a node in a Proxmox VE cluster.
|
||||
/// </summary>
|
||||
public class ProxmoxClusterNode
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the node name.
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node ID.
|
||||
/// </summary>
|
||||
[JsonProperty("id")]
|
||||
public string ID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node IP address.
|
||||
/// </summary>
|
||||
[JsonProperty("ip")]
|
||||
public string IP { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node online status.
|
||||
/// </summary>
|
||||
[JsonProperty("online")]
|
||||
public bool Online { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node type.
|
||||
/// </summary>
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the quorum information for a Proxmox VE cluster.
|
||||
/// </summary>
|
||||
public class ProxmoxClusterQuorum
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the quorum status.
|
||||
/// </summary>
|
||||
[JsonProperty("quorate")]
|
||||
public bool Quorate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of nodes.
|
||||
/// </summary>
|
||||
[JsonProperty("nodes")]
|
||||
public int Nodes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the expected votes.
|
||||
/// </summary>
|
||||
[JsonProperty("expected_votes")]
|
||||
public int ExpectedVotes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of votes needed for quorum.
|
||||
/// </summary>
|
||||
[JsonProperty("quorum")]
|
||||
public int Quorum { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a cluster backup in Proxmox VE.
|
||||
/// </summary>
|
||||
public class ProxmoxClusterBackup
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the backup ID.
|
||||
/// </summary>
|
||||
[JsonProperty("backup-id")]
|
||||
public string BackupID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the backup time.
|
||||
/// </summary>
|
||||
[JsonProperty("time")]
|
||||
public long Time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the backup type.
|
||||
/// </summary>
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the backup version.
|
||||
/// </summary>
|
||||
[JsonProperty("version")]
|
||||
public string Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the backup size.
|
||||
/// </summary>
|
||||
[JsonProperty("size")]
|
||||
public long Size { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the backup compression.
|
||||
/// </summary>
|
||||
[JsonProperty("compression")]
|
||||
public string Compression { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the backup node.
|
||||
/// </summary>
|
||||
[JsonProperty("node")]
|
||||
public string Node { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the backup file path.
|
||||
/// </summary>
|
||||
[JsonProperty("path")]
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the backup date.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public DateTime Date => DateTimeOffset.FromUnixTimeSeconds(Time).DateTime;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the backup size in megabytes.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public double SizeMB => Size / 1024.0 / 1024.0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the backup size in gigabytes.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public double SizeGB => Size / 1024.0 / 1024.0 / 1024.0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents connection information for a Proxmox VE server.
|
||||
/// </summary>
|
||||
public class ProxmoxConnectionInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the server hostname or IP address.
|
||||
/// </summary>
|
||||
public string Server { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the port number.
|
||||
/// </summary>
|
||||
public int Port { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the connection uses HTTPS.
|
||||
/// </summary>
|
||||
public bool UseSSL { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the username used for authentication.
|
||||
/// </summary>
|
||||
public string Username { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the realm used for authentication.
|
||||
/// </summary>
|
||||
public string Realm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the connection is authenticated.
|
||||
/// </summary>
|
||||
public bool IsAuthenticated { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="ProxmoxConnectionInfo"/> class from a <see cref="Session.ProxmoxConnection"/> object.
|
||||
/// </summary>
|
||||
/// <param name="connection">The connection object.</param>
|
||||
/// <returns>A new connection information object.</returns>
|
||||
public static ProxmoxConnectionInfo FromConnection(Session.ProxmoxConnection connection)
|
||||
{
|
||||
return new ProxmoxConnectionInfo
|
||||
{
|
||||
Server = connection.Server,
|
||||
Port = connection.Port,
|
||||
UseSSL = connection.UseSSL,
|
||||
Username = connection.Username,
|
||||
Realm = connection.Realm,
|
||||
IsAuthenticated = connection.IsAuthenticated
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an IP address pool for Proxmox VE.
|
||||
/// </summary>
|
||||
public class ProxmoxIPPool
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the pool.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the CIDR notation of the pool.
|
||||
/// </summary>
|
||||
public string CIDR { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the network address of the pool.
|
||||
/// </summary>
|
||||
public string NetworkAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the subnet mask of the pool.
|
||||
/// </summary>
|
||||
public string SubnetMask { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the prefix length of the pool.
|
||||
/// </summary>
|
||||
public int PrefixLength { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the total number of IPs in the pool.
|
||||
/// </summary>
|
||||
public int TotalIPs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of available IPs in the pool.
|
||||
/// </summary>
|
||||
public int AvailableIPs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of used IPs in the pool.
|
||||
/// </summary>
|
||||
public int UsedIPs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of excluded IPs in the pool.
|
||||
/// </summary>
|
||||
public int ExcludedIPs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of used IP addresses.
|
||||
/// </summary>
|
||||
public List<string> UsedIPAddresses { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of available IP addresses.
|
||||
/// </summary>
|
||||
public List<string> AvailableIPAddresses { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of excluded IP addresses.
|
||||
/// </summary>
|
||||
public List<string> ExcludedIPAddresses { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="ProxmoxIPPool"/> class from an <see cref="IPAM.IPPool"/> object.
|
||||
/// </summary>
|
||||
/// <param name="pool">The IP pool.</param>
|
||||
/// <returns>A new IP pool information object.</returns>
|
||||
public static ProxmoxIPPool FromIPPool(IPAM.IPPool pool)
|
||||
{
|
||||
return new ProxmoxIPPool
|
||||
{
|
||||
Name = pool.Name,
|
||||
CIDR = pool.CIDR,
|
||||
NetworkAddress = pool.NetworkAddress.ToString(),
|
||||
SubnetMask = pool.SubnetMask.ToString(),
|
||||
PrefixLength = pool.PrefixLength,
|
||||
TotalIPs = pool.TotalIPs,
|
||||
AvailableIPs = pool.AvailableIPs,
|
||||
UsedIPs = pool.UsedIPs,
|
||||
ExcludedIPs = pool.ExcludedIPs,
|
||||
UsedIPAddresses = pool.GetUsedIPs().Select(ip => ip.ToString()).ToList(),
|
||||
AvailableIPAddresses = pool.GetAvailableIPs().Select(ip => ip.ToString()).ToList(),
|
||||
ExcludedIPAddresses = pool.GetExcludedIPs().Select(ip => ip.ToString()).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a network interface in Proxmox VE.
|
||||
/// </summary>
|
||||
public class ProxmoxNetwork
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the interface name.
|
||||
/// </summary>
|
||||
[JsonProperty("iface")]
|
||||
public string Interface { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface type.
|
||||
/// </summary>
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface method.
|
||||
/// </summary>
|
||||
[JsonProperty("method")]
|
||||
public string Method { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface IP address.
|
||||
/// </summary>
|
||||
[JsonProperty("address")]
|
||||
public string Address { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface netmask.
|
||||
/// </summary>
|
||||
[JsonProperty("netmask")]
|
||||
public string Netmask { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface gateway.
|
||||
/// </summary>
|
||||
[JsonProperty("gateway")]
|
||||
public string Gateway { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface bridge ports.
|
||||
/// </summary>
|
||||
[JsonProperty("bridge_ports")]
|
||||
public string BridgePorts { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface bridge STP.
|
||||
/// </summary>
|
||||
[JsonProperty("bridge_stp")]
|
||||
public string BridgeSTP { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface bridge FD.
|
||||
/// </summary>
|
||||
[JsonProperty("bridge_fd")]
|
||||
public string BridgeFD { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface bond slaves.
|
||||
/// </summary>
|
||||
[JsonProperty("bond_slaves")]
|
||||
public string BondSlaves { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface bond mode.
|
||||
/// </summary>
|
||||
[JsonProperty("bond_mode")]
|
||||
public string BondMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface VLAN ID.
|
||||
/// </summary>
|
||||
[JsonProperty("vlan-id")]
|
||||
public string VlanID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface VLAN raw device.
|
||||
/// </summary>
|
||||
[JsonProperty("vlan-raw-device")]
|
||||
public string VlanRawDevice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface autostart flag.
|
||||
/// </summary>
|
||||
[JsonProperty("autostart")]
|
||||
public bool Autostart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface active flag.
|
||||
/// </summary>
|
||||
[JsonProperty("active")]
|
||||
public bool Active { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface comments.
|
||||
/// </summary>
|
||||
[JsonProperty("comments")]
|
||||
public string Comments { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interface node.
|
||||
/// </summary>
|
||||
[JsonProperty("node")]
|
||||
public string Node { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the interface is a bridge.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool IsBridge => Type == "bridge";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the interface is a bond.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool IsBond => Type == "bond";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the interface is a VLAN.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool IsVlan => Type == "vlan";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the interface is a physical interface.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool IsPhysical => Type == "eth";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the interface uses DHCP.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool IsDHCP => Method == "dhcp";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the interface uses a static IP.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool IsStatic => Method == "static";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a node in a Proxmox VE cluster.
|
||||
/// </summary>
|
||||
public class ProxmoxNode
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the node name.
|
||||
/// </summary>
|
||||
[JsonProperty("node")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node status.
|
||||
/// </summary>
|
||||
[JsonProperty("status")]
|
||||
public string Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node uptime in seconds.
|
||||
/// </summary>
|
||||
[JsonProperty("uptime")]
|
||||
public long Uptime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node CPU usage.
|
||||
/// </summary>
|
||||
[JsonProperty("cpu")]
|
||||
public double CPU { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node memory usage.
|
||||
/// </summary>
|
||||
[JsonProperty("mem")]
|
||||
public long Memory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node total memory.
|
||||
/// </summary>
|
||||
[JsonProperty("maxmem")]
|
||||
public long MaxMemory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node disk usage.
|
||||
/// </summary>
|
||||
[JsonProperty("disk")]
|
||||
public long Disk { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node total disk space.
|
||||
/// </summary>
|
||||
[JsonProperty("maxdisk")]
|
||||
public long MaxDisk { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node SSL fingerprint.
|
||||
/// </summary>
|
||||
[JsonProperty("ssl_fingerprint")]
|
||||
public string SSLFingerprint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node IP address.
|
||||
/// </summary>
|
||||
[JsonProperty("ip")]
|
||||
public string IP { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node level.
|
||||
/// </summary>
|
||||
[JsonProperty("level")]
|
||||
public string Level { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node ID.
|
||||
/// </summary>
|
||||
[JsonProperty("id")]
|
||||
public string ID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node type.
|
||||
/// </summary>
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the node is online.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool IsOnline => Status == "online";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the node uptime as a TimeSpan.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public TimeSpan UptimeSpan => TimeSpan.FromSeconds(Uptime);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the node memory usage percentage.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public double MemoryUsagePercent => MaxMemory > 0 ? (double)Memory / MaxMemory * 100 : 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the node disk usage percentage.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public double DiskUsagePercent => MaxDisk > 0 ? (double)Disk / MaxDisk * 100 : 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the node memory in gigabytes.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public double MemoryGB => MaxMemory / 1024.0 / 1024.0 / 1024.0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the node disk space in gigabytes.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public double DiskGB => MaxDisk / 1024.0 / 1024.0 / 1024.0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a response from the Proxmox VE API.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of data in the response.</typeparam>
|
||||
public class ProxmoxResponse<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the data in the response.
|
||||
/// </summary>
|
||||
[JsonProperty("data")]
|
||||
public T Data { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the request was successful.
|
||||
/// </summary>
|
||||
[JsonProperty("success")]
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a role in Proxmox VE.
|
||||
/// </summary>
|
||||
public class ProxmoxRole
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the role ID.
|
||||
/// </summary>
|
||||
[JsonProperty("roleid")]
|
||||
public string RoleID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the role's privileges.
|
||||
/// </summary>
|
||||
[JsonProperty("privs")]
|
||||
public string Privileges { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the role is a special role.
|
||||
/// </summary>
|
||||
[JsonProperty("special")]
|
||||
public bool Special { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the role's privileges as a list.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public List<string> PrivilegesList => Privileges?.Split(',') ?? new List<string>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an SDN VNet in Proxmox VE.
|
||||
/// </summary>
|
||||
public class ProxmoxSDNVnet
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet name.
|
||||
/// </summary>
|
||||
[JsonProperty("vnet")]
|
||||
public string VNet { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet zone.
|
||||
/// </summary>
|
||||
[JsonProperty("zone")]
|
||||
public string Zone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet type.
|
||||
/// </summary>
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet alias.
|
||||
/// </summary>
|
||||
[JsonProperty("alias")]
|
||||
public string Alias { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet VLAN ID.
|
||||
/// </summary>
|
||||
[JsonProperty("vlanid")]
|
||||
public int? VlanID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet tag.
|
||||
/// </summary>
|
||||
[JsonProperty("tag")]
|
||||
public int? Tag { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet IPv4 subnet.
|
||||
/// </summary>
|
||||
[JsonProperty("ipv4")]
|
||||
public string IPv4 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet IPv6 subnet.
|
||||
/// </summary>
|
||||
[JsonProperty("ipv6")]
|
||||
public string IPv6 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet MAC address.
|
||||
/// </summary>
|
||||
[JsonProperty("mac")]
|
||||
public string MAC { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet bridge.
|
||||
/// </summary>
|
||||
[JsonProperty("bridge")]
|
||||
public string Bridge { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet gateway.
|
||||
/// </summary>
|
||||
[JsonProperty("gateway")]
|
||||
public string Gateway { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet IPv6 gateway.
|
||||
/// </summary>
|
||||
[JsonProperty("gateway6")]
|
||||
public string Gateway6 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet MTU.
|
||||
/// </summary>
|
||||
[JsonProperty("mtu")]
|
||||
public int? MTU { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet DHCP.
|
||||
/// </summary>
|
||||
[JsonProperty("dhcp")]
|
||||
public bool DHCP { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet DNS.
|
||||
/// </summary>
|
||||
[JsonProperty("dns")]
|
||||
public string DNS { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet DNS search domain.
|
||||
/// </summary>
|
||||
[JsonProperty("dnssearchdomain")]
|
||||
public string DNSSearchDomain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VNet reverse DNS.
|
||||
/// </summary>
|
||||
[JsonProperty("reversedns")]
|
||||
public string ReverseDNS { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an SDN zone in Proxmox VE.
|
||||
/// </summary>
|
||||
public class ProxmoxSDNZone
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the zone name.
|
||||
/// </summary>
|
||||
[JsonProperty("zone")]
|
||||
public string Zone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the zone type.
|
||||
/// </summary>
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the zone DNS servers.
|
||||
/// </summary>
|
||||
[JsonProperty("dns")]
|
||||
public string DNS { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the zone DNS search domains.
|
||||
/// </summary>
|
||||
[JsonProperty("dnszone")]
|
||||
public string DNSZone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the zone DHCP server.
|
||||
/// </summary>
|
||||
[JsonProperty("dhcp")]
|
||||
public string DHCP { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the zone reverse DNS.
|
||||
/// </summary>
|
||||
[JsonProperty("reversedns")]
|
||||
public string ReverseDNS { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the zone IPv6.
|
||||
/// </summary>
|
||||
[JsonProperty("ipv6")]
|
||||
public string IPv6 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the zone MTU.
|
||||
/// </summary>
|
||||
[JsonProperty("mtu")]
|
||||
public int MTU { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the zone VLAN awareness.
|
||||
/// </summary>
|
||||
[JsonProperty("vlanaware")]
|
||||
public bool VLANAware { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the zone bridge.
|
||||
/// </summary>
|
||||
[JsonProperty("bridge")]
|
||||
public string Bridge { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the zone controller.
|
||||
/// </summary>
|
||||
[JsonProperty("controller")]
|
||||
public string Controller { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the zone gateway.
|
||||
/// </summary>
|
||||
[JsonProperty("gateway")]
|
||||
public string Gateway { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the zone MAC prefix.
|
||||
/// </summary>
|
||||
[JsonProperty("mac_prefix")]
|
||||
public string MACPrefix { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the zone VNET count.
|
||||
/// </summary>
|
||||
[JsonProperty("vnet_count")]
|
||||
public int VNetCount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a storage in Proxmox VE.
|
||||
/// </summary>
|
||||
public class ProxmoxStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the storage name.
|
||||
/// </summary>
|
||||
[JsonProperty("storage")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the storage type.
|
||||
/// </summary>
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the storage content types.
|
||||
/// </summary>
|
||||
[JsonProperty("content")]
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the storage path.
|
||||
/// </summary>
|
||||
[JsonProperty("path")]
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the storage node.
|
||||
/// </summary>
|
||||
[JsonProperty("node")]
|
||||
public string Node { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the storage used space in bytes.
|
||||
/// </summary>
|
||||
[JsonProperty("used")]
|
||||
public long Used { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the storage available space in bytes.
|
||||
/// </summary>
|
||||
[JsonProperty("avail")]
|
||||
public long Available { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the storage total space in bytes.
|
||||
/// </summary>
|
||||
[JsonProperty("total")]
|
||||
public long Total { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the storage is enabled.
|
||||
/// </summary>
|
||||
[JsonProperty("enabled")]
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the storage is shared.
|
||||
/// </summary>
|
||||
[JsonProperty("shared")]
|
||||
public bool Shared { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the storage is active.
|
||||
/// </summary>
|
||||
[JsonProperty("active")]
|
||||
public bool Active { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the storage used space in gigabytes.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public double UsedGB => Used / 1024.0 / 1024.0 / 1024.0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the storage available space in gigabytes.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public double AvailableGB => Available / 1024.0 / 1024.0 / 1024.0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the storage total space in gigabytes.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public double TotalGB => Total / 1024.0 / 1024.0 / 1024.0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the storage usage percentage.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public double UsagePercent => Total > 0 ? (double)Used / Total * 100 : 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an authentication ticket from the Proxmox VE API.
|
||||
/// </summary>
|
||||
public class ProxmoxTicket
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the authentication ticket.
|
||||
/// </summary>
|
||||
[JsonProperty("ticket")]
|
||||
public string Ticket { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the CSRF prevention token.
|
||||
/// </summary>
|
||||
[JsonProperty("CSRFPreventionToken")]
|
||||
public string CSRFPreventionToken { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the username.
|
||||
/// </summary>
|
||||
[JsonProperty("username")]
|
||||
public string Username { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a user in Proxmox VE.
|
||||
/// </summary>
|
||||
public class ProxmoxUser
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user ID.
|
||||
/// </summary>
|
||||
[JsonProperty("userid")]
|
||||
public string UserID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the user's first name.
|
||||
/// </summary>
|
||||
[JsonProperty("firstname")]
|
||||
public string FirstName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the user's last name.
|
||||
/// </summary>
|
||||
[JsonProperty("lastname")]
|
||||
public string LastName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the user's email address.
|
||||
/// </summary>
|
||||
[JsonProperty("email")]
|
||||
public string Email { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the user is enabled.
|
||||
/// </summary>
|
||||
[JsonProperty("enable")]
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the user is an administrator.
|
||||
/// </summary>
|
||||
[JsonProperty("isadmin")]
|
||||
public bool IsAdmin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the user's comment.
|
||||
/// </summary>
|
||||
[JsonProperty("comment")]
|
||||
public string Comment { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the user's expiration date.
|
||||
/// </summary>
|
||||
[JsonProperty("expire")]
|
||||
public long Expire { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the user's groups.
|
||||
/// </summary>
|
||||
[JsonProperty("groups")]
|
||||
public List<string> Groups { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the user's realm.
|
||||
/// </summary>
|
||||
[JsonProperty("realm")]
|
||||
public string Realm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user's full name.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string FullName => $"{FirstName} {LastName}".Trim();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user's username.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string Username => UserID?.Split('@')[0];
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the user has expired.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool HasExpired => Expire > 0 && Expire < System.DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a virtual machine in Proxmox VE.
|
||||
/// </summary>
|
||||
public class ProxmoxVM
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the VM ID.
|
||||
/// </summary>
|
||||
[JsonProperty("vmid")]
|
||||
public int VMID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VM name.
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VM status.
|
||||
/// </summary>
|
||||
[JsonProperty("status")]
|
||||
public string Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VM CPU count.
|
||||
/// </summary>
|
||||
[JsonProperty("cpus")]
|
||||
public int CPUs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VM memory in bytes.
|
||||
/// </summary>
|
||||
[JsonProperty("maxmem")]
|
||||
public long MaxMemory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VM disk size in bytes.
|
||||
/// </summary>
|
||||
[JsonProperty("maxdisk")]
|
||||
public long MaxDisk { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VM uptime in seconds.
|
||||
/// </summary>
|
||||
[JsonProperty("uptime")]
|
||||
public long Uptime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VM node.
|
||||
/// </summary>
|
||||
[JsonProperty("node")]
|
||||
public string Node { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VM type (qemu, lxc, etc.).
|
||||
/// </summary>
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VM template flag.
|
||||
/// </summary>
|
||||
[JsonProperty("template")]
|
||||
public int Template { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VM network interfaces.
|
||||
/// </summary>
|
||||
[JsonProperty("netif")]
|
||||
public string NetIf { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VM tags.
|
||||
/// </summary>
|
||||
[JsonProperty("tags")]
|
||||
public string Tags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the VM is a template.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool IsTemplate => Template == 1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the VM is running.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool IsRunning => Status == "running";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the VM memory in megabytes.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public int MemoryMB => (int)(MaxMemory / 1024 / 1024);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the VM disk size in gigabytes.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public int DiskGB => (int)(MaxDisk / 1024 / 1024 / 1024);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the VM uptime as a TimeSpan.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public TimeSpan UptimeSpan => TimeSpan.FromSeconds(Uptime);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Builder for creating virtual machine configurations in Proxmox VE.
|
||||
/// </summary>
|
||||
public class ProxmoxVMBuilder
|
||||
{
|
||||
private readonly Dictionary<string, string> _parameters = new Dictionary<string, string>();
|
||||
private readonly List<string> _networkInterfaces = new List<string>();
|
||||
private readonly List<string> _disks = new List<string>();
|
||||
private readonly List<string> _serialPorts = new List<string>();
|
||||
private readonly List<string> _usbDevices = new List<string>();
|
||||
private readonly List<string> _pciDevices = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the VM.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the VM ID.
|
||||
/// </summary>
|
||||
public int? VMID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the node where the VM will be created.
|
||||
/// </summary>
|
||||
public string Node { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the description of the VM.
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the tags for the VM.
|
||||
/// </summary>
|
||||
public string Tags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the memory in MB.
|
||||
/// </summary>
|
||||
public int Memory { get; set; } = 512;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of CPU cores.
|
||||
/// </summary>
|
||||
public int Cores { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the CPU type.
|
||||
/// </summary>
|
||||
public string CPUType { get; set; } = "host";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the operating system type.
|
||||
/// </summary>
|
||||
public string OSType { get; set; } = "l26"; // Linux 2.6+
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to start the VM after creation.
|
||||
/// </summary>
|
||||
public bool Start { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the IP pool to use for assigning an IP address.
|
||||
/// </summary>
|
||||
public string IPPool { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ProxmoxVMBuilder"/> class.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the VM.</param>
|
||||
public ProxmoxVMBuilder(string name)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the VM ID.
|
||||
/// </summary>
|
||||
/// <param name="vmid">The VM ID.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithVMID(int vmid)
|
||||
{
|
||||
VMID = vmid;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the node where the VM will be created.
|
||||
/// </summary>
|
||||
/// <param name="node">The node name.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithNode(string node)
|
||||
{
|
||||
Node = node ?? throw new ArgumentNullException(nameof(node));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the description of the VM.
|
||||
/// </summary>
|
||||
/// <param name="description">The description.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithDescription(string description)
|
||||
{
|
||||
Description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the tags for the VM.
|
||||
/// </summary>
|
||||
/// <param name="tags">The tags.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithTags(params string[] tags)
|
||||
{
|
||||
Tags = string.Join(",", tags);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the memory for the VM.
|
||||
/// </summary>
|
||||
/// <param name="memoryMB">The memory in MB.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithMemory(int memoryMB)
|
||||
{
|
||||
if (memoryMB <= 0)
|
||||
{
|
||||
throw new ArgumentException("Memory must be greater than 0", nameof(memoryMB));
|
||||
}
|
||||
|
||||
Memory = memoryMB;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the number of CPU cores for the VM.
|
||||
/// </summary>
|
||||
/// <param name="cores">The number of cores.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithCores(int cores)
|
||||
{
|
||||
if (cores <= 0)
|
||||
{
|
||||
throw new ArgumentException("Cores must be greater than 0", nameof(cores));
|
||||
}
|
||||
|
||||
Cores = cores;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the CPU type for the VM.
|
||||
/// </summary>
|
||||
/// <param name="cpuType">The CPU type.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithCPUType(string cpuType)
|
||||
{
|
||||
CPUType = cpuType ?? throw new ArgumentNullException(nameof(cpuType));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the operating system type for the VM.
|
||||
/// </summary>
|
||||
/// <param name="osType">The OS type.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithOSType(string osType)
|
||||
{
|
||||
OSType = osType ?? throw new ArgumentNullException(nameof(osType));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether to start the VM after creation.
|
||||
/// </summary>
|
||||
/// <param name="start">Whether to start the VM.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithStart(bool start)
|
||||
{
|
||||
Start = start;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the IP pool to use for assigning an IP address.
|
||||
/// </summary>
|
||||
/// <param name="ipPool">The IP pool name.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithIPPool(string ipPool)
|
||||
{
|
||||
IPPool = ipPool;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a disk to the VM.
|
||||
/// </summary>
|
||||
/// <param name="sizeGB">The disk size in GB.</param>
|
||||
/// <param name="storage">The storage location.</param>
|
||||
/// <param name="format">The disk format.</param>
|
||||
/// <param name="bus">The disk bus.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithDisk(int sizeGB, string storage, string format = "raw", string bus = "virtio")
|
||||
{
|
||||
if (sizeGB <= 0)
|
||||
{
|
||||
throw new ArgumentException("Size must be greater than 0", nameof(sizeGB));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(storage))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(storage));
|
||||
}
|
||||
|
||||
string diskId = $"scsi{_disks.Count}";
|
||||
_disks.Add($"{diskId}={storage}:{sizeGB},format={format}");
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a network interface to the VM.
|
||||
/// </summary>
|
||||
/// <param name="model">The network model.</param>
|
||||
/// <param name="bridge">The network bridge.</param>
|
||||
/// <param name="vlan">The VLAN ID.</param>
|
||||
/// <param name="macAddress">The MAC address.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithNetwork(string model = "virtio", string bridge = "vmbr0", int? vlan = null, string macAddress = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(bridge))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(bridge));
|
||||
}
|
||||
|
||||
string netId = $"net{_networkInterfaces.Count}";
|
||||
string netConfig = $"{model},bridge={bridge}";
|
||||
|
||||
if (vlan.HasValue)
|
||||
{
|
||||
netConfig += $",tag={vlan.Value}";
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(macAddress))
|
||||
{
|
||||
netConfig += $",macaddr={macAddress}";
|
||||
}
|
||||
|
||||
_networkInterfaces.Add($"{netId}={netConfig}");
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a static IP configuration to the VM.
|
||||
/// </summary>
|
||||
/// <param name="ipAddress">The IP address with CIDR notation.</param>
|
||||
/// <param name="gateway">The gateway address.</param>
|
||||
/// <param name="networkIndex">The network interface index.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithIPConfig(string ipAddress, string gateway, int networkIndex = 0)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ipAddress))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(ipAddress));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(gateway))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(gateway));
|
||||
}
|
||||
|
||||
if (networkIndex < 0 || networkIndex >= _networkInterfaces.Count)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(networkIndex));
|
||||
}
|
||||
|
||||
string netId = $"net{networkIndex}";
|
||||
string netConfig = _networkInterfaces[networkIndex].Split('=')[1];
|
||||
_networkInterfaces[networkIndex] = $"{netId}={netConfig},ip={ipAddress},gw={gateway}";
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the boot order for the VM.
|
||||
/// </summary>
|
||||
/// <param name="bootDevices">The boot devices in order.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithBootOrder(params string[] bootDevices)
|
||||
{
|
||||
if (bootDevices == null || bootDevices.Length == 0)
|
||||
{
|
||||
throw new ArgumentException("At least one boot device must be specified", nameof(bootDevices));
|
||||
}
|
||||
|
||||
_parameters["boot"] = string.Join(";", bootDevices);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the VGA type for the VM.
|
||||
/// </summary>
|
||||
/// <param name="vgaType">The VGA type.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithVGA(string vgaType)
|
||||
{
|
||||
if (string.IsNullOrEmpty(vgaType))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(vgaType));
|
||||
}
|
||||
|
||||
_parameters["vga"] = vgaType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a custom parameter for the VM.
|
||||
/// </summary>
|
||||
/// <param name="name">The parameter name.</param>
|
||||
/// <param name="value">The parameter value.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithParameter(string name, string value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
|
||||
_parameters[name] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the VM configuration parameters.
|
||||
/// </summary>
|
||||
/// <returns>The VM configuration parameters.</returns>
|
||||
public Dictionary<string, string> Build()
|
||||
{
|
||||
var parameters = new Dictionary<string, string>(_parameters);
|
||||
|
||||
// Add basic parameters
|
||||
parameters["name"] = Name;
|
||||
parameters["memory"] = Memory.ToString();
|
||||
parameters["cores"] = Cores.ToString();
|
||||
parameters["cpu"] = CPUType;
|
||||
parameters["ostype"] = OSType;
|
||||
|
||||
if (!string.IsNullOrEmpty(Description))
|
||||
{
|
||||
parameters["description"] = Description;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Tags))
|
||||
{
|
||||
parameters["tags"] = Tags;
|
||||
}
|
||||
|
||||
// Add network interfaces
|
||||
for (int i = 0; i < _networkInterfaces.Count; i++)
|
||||
{
|
||||
string[] parts = _networkInterfaces[i].Split('=');
|
||||
parameters[parts[0]] = parts[1];
|
||||
}
|
||||
|
||||
// Add disks
|
||||
for (int i = 0; i < _disks.Count; i++)
|
||||
{
|
||||
string[] parts = _disks[i].Split('=');
|
||||
parameters[parts[0]] = parts[1];
|
||||
}
|
||||
|
||||
// Add serial ports
|
||||
for (int i = 0; i < _serialPorts.Count; i++)
|
||||
{
|
||||
string[] parts = _serialPorts[i].Split('=');
|
||||
parameters[parts[0]] = parts[1];
|
||||
}
|
||||
|
||||
// Add USB devices
|
||||
for (int i = 0; i < _usbDevices.Count; i++)
|
||||
{
|
||||
string[] parts = _usbDevices[i].Split('=');
|
||||
parameters[parts[0]] = parts[1];
|
||||
}
|
||||
|
||||
// Add PCI devices
|
||||
for (int i = 0; i < _pciDevices.Count; i++)
|
||||
{
|
||||
string[] parts = _pciDevices[i].Split('=');
|
||||
parameters[parts[0]] = parts[1];
|
||||
}
|
||||
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a virtual machine template in Proxmox VE.
|
||||
/// </summary>
|
||||
public class ProxmoxVMTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the template ID.
|
||||
/// </summary>
|
||||
[JsonProperty("vmid")]
|
||||
public int VMID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the template name.
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the template node.
|
||||
/// </summary>
|
||||
[JsonProperty("node")]
|
||||
public string Node { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the template CPU count.
|
||||
/// </summary>
|
||||
[JsonProperty("cpus")]
|
||||
public int CPUs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the template memory in bytes.
|
||||
/// </summary>
|
||||
[JsonProperty("maxmem")]
|
||||
public long MaxMemory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the template disk size in bytes.
|
||||
/// </summary>
|
||||
[JsonProperty("maxdisk")]
|
||||
public long MaxDisk { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the template type (qemu, lxc, etc.).
|
||||
/// </summary>
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the template description.
|
||||
/// </summary>
|
||||
[JsonProperty("description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the template creation time.
|
||||
/// </summary>
|
||||
[JsonProperty("ctime")]
|
||||
public long CreationTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the template tags.
|
||||
/// </summary>
|
||||
[JsonProperty("tags")]
|
||||
public string Tags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the template memory in megabytes.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public int MemoryMB => (int)(MaxMemory / 1024 / 1024);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the template disk size in gigabytes.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public int DiskGB => (int)(MaxDisk / 1024 / 1024 / 1024);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the template creation date.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public DateTime CreationDate => DateTimeOffset.FromUnixTimeSeconds(CreationTime).DateTime;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="ProxmoxVMTemplate"/> class from a <see cref="ProxmoxVM"/> object.
|
||||
/// </summary>
|
||||
/// <param name="vm">The VM object.</param>
|
||||
/// <returns>A new template object.</returns>
|
||||
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()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user