proxmox-rest-module.psm1

#Region '.\Private\added-fields.ps1' 0
function createPostJson {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $True, Position = 0)][object]$Fields
    )
    $CurrentObject=New-Object -TypeName System.Object
    $Fields | ForEach-Object {
        $_.key | Out-Host
        $_.value | Out-Host
        $CurrentObject | Add-Member -MemberType NoteProperty -Name $_.key -Value $_.value
    }
    createJson($CurrentObject)
}
function createJson ($Object) { $Object | ConvertTo-Json -Depth 50 }
#EndRegion '.\Private\added-fields.ps1' 15
#Region '.\Private\api-items.ps1' 0
function Get-APIItemByQuery {
    [CmdletBinding()]
    Param(
        [parameter(Mandatory = $false)][object]$apiConnection = $Script:Connection,
        [parameter(Mandatory = $true)][string]$RelativePath,
        [parameter(Mandatory = $true)][string]$field,
        [parameter(Mandatory = $true)][string]$value
    )
    $QueryArguments= @{
        $field = $value
    }
    $ArgumentString= New-ArgumentString $QueryArguments
    $restParams = @{
        Method               = 'get'
        URI                  = "$($Connection.ApiBaseURL)/$RelativePath/?$ArgumentString"
        SkipCertificateCheck = $apiConnection.SkipCertificateCheck
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Making API search call using '$field' looking for '$value'."
    Invoke-CustomRequest $restParams -Connection $Connection
}
function Find-ApiItemsContainingName {
    [CmdletBinding()]
    Param(
        [parameter(Mandatory = $false)][object]$apiConnection = $Script:Connection,
        [parameter(Mandatory = $true)][string]$RelativePath,
        [parameter(Mandatory = $true)][string]$Name
    )
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Attempting to find items containing '$Name'."
    Get-APIItemByQuery -apiConnection $apiConnection -field 'name__ic' -value $Name -RelativePath $RelativePath
}

function Get-APIItemByName {
    [CmdletBinding()]
    Param(
        [parameter(Mandatory = $false)][object]$apiConnection = $Script:Connection,
        [parameter(Mandatory = $true)][string]$RelativePath,
        [parameter(Mandatory = $true)][string]$value
    )
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Attempting to find item named '$Name'."
    (Get-APIItemByQuery -apiConnection $apiConnection -field 'name__ie' -value $value -RelativePath $RelativePath).results
}

function Get-ApiItemByID {
    [CmdletBinding()]
    Param(
        [parameter(Mandatory = $false)][object]$apiConnection = $Script:Connection,
        [parameter(Mandatory = $true)][string]$RelativePath,
        [parameter(Mandatory = $true)][string]$id
    )
    $restParams = @{
        Method               = 'get'
        URI                  = "$($Connection.ApiBaseURL)/$RelativePath/$id/"
        SkipCertificateCheck = $apiConnection.SkipCertificateCheck
    }
    Invoke-CustomRequest $restParams -Connection $Connection
}


function Get-ApiItems {
    [CmdletBinding()]
    Param(
        [parameter(Mandatory = $false)][object]$apiConnection = $Script:Connection,
        [parameter(Mandatory = $true)][string]$RelativePath
    )
    $arguments = @{
        limit = 5000
    }
    $argumentString=[System.Web.HttpUtility]::ParseQueryString('')
    $arguments.GetEnumerator() | ForEach-Object {$argumentString.Add($_.Key, $_.Value)}
    $argumentString=$argumentString.ToString()
    $restParams = @{
        Method               = 'get'
        URI                  = "$($Connection.ApiBaseURL)/$RelativePath/?$argumentString"
        SkipCertificateCheck = $apiConnection.SkipCertificateCheck
    }
    # # (Invoke-CustomRequest -restParams $restParams -Connection $Connection).results
    (Invoke-CustomRequest $restParams -Connection $apiConnection).results
}
#EndRegion '.\Private\api-items.ps1' 79
#Region '.\Private\apiPaths.ps1' 0
$apiPaths= @{
    acc_domains = 'access/domains'
    acc_groups = 'access/groups'
    acc_openid = 'access/openid'
    acc_roles = 'access/roles'
    acc_tfa = 'access/tfa'
    acc_users = 'access/users'
    acc_acl = 'access/acl'
    acc_perms = 'access/permissions'
    cl = 'cluster'
    cl_acme = 'cluster/acme'
    cl_backup = 'cluster/backup'
    cl_backup_info = 'cluster/backup-info'
    cl_ceph = 'cluster/ceph'
    cl_config = 'cluster/config'
    cl_firewall = 'cluster/firewall'
    cl_ha = 'cluster/ha'
    cl_jobs = 'cluster/jobs'
    cl_mapping = 'cluster/mapping'
    cl_metrics = 'cluster/metrics'
    cl_notifs = 'cluster/notifications'
    cl_repl = 'cluster/replication'
    cl_sdn = 'cluster/sdn'
    cl_status = 'cluster/status'
    cl_cf_apiver = '/cluster/config/apiversion'
    cl_cf_join = 'cluster/config/join'
    cl_cf_nodes = 'cluster/config/nodes'
    cl_cf_qdevice = 'cluster/config/qdevice'
    cl_cf_totem = 'cluster/config/totem'
    pools = 'pools'
    nodes = 'nodes'
    storage = 'storage'
    version = 'version'
    cl_fw_aliases = 'cluster/firewall/aliases'
    cl_fw_groups = 'cluster/firewall/groups'
    cl_fw_ipset = 'cluster/firewall/ipset'
    cl_fw_macros = 'cluster/firewall/macros'
    cl_fw_options = 'cluster/firewall/options'
    cl_fw_refs = 'cluster/firewall/refs'
    cl_fw_rules = 'cluster/firewall/rules'
    cl_resources = 'cluster/resources'
}
#EndRegion '.\Private\apiPaths.ps1' 43
#Region '.\Private\Invoke-PXRequest.ps1' 0
function Invoke-PXRequest {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $True, Position = 0)][System.Object]$restParams,
        [Parameter(Mandatory = $True, Position = 1)][System.Object]$Connection
    )
    $Headers = @{
        Authorization = "PVEAPIToken $($Connection.User)!$($Connection.TokenID)=$($Connection.ApiKey)"
        "Content-Type"    = 'application/json'
    }
    Write-Verbose ("[$($MyInvocation.MyCommand.Name)] REST params:`n" + ($restParams|Out-String))
    Write-Verbose ("[$($MyInvocation.MyCommand.Name)] Headers:`n" + ($Headers|Out-String))
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Making API call."
    try {
        $result = Invoke-RestMethod @restParams -Headers $headers -SkipCertificateCheck:$Connection.SkipCertificateCheck -ResponseHeadersVariable $ResponseHeaders -StatusCodeVariable $StatusCode
        Write-Verbose ("[$($MyInvocation.MyCommand.Name)] ResponseHeaders:`n" + ($ResponseHeaders|Out-String))
        Write-Verbose ("[$($MyInvocation.MyCommand.Name)] StatusCode:`n" + ($StatusCode|Out-String))
    }
    catch {
        Write-Error ("[$($MyInvocation.MyCommand.Name)] Exception:`n" + ($_.Exception.Message|Out-String))
    }
    $result.data
}
 
#EndRegion '.\Private\Invoke-PXRequest.ps1' 25
#Region '.\Private\New-ArgumentString.ps1' 0
function New-ArgumentString {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $True, Position = 0)][hashtable]$QueryArguments
    )
    $OutputString = [System.Web.HttpUtility]::ParseQueryString('')
    $QueryArguments.GetEnumerator() | ForEach-Object { $OutputString.Add($_.Key, $_.Value) }
    $OutputString.ToString()
}
#EndRegion '.\Private\New-ArgumentString.ps1' 10
#Region '.\Private\parseNics.ps1' 0
function parseNICConfigLXC ($Definition) {
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Begin"
    Write-Verbose ("[$($MyInvocation.MyCommand.Name)] " + ($Definition|Out-String))
    $NameHunt=$Definition | Select-String -Pattern 'name=([\w\d]+),'
    $MACHunt=$Definition | Select-String -Pattern 'hwaddr=([0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2})'
    $IPv4Hunt=$Definition | Select-String -Pattern 'ip=((?:[0-9]{1,3}\.){3}[0-9]{1,3}\/[\d]{1,2})'
    $IPv6Hunt= $Definition | Select-String -Pattern 'ip6=((?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}\/[\d]{1,3})'
    $Name= $NameHunt.Matches.Groups[1].Value
    $MAC = $MACHunt.Matches.Groups[1].Value
    if ($null -ne $IPv4Hunt) {$IPv4 = $IPv4Hunt.Matches.Groups[1].Value}
    else {$IPv4 = 'dhcp'}
    if ($null -ne $IPv6Hunt) {$IPv6 = $IPv6Hunt.Matches.Groups[1].Value}
    else {$IPv6 = 'auto'}
    $Results=[PSCustomObject]@{
        Name = $Name
        MAC  = $MAC
        IPv4 = $IPv4
        IPv6 = $IPv6
    }
    $Results
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] End"
    #>
}

function parseQEMUNetworkConfig ($NetInfo) {
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Begin"
    [System.Collections.ArrayList]$Results=@()
    foreach ($Item in $NetInfo) {
        $tempItem=[PSCustomObject]@{
            Name = $Item.Name
            MAC  = $Item.Definition.Split('=')[2].Split(',')[0]
        }
        $Results.Add($tempItem)|Out-Null
    }
    $Results
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] End"
}
#EndRegion '.\Private\parseNics.ps1' 38
#Region '.\Private\processFieldUpdates.ps1' 0
function processFieldUpdates($key,$value) {
    switch($key){
        'slug' {$value=makeSlug -name $value}
        'tags' {[array]$value=$value.Split(',')}
        'install_date' {$value = $value|Get-Date -Format 'yyyy-MM-dd'}
        'termination_date' {$value = $value|Get-Date -Format 'yyyy-MM-dd'}
        'ipaddresses' {[array]$value=$value.Split(',')}
        default {}
    }
    $update=@{
        $key = $value
    }
    $update
}
#EndRegion '.\Private\processFieldUpdates.ps1' 15
#Region '.\Public\endpoints\access\acl\Get-PXACLs.ps1' 0
function Get-PXACLs {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['acc_acl'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\access\acl\Get-PXACLs.ps1' 13
#Region '.\Public\endpoints\access\domains\Get-PXDomains.ps1' 0
function Get-PXDomains {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['acc_domains'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\access\domains\Get-PXDomains.ps1' 13
#Region '.\Public\endpoints\access\groups\Get-PXGroups.ps1' 0
function Get-PXGroups {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['acc_groups'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\access\groups\Get-PXGroups.ps1' 13
#Region '.\Public\endpoints\access\openid\Get-PXOpenID.ps1' 0
function Get-PXOpenID {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['acc_openid'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\access\openid\Get-PXOpenID.ps1' 13
#Region '.\Public\endpoints\access\permissions\Get-PXPermissions.ps1' 0
function Get-PXPermissions {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['acc_perms'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\access\permissions\Get-PXPermissions.ps1' 13
#Region '.\Public\endpoints\access\roles\Get-PXRoles.ps1' 0
function Get-PXRoles {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['acc_roles'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\access\roles\Get-PXRoles.ps1' 13
#Region '.\Public\endpoints\access\tfa\Get-PXTFA.ps1' 0
function Get-PXPermissions {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['acc_tfa'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\access\tfa\Get-PXTFA.ps1' 13
#Region '.\Public\endpoints\access\users\Get-PXUsers.ps1' 0
function Get-PXUsers {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['acc_users'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\access\users\Get-PXUsers.ps1' 13
#Region '.\Public\endpoints\cluster\acme\Get-PXACME.ps1' 0
function Get-PXACME {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_acme'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\acme\Get-PXACME.ps1' 13
#Region '.\Public\endpoints\cluster\backup-info\Get-PXBackupInfo.ps1' 0
function Get-PXBackupInfo {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_backup_info'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\backup-info\Get-PXBackupInfo.ps1' 13
#Region '.\Public\endpoints\cluster\backup\Get-PXBackup.ps1' 0
function Get-PXBackup {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_backup'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\backup\Get-PXBackup.ps1' 13
#Region '.\Public\endpoints\cluster\config\apiversion\Get-PXClusterAPIVersion.ps1' 0
function Get-PXClusterAPIVersion {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_cf_apiver'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\config\apiversion\Get-PXClusterAPIVersion.ps1' 13
#Region '.\Public\endpoints\cluster\config\join\Get-PXClusterJoinInfo.ps1' 0
function Get-PXClusterJoinInfo {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_cf_join'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\config\join\Get-PXClusterJoinInfo.ps1' 13
#Region '.\Public\endpoints\cluster\config\nodes\Get-PXClusterNodes.ps1' 0
function Get-PXClusterNodes {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_cf_nodes'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\config\nodes\Get-PXClusterNodes.ps1' 13
#Region '.\Public\endpoints\cluster\config\qdevice\Get-PXQDevice.ps1' 0
function Get-PXQDevice {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_cf_qdevice'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\config\qdevice\Get-PXQDevice.ps1' 13
#Region '.\Public\endpoints\cluster\config\totem\Get-PXTotem.ps1' 0
function Get-PXTotem {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_cf_totem'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\config\totem\Get-PXTotem.ps1' 13
#Region '.\Public\endpoints\cluster\firewall\aliases\Get-PXFWAliases.ps1' 0
function Get-PXFWAliases {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_fw_aliases'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\firewall\aliases\Get-PXFWAliases.ps1' 13
#Region '.\Public\endpoints\cluster\firewall\groups\Get-PXFWGroups.ps1' 0
function Get-PXFWGroups {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_fw_groups'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\firewall\groups\Get-PXFWGroups.ps1' 13
#Region '.\Public\endpoints\cluster\firewall\ipset\Get-PXFWIpset.ps1' 0
function Get-PXFWIpset {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_fw_ipset'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\firewall\ipset\Get-PXFWIpset.ps1' 13
#Region '.\Public\endpoints\cluster\firewall\macros\Get-PXFWMacros.ps1' 0
function Get-PXFWMacros {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_fw_macros'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\firewall\macros\Get-PXFWMacros.ps1' 13
#Region '.\Public\endpoints\cluster\firewall\options\Get-PXFWOptions.ps1' 0
function Get-PXFWOptions {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_fw_options'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\firewall\options\Get-PXFWOptions.ps1' 13
#Region '.\Public\endpoints\cluster\firewall\refs\Get-PXFWRefs.ps1' 0
function Get-PXFWRefs {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_fw_refs'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\firewall\refs\Get-PXFWRefs.ps1' 13
#Region '.\Public\endpoints\cluster\firewall\rules\Get-PXFWRules.ps1' 0
function Get-PXFWRules {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_fw_rules'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\firewall\rules\Get-PXFWRules.ps1' 13
#Region '.\Public\endpoints\cluster\resources\Get-PXHypervisors.ps1' 0
function Get-PXHypervisors {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_resources'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    (Invoke-PXRequest -restParams $restParams -Connection $Connection)|Where-Object {$_.type -eq 'node'}
}
#EndRegion '.\Public\endpoints\cluster\resources\Get-PXHypervisors.ps1' 13
#Region '.\Public\endpoints\cluster\resources\Get-PXLXCs.ps1' 0
function Get-PXLXCs {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_resources'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    (Invoke-PXRequest -restParams $restParams -Connection $Connection)|Where-Object {$_.type -eq 'lxc'}
}
#EndRegion '.\Public\endpoints\cluster\resources\Get-PXLXCs.ps1' 13
#Region '.\Public\endpoints\cluster\resources\Get-PXLXCVMConfigInfo.ps1' 0
function Get-PXLXCVMConfigInfo {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true,Position=0)][String]$NodeName,
        [Parameter(Mandatory=$true,Position=1)][int]$ID,
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['nodes'])/$NodeName/lxc/$ID/config"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    (Invoke-PXRequest -restParams $restParams -Connection $Connection)
}
#EndRegion '.\Public\endpoints\cluster\resources\Get-PXLXCVMConfigInfo.ps1' 15
#Region '.\Public\endpoints\cluster\resources\Get-PXQEMUNodeInfo.ps1' 0
function Get-PXQEMUNodeInfo {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true,Position=0)][String]$NodeName,
        [Parameter(Mandatory=$false,Position=1)][int]$ID,
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['nodes'])/$NodeName/qemu"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    if($ID){(Invoke-PXRequest -restParams $restParams -Connection $Connection)|Where-Object {$_.VMID -eq $ID}}
    else{(Invoke-PXRequest -restParams $restParams -Connection $Connection)}

}
#EndRegion '.\Public\endpoints\cluster\resources\Get-PXQEMUNodeInfo.ps1' 17
#Region '.\Public\endpoints\cluster\resources\Get-PXQEMUs.ps1' 0
function Get-PXQEMUs {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_resources'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    (Invoke-PXRequest -restParams $restParams -Connection $Connection)|Where-Object {$_.type -eq 'qemu'}
}
#EndRegion '.\Public\endpoints\cluster\resources\Get-PXQEMUs.ps1' 13
#Region '.\Public\endpoints\cluster\resources\Get-PXQEMUVMConfigInfo.ps1' 0
function Get-PXQEMUVMConfigInfo {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true,Position=0)][String]$NodeName,
        [Parameter(Mandatory=$true,Position=1)][int]$ID,
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['nodes'])/$NodeName/qemu/$ID/config"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    (Invoke-PXRequest -restParams $restParams -Connection $Connection)
}
#EndRegion '.\Public\endpoints\cluster\resources\Get-PXQEMUVMConfigInfo.ps1' 15
#Region '.\Public\endpoints\cluster\resources\Get-PXQEMUVMGuestNetInfo.ps1' 0
function Get-PXQEMUVMGuestNetInfo {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true,Position=0)][String]$NodeName,
        [Parameter(Mandatory=$true,Position=1)][int]$ID,
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['nodes'])/$NodeName/qemu/$ID/agent/network-get-interfaces"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    (Invoke-PXRequest -restParams $restParams -Connection $Connection).result|Where {$_.Name -notlike "Loopback*"}

}
#EndRegion '.\Public\endpoints\cluster\resources\Get-PXQEMUVMGuestNetInfo.ps1' 16
#Region '.\Public\endpoints\cluster\resources\Get-PXQEMUVMInfo.ps1' 0
function Get-PXQEMUNodeVMInfo {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true,Position=0)][String]$NodeName,
        [Parameter(Mandatory=$false,Position=1)][int]$ID,
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['nodes'])/$NodeName/qemu"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    if($ID){(Invoke-PXRequest -restParams $restParams -Connection $Connection)|Where-Object {$_.VMID -eq $ID}}
    else{(Invoke-PXRequest -restParams $restParams -Connection $Connection)}

}
#EndRegion '.\Public\endpoints\cluster\resources\Get-PXQEMUVMInfo.ps1' 17
#Region '.\Public\endpoints\cluster\resources\Get-PXResources.ps1' 0
function Get-PXResources {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_resources'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\cluster\resources\Get-PXResources.ps1' 13
#Region '.\Public\endpoints\cluster\resources\Get-PXVMs.ps1' 0
function Get-PXVMs {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][switch]$IncludeAllIPs,
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['cl_resources'])"
    }
    $QEMUS=Get-PXQEMUs
    $LXCS=Get-PXLXCs
    [System.Collections.ArrayList]$Results=@()
    foreach ($item in $QEMUS){
        $VMConfigInfo=Get-PXQEMUVMConfigInfo -NodeName $item.Node -ID $item.VMID
        $NetworkDevicesConfig= parseQEMUNetworkConfig ($VMConfigInfo|Get-Member|Where-Object {$_.Name -like 'net*'})
        [System.Collections.ArrayList]$NICInfo=@()
        try {
            $NetworkDevicesAgent= Get-PXQEMUVMGuestNetInfo -NodeName $item.Node -ID $item.VMID -erroraction stop
            Foreach($netDevice in $NetworkDevicesConfig) {
                $IPv4Entries=(($NetworkDevicesAgent | Where-Object {$_.'hardware-address' -eq $netDevice.MAC}).'ip-addresses'|Where-Object {$_.'ip-address-type' -eq 'ipv4'})
                $IPv4String=($IPv4Entries| % {"$($_.'ip-address')/$($_.prefix)"}) -join ','
                if ($IncludeAllIPs){$IPv6Entries=(($NetworkDevicesAgent | Where-Object {$_.'hardware-address' -eq $netDevice.MAC}).'ip-addresses'|Where-Object {$_.'ip-address-type' -eq 'ipv6'})}
                else{$IPv6Entries=(($NetworkDevicesAgent | Where-Object {$_.'hardware-address' -eq $netDevice.MAC}).'ip-addresses'|Where-Object {$_.'ip-address-type' -eq 'ipv6' -and $_.'ip-address' -notlike 'fe80*' -and $_.prefix -ne 128})}
                $IPv6String=($IPv6Entries| % {"$($_.'ip-address')/$($_.prefix)"}) -join ','
                $NicEntry=[PSCustomObject]@{
                    Name = $netDevice.Name
                    MAC  = $netDevice.MAC
                    IPv4 = $IPv4String
                    IPv6 = $IPv6String
                }
                $NICInfo.Add($NicEntry)|Out-Null
            }
        }
        catch{
            Foreach($netDevice in $NetworkDevicesConfig) {
                $NicEntry=[PSCustomObject]@{
                    Name = $netDevice.Name
                    MAC  = $netDevice.MAC
                    IPv4 = ''
                    IPv6 = ''
                }
                $NICInfo.Add($NicEntry)|Out-Null
            }
        }
        $ReportItem=[PSCustomObject]@{
            VMID = $item.vmid
            Name  = (Get-PXQEMUNodeInfo -NodeName $item.Node -ID $item.VMID).name
            Node = $item.Node
            CPUCount= $item.maxcpu
            Type = 'QEMU'
        }
        $ReportItem | Add-Member -MemberType NoteProperty -Name NICs -Value $NICInfo
        $Results.Add($ReportItem)|Out-Null
    }
    foreach ($item in $LXCS){
        $NetworkDevicesConfig=((Get-PXLXCVMConfigInfo -NodeName $item.Node -ID $item.VMID)|Get-member |Where-Object {$_.Name -like 'net*'})
        [System.Collections.ArrayList]$NICInfo=@()
        foreach ($nicItem in $NetworkDevicesConfig){
            $Definition=parseNICConfigLXC($nicItem.Definition)
            $NicEntry=[PSCustomObject]@{
                Name = $nicItem.Name
                MAC  = $Definition.MAC
                IPv4 = $Definition.IPv4
                IPv6 = $Definition.IPv6
            }
            $NICInfo.Add($NicEntry)|Out-Null
        }

        $ReportItem=[PSCustomObject]@{
            VMID = $item.vmid
            Name  = $item.name
            Node = $item.Node
            CPUCount= $item.maxcpu
            Type = 'LXC'
        }
        $ReportItem | Add-Member -MemberType NoteProperty -Name NICs -Value $NICInfo
        #[array]$ReportNICs=((Get-PXLXCVMConfigInfo -NodeName $item.Node -ID $item.VMID)|Get-member |Where-Object {$_.Name -like 'net*'})
        #$ReportItem | Add-Member -MemberType NoteProperty -Name NICs -Value $ReportNICs
        #$ReportItem | Add-Member -MemberType NoteProperty -Name NICs -Value $ParsedNICInfo
        $Results.Add($ReportItem)|Out-Null
    }
    $Results

}
#EndRegion '.\Public\endpoints\cluster\resources\Get-PXVMs.ps1' 86
#Region '.\Public\endpoints\nodes\Get-PXNodes.ps1' 0
function Get-PXNodes {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['nodes'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\nodes\Get-PXNodes.ps1' 13
#Region '.\Public\endpoints\pools\Get-PXPools.ps1' 0
function Get-PXPools {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['pools'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\pools\Get-PXPools.ps1' 13
#Region '.\Public\endpoints\storage\Get-PXStorage.ps1' 0
function Get-PXStorage {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['storage'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\storage\Get-PXStorage.ps1' 13
#Region '.\Public\endpoints\version\Get-PXVersion.ps1' 0
function Get-PXVersion {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false)][object]$Connection=$Script:PXConnection
    )
    $restParams=@{
        Method = 'Get'
        Uri = "$($Connection.ApiBaseUrl)/$($apiPaths['version'])"
    }
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Calling Invoke-PXRequest"
    Invoke-PXRequest -restParams $restParams -Connection $Connection
}
#EndRegion '.\Public\endpoints\version\Get-PXVersion.ps1' 13
#Region '.\Public\Get-PXCurrentConnection.ps1' 0
function Get-PXCurrentConnection {
    "Default Proxmox Connection:"
    $Script:PXConnection
}
#EndRegion '.\Public\Get-PXCurrentConnection.ps1' 5
#Region '.\Public\New-PXConnection.ps1' 0
function New-PXConnection {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true,Position=0)][string]$DeviceAddress,
        [Parameter(Mandatory=$true,Position=1)][string]$User,
        [Parameter(Mandatory=$true,Position=2)][string]$TokenID,
        [Parameter(Mandatory=$true,Position=3)][string]$ApiKey,
        [Parameter(Mandatory=$false)][int]$port=8006,
        [Parameter(Mandatory=$false)][switch]$SkipCertificateCheck,
        [Parameter(Mandatory=$false)][switch]$Passthru
    )
    $ConnectionProperties = @{
        Address = "$DeviceAddress"
        ApiKey = $ApiKey
        ApiBaseUrl = "https://$($DeviceAddress):$port/api2/json"
        User = $User
        TokenID = $TokenID
        SkipCertificateCheck = $SkipCertificateCheck
    }
    $PXConnection = New-Object psobject -Property $ConnectionProperties
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Host '$($PXConnection.Address)' is now the default connection."
    $Script:PXConnection = $PXConnection
    if ($Passthru) {
        $PXConnection
    }
} 
#EndRegion '.\Public\New-PXConnection.ps1' 27
#Region '.\Public\Test-PXConnection.ps1' 0
function Test-PXConnection {
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline=$true,Mandatory=$false,Position=0)][object]$PXConnection=$Script:PXConnection
    )
    Write-Verbose "[$($MyInvocation.MyCommand.Name)] Trying to connect"
    try {
        Get-PXStatus -Connection $PXConnection
    }
    catch {
        write-error "failed"
        $NBConnection
    }
}
#EndRegion '.\Public\Test-PXConnection.ps1' 15