mirror of
https://github.com/Grace-Solutions/PSProxmox.git
synced 2026-07-26 08:18:19 +00:00
Fix cloud image functionality and add pipeline support
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
@{
|
||||
ModuleVersion = '2025.05.11.0935'
|
||||
ModuleVersion = '2025.05.11.1030'
|
||||
GUID = 'd24f0894-3d0c-4ef1-a41e-b273c3db86ad'
|
||||
Author = 'PSProxmox Team'
|
||||
CompanyName = 'PSProxmox'
|
||||
@@ -106,7 +106,7 @@
|
||||
Tags = @('Proxmox', 'VirtualMachine', 'Cluster', 'Management')
|
||||
LicenseUri = 'https://github.com/Grace-Solutions/PSProxmox/blob/main/LICENSE'
|
||||
ProjectUri = 'https://github.com/Grace-Solutions/PSProxmox'
|
||||
ReleaseNotes = 'Added LXC container and TurnKey template support. See https://github.com/Grace-Solutions/PSProxmox/releases/tag/v2025.05.11.0935'
|
||||
ReleaseNotes = 'Added LXC container and TurnKey template support. Fixed cloud image functionality and added pipeline support. See https://github.com/Grace-Solutions/PSProxmox/releases/tag/v2025.05.11.1030'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,14 +68,14 @@ namespace PSProxmox.CloudImages
|
||||
(string.IsNullOrEmpty(variant) || i.Variant == variant));
|
||||
}
|
||||
|
||||
private static async Task<Dictionary<string, Dictionary<string, CloudImageMetadata>>> GetMetadataAsync()
|
||||
private static Task<Dictionary<string, Dictionary<string, CloudImageMetadata>>> GetMetadataAsync()
|
||||
{
|
||||
if (File.Exists(_metadataFile))
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(_metadataFile);
|
||||
return JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, CloudImageMetadata>>>(json);
|
||||
return Task.FromResult(JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, CloudImageMetadata>>>(json));
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -83,13 +83,14 @@ namespace PSProxmox.CloudImages
|
||||
}
|
||||
}
|
||||
|
||||
return new Dictionary<string, Dictionary<string, CloudImageMetadata>>(StringComparer.OrdinalIgnoreCase);
|
||||
return Task.FromResult(new Dictionary<string, Dictionary<string, CloudImageMetadata>>(StringComparer.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private static async Task SaveMetadataAsync(Dictionary<string, Dictionary<string, CloudImageMetadata>> metadata)
|
||||
private static Task SaveMetadataAsync(Dictionary<string, Dictionary<string, CloudImageMetadata>> metadata)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(metadata, Formatting.Indented);
|
||||
File.WriteAllText(_metadataFile, json);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static async Task<Dictionary<string, CloudImageMetadata>> FetchDistributionMetadataAsync(string distribution)
|
||||
|
||||
@@ -25,6 +25,10 @@ namespace PSProxmox.Cmdlets
|
||||
/// <para>Get Ubuntu 22.04 cloud images</para>
|
||||
/// <code>Get-ProxmoxCloudImage -Distribution "ubuntu" -Release "22.04"</code>
|
||||
/// </example>
|
||||
/// <example>
|
||||
/// <para>Get Ubuntu 22.04 server cloud image and download it</para>
|
||||
/// <code>Get-ProxmoxCloudImage -Distribution "ubuntu" -Release "22.04" -Variant "server" | Save-ProxmoxCloudImage</code>
|
||||
/// </example>
|
||||
[Cmdlet(VerbsCommon.Get, "ProxmoxCloudImage")]
|
||||
[OutputType(typeof(CloudImage))]
|
||||
public class GetProxmoxCloudImageCmdlet : PSCmdlet
|
||||
|
||||
@@ -20,6 +20,14 @@ namespace PSProxmox.Cmdlets
|
||||
/// <para>Download a Debian 11 generic cloud image</para>
|
||||
/// <code>Save-ProxmoxCloudImage -Distribution "debian" -Release "11" -Variant "generic"</code>
|
||||
/// </example>
|
||||
/// <example>
|
||||
/// <para>Get Ubuntu 22.04 server cloud image and download it</para>
|
||||
/// <code>Get-ProxmoxCloudImage -Distribution "ubuntu" -Release "22.04" -Variant "server" | Save-ProxmoxCloudImage</code>
|
||||
/// </example>
|
||||
/// <example>
|
||||
/// <para>Download an Ubuntu 22.04 server cloud image to a specific location</para>
|
||||
/// <code>Save-ProxmoxCloudImage -Distribution "ubuntu" -Release "22.04" -Variant "server" -OutputPath "C:\Images\ubuntu-22.04-server.img"</code>
|
||||
/// </example>
|
||||
[Cmdlet(VerbsData.Save, "ProxmoxCloudImage")]
|
||||
[OutputType(typeof(string))]
|
||||
public class SaveProxmoxCloudImageCmdlet : PSCmdlet
|
||||
@@ -27,32 +35,40 @@ namespace PSProxmox.Cmdlets
|
||||
/// <summary>
|
||||
/// <para type="description">The distribution to download (e.g., "ubuntu", "debian").</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = true, Position = 0)]
|
||||
[Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true, ParameterSetName = "ByProperties")]
|
||||
[ValidateSet("ubuntu", "debian")]
|
||||
public string Distribution { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The release version to download (e.g., "22.04", "11").</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = true, Position = 1)]
|
||||
[Parameter(Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true, ParameterSetName = "ByProperties")]
|
||||
public string Release { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The image variant to download (e.g., "server", "minimal").</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false, Position = 2)]
|
||||
[Parameter(Mandatory = false, Position = 2, ValueFromPipelineByPropertyName = true, ParameterSetName = "ByProperties")]
|
||||
public string Variant { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The cloud image object to download.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "ByCloudImage")]
|
||||
public CloudImage CloudImage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The output path where the image will be saved. If not specified, the image will be saved to the default download directory.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false)]
|
||||
[Parameter(Mandatory = false, ParameterSetName = "ByProperties")]
|
||||
[Parameter(Mandatory = false, ParameterSetName = "ByCloudImage")]
|
||||
public string OutputPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">Force download even if the image already exists.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false)]
|
||||
[Parameter(Mandatory = false, ParameterSetName = "ByProperties")]
|
||||
[Parameter(Mandatory = false, ParameterSetName = "ByCloudImage")]
|
||||
public SwitchParameter Force { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -65,10 +81,21 @@ namespace PSProxmox.Cmdlets
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
// Get the cloud image
|
||||
var image = await CloudImageRepository.GetImageAsync(Distribution, Release, Variant);
|
||||
if (image == null)
|
||||
CloudImage image;
|
||||
|
||||
if (ParameterSetName == "ByCloudImage")
|
||||
{
|
||||
throw new Exception($"Cloud image not found for {Distribution} {Release} {Variant}");
|
||||
// Use the provided CloudImage object
|
||||
image = CloudImage;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get the cloud image from the repository
|
||||
image = await CloudImageRepository.GetImageAsync(Distribution, Release, Variant);
|
||||
if (image == null)
|
||||
{
|
||||
throw new Exception($"Cloud image not found for {Distribution} {Release} {Variant}");
|
||||
}
|
||||
}
|
||||
|
||||
// Create a cancellation token source
|
||||
|
||||
Reference in New Issue
Block a user