clusters.psm1


$ClustersDefaultProperties = ('index','name','ud-ssd-space-in-use','sys-state','logical-space-in-use','size-and-capacity','data-reduction-ratio','iops')

.(commonLib) 

Function Get-XtremXMS{
   <#
    .DESCRIPTION
    displays details of the XMS
 
    .PARAMETER Properties
    Array of properties requested from this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Get-XtremXMS
  #>

    [cmdletbinding()]
    Param (
        [Parameter()]
        [Alias("Properties")]
        [string[]]$Property,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    $Route = '/types/xms'
    $Route, $GetProperty = SetParametersForRequest $Route 1
    $ObjectSelection = 'content'
     
    $result = NewXtremRequest -Method GET -Endpoint $Route -Session $Session -ObjectSelection $ObjectSelection -GetProperty $GetProperty -Properties $Property -ShowRest:$ShowRest.IsPresent

    $result = formatOutPut $Property $result

    return $result
}

Function Get-XtremClusters{
   <#
     .DESCRIPTION
      Displays the information of the cluster currently being managed.
 
      .PARAMETER Properties
      Array of properties requested from this call.
 
        .PARAMETER Filters
      Array of filters for this call.
 
      .PARAMETER ShowRest
      Return an object represents the REST operation including URI , Method and JSON
 
      .EXAMPLE
      Get-XtremClusters
   #>


    [CmdletBinding()]
    Param(
        [Parameter()]
        [Alias("Properties")]
        [String[]]$Property=$ClustersDefaultProperties,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest,
        [Parameter()]
        [switch]$Full = $false
    )
    initCommand
    $Route = '/types/clusters'

    if ($Full) { $Property = '' }

    $result = NewXtremRequest -Method GET -Endpoint $Route  -Session $Session -ObjectSelection $ObjectSelection -Properties $Property -ShowRest:$ShowRest.IsPresent -Multi -Full:$Full.IsPresent

    $result = formatOutPut $Property $result

    finalizeCommand
    return $result
}


Function Get-XtremCluster{
   <#
     .DESCRIPTION
      Displays the cluster information.
 
      .PARAMETER ClusterName
      Cluster’s name or index number
 
      .PARAMETER Properties
      Array of properties requested from this call.
 
      .PARAMETER ShowRest
      Return an object represents the REST operation including URI , Method and JSON
 
      .EXAMPLE
      Get-XtremCluster -ClusterName brick123
  #>

  [cmdletbinding()]
    Param (
        [Alias("Name","Index")]
        [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
        [Argumentcompleter( { doComplete $args 'clusters' name })]
        $ClusterName,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Alias("Properties")]
        [array]$Property,
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
  
    $Route = '/types/clusters'
    $Route, $GetProperty = SetParametersForRequest $Route $ClusterName

    $result = NewXtremRequest -Method GET -Endpoint $Route -Session $Session -ObjectSelection $ObjectSelection -GetProperty $GetProperty -Properties $Property -ShowRest:$ShowRest.IsPresent

    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}

function Create-XtremClusterFunctions($SessionObject) {

    $SessionObject | Add-Member -MemberType ScriptMethod -Name "XMSGet" -Value {
    Param (
        [Parameter()]
        [Alias("Properties")]
        [string[]]$Property,
        [Parameter()]
        [switch]$ShowRest
    )

        return Get-XtremXMS -Session $this -Property $Property -ShowRest $ShowRest
    }

    $SessionObject | Add-Member -MemberType ScriptMethod -Name "ClusterGet" -Value {
    Param (
        [Alias("Name","Index")]
        [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
        $ClusterName,
        [Alias("Properties")]
        [array]$Property,
        [Parameter()]
        [switch]$ShowRest
      )

        Get-XtremCluster -Session $this -ClusterName $ClusterName -Property $Property -ShowRest $ShowRest
    }

    $SessionObject | Add-Member -MemberType ScriptMethod -Name "ClusterList" -Value {
    Param (
           [Parameter()]
        [Alias("Properties")]
        [String[]]$Property=$ClustersDefaultProperties,
        [Parameter()]
        [switch]$ShowRest,
        [Parameter()]
        [switch]$Full = $false
    )

        Get-XtremClusters -Session $this -Property $Property -ShowRest $ShowRest -Full $Full
    }

    $SessionObject | Add-Member -MemberType ScriptMethod -Name "SetXtremInternalPopulateClusters" -Value {

        $clusters = Get-XtremClusters -Property hardware-platform

        $clusterType = "X1"
        foreach ($cluster in $clusters)
        {
            if ($null -eq $this._XtremDefaultCluster) {
                $this._XtremDefaultCluster = $cluster.index
            }
            if ($cluster.'hardware-platform' -eq "X2") {
                $clusterType = "X2"
            }
            $name = $cluster.name
            $ind = $cluster.index
            $this._XtremClusterTypeByName.Add("$name", $clusterType);
            $this._XtremClusterTypeByIndex.Add("$ind", $clusterType);
        }
    }

    $SessionObject | Add-Member -MemberType ScriptMethod -Name "GetXtremInternalClusterType" -Value {
        param(
            [Parameter(Mandatory=$true)]
            $cluster
        )

        if ($null -eq $cluster) {
            return $this._XtremClusterTypeByIndex[$this._XtremDefaultCluster]
        }
        if ($cluster.GetType().Name -eq "Int32") {
            return $this._XtremClusterTypeByIndex[$cluster]
        }
        return $this._XtremClusterTypeByName[$cluster]
    }


    return $SessionObject
}

Export-ModuleMember Create-XtremClusterFunctions
Export-ModuleMember Get-XtremXMS
Export-ModuleMember Get-XtremClusters
Export-ModuleMember Get-XtremCluster