Hi Pascal,
Also another option for you in WFA is to compare the ONTAP version running on the cluster, if 9.6.0 or greater then use the native REST API otherwise use the PSTK\ZAPI.
Param(
[Parameter(Mandatory=$True, HelpMessage="The cluster name or IP Address")]
[String]$Cluster,
[Parameter(Mandatory=$True, HelpMessage="The cluster's ONTAP version number")]
[String]$Version,
[Parameter(Mandatory=$True, HelpMessage="The IPSpace name")]
[String]$IPSpace,
[Parameter(Mandatory=$False, HelpMessage="The maximum number of ZAPI retry attempts")]
[Int]$ZapiRetryCount
)
#'------------------------------------------------------------------------------
#'Compare ONTAP versions.
#'------------------------------------------------------------------------------
$versionCompare960 = Compare-OntapVersions $Version "9.6.0"
If($versionCompare960 -lt 0){
[Bool]$UseRestApi = $False
}Else{
[Bool]$UseRestApi = $True
}
#'------------------------------------------------------------------------------
#'Create the IPSpace using the REST API if running ONTAP 9.6 or greater
#'------------------------------------------------------------------------------
If($UseRestApi){
[String]$uri = "https://$Cluster/api/network/ipspaces"
[System.Management.Automation.PSCredential]$Credentials = Get-WfaCredentials -Host $Cluster
[HashTable]$ips = @{}
[HashTable]$ips.Add("name", $IPSpace)
$body = $ips | ConvertTo-Json
#'---------------------------------------------------------------------------
#'Create the IPSpace on the cluster.
#'---------------------------------------------------------------------------
Get-WFALogger -Info -Message "Creating IPSpace ""$IPSpace"" on cluster ""$Cluster"" using URI ""$uri"""
Try{
$response = Invoke-RestMethod -Uri $uri -Method POST -Body $body -ContentType "application/json" -Credential $Credentials -ErrorAction Stop
Get-WFALogger -Info -Message "Created IPSpace ""$IPSpace"" on cluster ""$Cluster"" using URI ""$uri"""
}Catch{
Get-WFALogger -Error -Message $("Failed Creating IPSpace ""$IPSpace"" on cluster ""$Cluster"" using URI ""$uri"". Error " + $_.Exception.Message + " Status Code " + $_.Exception.Response.StatusCode.value__)
Throw "Failed creating IPSpace ""$IPSpace"" on cluster ""$Cluster"""
}
}Else{
#'---------------------------------------------------------------------------
#'Connect to the cluster and create the IPSpace using the PSTK\ZAPI.
#'---------------------------------------------------------------------------
Connect-WfaCluster $Cluster
Get-WFALogger -Info -Message "Creating IPSpace ""$IPSpace"" on cluster ""$Cluster"""
Try{
[String]$command = "New-NcNetIpspace -Name $IPSpace "
If($ZapiRetryCount){
[String]$command += "-ZapiRetryCount $ZapiRetryCount "
}
[String]$command += "-ErrorAction Stop"
Invoke-Expression -Command $command -ErrorAction Stop
Get-WFALogger -Info -Message "Executed Command`: $command"
Get-WFALogger -Info -Message "Created IPSpace ""$IPSpace"" on cluster ""$Cluster"""
}Catch{
Get-WFALogger -Error -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
Throw "Failed creating IPSpace ""$IPSpace"" on cluster ""$Cluster"""
}
}
#'------------------------------------------------------------------------------
Hope thats useful.
/Matt
If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.