Public/New-Image.ps1

<#
    .DESCRIPTION
    Wrapper for Nutanix API version 0.3.
 
    .NOTES
    Author: Timothy Rasiah
#>


function New-Image {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        [String]$Name,
        [ValidateSet("DISK_IMAGE", "ISO_IMAGE")]
        [String]$ImageType,
        [String]$SourceUrl,
        [String]$ClusterUuid,
        [String]$Description
    )

    $Data = @{
        "spec" = @{
            "name" = $Name
            "resources" = @{}
        }
        "metadata" = @{
            "kind" = "image"
        }
    }

    if ($ImageType) {
        $Data.spec.resources["image_type"] = $ImageType
    }

    if ($SourceUrl) {
        $Data.spec.resources["source_uri"] = $SourceUrl
    }

    if ($ClusterUuid) {
        $Data.spec.resources["initial_placement_ref_list"] = @(
            @{
                "kind" = "cluster"
                "uuid" = $ClusterUuid
            }
        )
    }

    if ($Description) {
        $Data.spec["description"] = $Description
    }
    
    $response = Send-Request -method "POST" -endpoint "/images" -data $Data
    return $response
}