Active IQ Unified Manager Discussions

WFA Create IPSPACE

PMensing
3,487 Views

Hello,

has someone already a Command which create an IPSpace?

 

I was wondering that this is not included in the NetApp Packs.

 

Greets Pascal

1 ACCEPTED SOLUTION

mbeattie
3,421 Views

Hi Pascal,

 

Here is some WFA command code in PowerShell to create an IPSpace.

 

Param(
   [Parameter(Mandatory=$True, HelpMessage="The cluster name or IP Address")]
   [String]$Cluster,
   [Parameter(Mandatory=$True, HelpMessage="The IPSpace name")]
   [String]$IPSpace,
   [Parameter(Mandatory=$False, HelpMessage="The maximum number of ZAPI retry attempts")]
   [Int]$ZapiRetryCount
)
#'------------------------------------------------------------------------------
#'Connect to the cluster
#'------------------------------------------------------------------------------
Connect-WfaCluster $Cluster
#'------------------------------------------------------------------------------
# Create the IPSpace.
#'------------------------------------------------------------------------------
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 that helps

 

/Matt

 

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

View solution in original post

6 REPLIES 6

mbeattie
3,422 Views

Hi Pascal,

 

Here is some WFA command code in PowerShell to create an IPSpace.

 

Param(
   [Parameter(Mandatory=$True, HelpMessage="The cluster name or IP Address")]
   [String]$Cluster,
   [Parameter(Mandatory=$True, HelpMessage="The IPSpace name")]
   [String]$IPSpace,
   [Parameter(Mandatory=$False, HelpMessage="The maximum number of ZAPI retry attempts")]
   [Int]$ZapiRetryCount
)
#'------------------------------------------------------------------------------
#'Connect to the cluster
#'------------------------------------------------------------------------------
Connect-WfaCluster $Cluster
#'------------------------------------------------------------------------------
# Create the IPSpace.
#'------------------------------------------------------------------------------
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 that helps

 

/Matt

 

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

PMensing
3,397 Views

Hello,

it works. Thank you for your help.

 

Regards Pascal

PMensing
3,366 Views

Hi,

the creation of the IPSpace works fine but now i have an Problem with the Reservation. My Reservation SQL Statement is this one:

 

INSERT   
INTO
    cm_storage.ipspace
    SELECT
        NULL AS id,
        '${IPSpaceName}' AS name,
        cluster.id AS cluster_id           
    FROM
        cm_storage_cluster,
        cm_storage.ipspace          
    WHERE
        cluster.name = '${ClusterName}'                 
        AND ipspace.cluster_id = cluster.id

Unfortunately it didn't work like it should do. Can someone find any mistake in my SQL Query ?

 

Thanks Pascal

mbeattie
3,340 Views

Hi Pascal,

 

The following SQL code worked for me:

 

Reservation:

 

INSERT       
INTO
    cm_storage.ipspace
    SELECT
        NULL AS id,
        '${IPSpace}' AS 'name',
        cluster.id AS 'cluster_id'                               
    FROM
        cm_storage.cluster                       
    WHERE
        (
            cluster.primary_address = '${Cluster}'                       
            OR cluster.name = '${Cluster}'                   
        )

Verification:

 

SELECT
    ipspace.id    
FROM
    cm_storage.cluster,
    cm_storage.ipspace    
WHERE
    ipspace.cluster_id = cluster.id               
    AND ipspace.name = '${IPSpace}'               
    AND (
        cluster.primary_address = '${Cluster}'                   
        OR cluster.name = '${Cluster}'               
    )

Hope that helps?

 

/Matt

 

P.S...out of curiousity have you considered looking at alternatives such as Ansible? It is much easier to define your configuration than write code and mess around with reservations etc. EG:

 

https://docs.ansible.com/ansible/2.9/modules/na_ontap_ipspace_module.html 

 

A good place to start is this blog: https://netapp.io/2018/10/11/getting-started-with-netapp-and-ansible-first-playbook-example/ Please let me know if you have any questions?

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

mbeattie
3,276 Views

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.

PMensing
3,256 Views

Hi Matt,

thank you for your help. Now it works fine.

 

We have done some tests with ansible, but there are still missing some features (like logical space reporting), that we need.

 

I'll take a look on the Rest API Option. Thanks again for your help.

 

 

Public