├── LICENSE.txt ├── WSAPI ├── AvailableSpace.psm1 ├── AoConfigurationInformation.psm1 ├── SystemEvents.psm1 ├── WsapiUserAndRoleInformation.psm1 ├── SessionKeysAndWsapiSystemAccess.psm1 ├── FlashCacheOperations.psm1 ├── VirtualLUNs.psm1 └── SystemInformationQueriesAndManagement.psm1 ├── README.md ├── CLI ├── InventoryManagement.psm1 ├── FilePersonaManagement.psm1 ├── UserManagement.psm1 ├── Flashcache.psm1 ├── MaintenanceMode.psm1 ├── Vasa.psm1 ├── CimManagement.psm1 └── TaskManagement.psm1 └── HPEStoragePowerShellToolkit.psd1 /LICENSE.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/hpe3par_pstoolkit/HEAD/LICENSE.txt -------------------------------------------------------------------------------- /WSAPI/AvailableSpace.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: AvailableSpace.psm1 23 | ## Description: Available space cmdlets 24 | ## 25 | ## Created: February 2020 26 | ## Last Modified: February 2020 27 | ## History: v3.0 - Created 28 | ##################################################################################### 29 | 30 | $Info = "INFO:" 31 | $Debug = "DEBUG:" 32 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 33 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 34 | 35 | ############################################################################################################################################ 36 | ## FUNCTION Get-CapacityInfo_WSAPI 37 | ############################################################################################################################################ 38 | Function Get-CapacityInfo_WSAPI 39 | { 40 | <# 41 | 42 | .SYNOPSIS 43 | Overall system capacity. 44 | 45 | .DESCRIPTION 46 | Overall system capacity. 47 | 48 | .PARAMETER WsapiConnection 49 | WSAPI Connection object created with Connection command 50 | 51 | .EXAMPLE 52 | Get-CapacityInfo_WSAPI 53 | Display Overall system capacity. 54 | 55 | .Notes 56 | NAME : Get-CapacityInfo_WSAPI 57 | LASTEDIT: February 2020 58 | KEYWORDS: Get-CapacityInfo_WSAPI 59 | 60 | .Link 61 | http://www.hpe.com 62 | 63 | #Requires PS -Version 3.0 64 | #> 65 | 66 | [CmdletBinding()] 67 | Param( 68 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 69 | $WsapiConnection = $global:WsapiConnection 70 | ) 71 | 72 | # Test if connection exist 73 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 74 | 75 | #Request 76 | $Result = Invoke-WSAPI -uri '/capacity' -type 'GET' -WsapiConnection $WsapiConnection 77 | 78 | if($Result.StatusCode -eq 200) 79 | { 80 | # Results 81 | $dataPS = ($Result.content | ConvertFrom-Json) 82 | } 83 | else 84 | { 85 | return $Result.StatusDescription 86 | } 87 | # Add custom type to the resulting oject for formating purpose 88 | Write-DebugLog "Running: Add custom type to the resulting object for formatting purpose" $Debug 89 | #$AlldataPS = Format-Result -dataPS $dataPS -TypeName '3PAR.Capacity' 90 | 91 | Write-Verbose "Return result(s) without any filter" 92 | Write-DebugLog "End: Get-CapacityInfo_WSAPI(WSAPI)" $Debug 93 | return $dataPS 94 | } 95 | #END Get-CapacityInfo_WSAPI 96 | 97 | 98 | Export-ModuleMember Get-CapacityInfo_WSAPI -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 2 | # HPE Alletra 9000 and Primera and 3PAR PowerShell Toolkit 3 | 4 | The HPE Alletra 9000 and Primera and 3PAR PowerShell Toolkit supports cmdlets, which are wrappers around the native HPE Alletra 9000 or HPE Primera or HPE 3PAR storage CLI commands and Web Services API (WSAPI). 5 | 6 | ## Features of HPE Alletra 9000 and Primera and 3PAR PowerShell Toolkit 7 | 8 | The latest HPE Alletra 9000 and Primera and 3PAR PowerShell Toolkit works with PowerShell 3.0 and later up to PowerShell 5.1, PowerShell Core 6.x, and PowerShell 7. 9 | 10 | It can be used in the following two ways: 11 | 12 | **With Native HPE Alletra 9000 or HPE Primera or HPE 3PAR storage CLI command** 13 | 14 | When you run the cmdlets, the following actions take place: 15 | 16 | 1. A secure connection to the HPE Alletra 9000 or HPE Primera or HPE 3PAR storage is established over a secure shell. 17 | 2. The native HPE Alletra 9000 or HPE Primera or HPE 3PAR storage CLI command and parameters are formed based on the PowerShell cmdlet and parameters. 18 | 3. The native HPE Alletra 9000 or HPE Primera or HPE 3PAR storage CLI command are executed. 19 | 4. The output of the cmdlets is returned as PowerShell objects. This output can be piped to other PowerShell cmdlets for further processing. 20 | 21 | NOTE: PowerShell Core 6.x and PowerShell 7 are supported only for CLI and WSAPI connections. Not supported for PoshSSH Connection. 22 | 23 | **With HPE Alletra 9000 or HPE Primera or HPE 3PAR storage Web Service API (WSAPI 1.6.4 and 1.7)** 24 | 25 | When you run the cmdlets, the following actions take place: 26 | 27 | 1. A secure connection using WSAPI is established as a session key (credential). Unused session keys expire after 15 minutes. 28 | 2. The WSAPI and parameters are formed based on the PowerShell cmdlet and parameters. 29 | 3. The WSAPI uses the HTTPS protocol to enable programmatic management of HPE Alletra 9000 or HPE Primera or HPE 3PAR storage servers and provides client access to web services at specified HTTPS locations. Clients communicate with the WSAPI server using HTTPS methods and data structures represented with JSON. 30 | 4. The output of the cmdlets is returned as PowerShell objects. This output can be piped to other PowerShell cmdlets for search. 31 | 32 | ## Product support 33 | 34 | The HPE Alletra 9000 and Primera and 3PAR PowerShell Toolkit supports PowerShell 3.0 and later up to PowerShell 5.1, PowerShell Core 6.x and PowerShell 7. This Toolkit provides cmdlets to manage the following operations: 35 | 36 | - Views and manages 37 | - Common Provisioning Group (CPG) 38 | - VVols 39 | - Virtual Volume sets 40 | - Hosts 41 | - Host sets 42 | - Virtual Logical Unit Number (vLUN) 43 | - Physical copy 44 | - Virtual copy (Snapshots) 45 | - Ports 46 | - Tasks 47 | - Disk Enclosure 48 | - Performance Management 49 | - Spares 50 | - CIM 51 | - Support for 52 | - System Reporter Cmdlets 53 | - Remote Copy Cmdlets 54 | - Compression-related Cmdlets 55 | - Asynchronous streaming replication 56 | - Deduplication-related Cmdlets 57 | - Storage Federation related Cmdlets 58 | - Smart SAN Enhancements (iSCSI) related Cmdlets. 59 | - Adaptive Optimization (AO) 60 | - Domain Management 61 | - Flash cache 62 | - Health and Alert Management 63 | - Node Subsystem Management 64 | - Service Cmdlets 65 | - CIM Cmdlets 66 | - HPE Primera and HPE 3PAR Web Services API 67 | 68 | ## Supported Host operating systems and PowerShell versions 69 | 70 | HPE Alletra 9000 and Primera and 3PAR PowerShell Toolkit works with PowerShell 3.0 and later up to PowerShell 5.1, PowerShell Core 6.x, and PowerShell 7. You can use this Toolkit in the following environments: 71 | 72 | - Microsoft Windows 2019 73 | - Microsoft Windows Server 2016 74 | - Microsoft Windows Server 2012 R2 75 | - Microsoft Windows Server 2012 76 | - Microsoft Windows Server 2008 R2 SP1 77 | - Microsoft Windows Server 2008 R2 78 | - Microsoft Windows Server 2008 SP1 79 | - Microsoft Windows 10 80 | - Microsoft Windows 8 81 | - Microsoft Windows 7 SP1 82 | - Microsoft Windows 7 83 | 84 | ## Supported Storage Platforms 85 | 86 | **HPE Alletra 9000** 87 | 88 | Supported firmware for HPE Alletra 9000 is 9.3.0 89 | 90 | **HPE Primera 630, 650 and 670 series** 91 | 92 | Supported firmware for HPE Primera are 4.0.0, 4.1.0, 4.2.0 and 4.3.0 93 | 94 | **HPE 3PAR storage 7000, 8000, 9000, 10000, & 20000 series** 95 | 96 | Supported firmware for HPE 3PAR storage are: 97 | 98 | - 3.3.1 (MU1, MU2, MU3, MU4 & MU5) 99 | - 3.3.1 (MU1, MU2, and MU3) 100 | - 3.2.2 (including all MUs) 101 | - 3.2.1 (including all MUs) 102 | 103 | ## PowerShell Toolkit cmdlets Flow 104 | 105 | We can perform the following operations using PowerShell Toolkit CLI cmdlets. 106 | 107 | - Create/Add 108 | - Update/Set 109 | - Delete/Remove 110 | - Get 111 | -------------------------------------------------------------------------------- /WSAPI/AoConfigurationInformation.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: AoConfigurationInformation.psm1 23 | ## Description: AO configuration information cmdlets 24 | ## 25 | ## Created: February 2020 26 | ## Last Modified: February 2020 27 | ## History: v3.0 - Created 28 | ##################################################################################### 29 | 30 | $Info = "INFO:" 31 | $Debug = "DEBUG:" 32 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 33 | 34 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 35 | 36 | 37 | ############################################################################################################################################ 38 | ## FUNCTION Get-AOConfiguration_WSAPI 39 | ############################################################################################################################################ 40 | Function Get-AOConfiguration_WSAPI 41 | { 42 | <# 43 | .SYNOPSIS 44 | Get all or single WSAPI AO configuration information. 45 | 46 | .DESCRIPTION 47 | Get all or single WSAPI AO configuration information. 48 | 49 | .EXAMPLE 50 | Get-AOConfiguration_WSAPI 51 | Get all WSAPI AO configuration information. 52 | 53 | .EXAMPLE 54 | Get-AOConfiguration_WSAPI -AOconfigName XYZ 55 | Get single WSAPI AO configuration information. 56 | 57 | .PARAMETER AOconfigName 58 | AO configuration name. 59 | 60 | .PARAMETER WsapiConnection 61 | WSAPI Connection object created with Connection command 62 | 63 | .Notes 64 | NAME : Get-AOConfiguration_WSAPI 65 | LASTEDIT: February 2020 66 | KEYWORDS: Get-AOConfiguration_WSAPI 67 | 68 | .Link 69 | http://www.hpe.com 70 | 71 | #Requires PS -Version 3.0 72 | 73 | #> 74 | [CmdletBinding()] 75 | Param( 76 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 77 | [System.String] 78 | $AOconfigName, 79 | 80 | [Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)] 81 | $WsapiConnection = $global:WsapiConnection 82 | ) 83 | 84 | Begin 85 | { 86 | #Test if connection exist 87 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 88 | } 89 | 90 | Process 91 | { 92 | $Result = $null 93 | $dataPS = $null 94 | 95 | if($AOconfigName) 96 | { 97 | #Request 98 | $uri = '/aoconfigurations/'+$AOconfigName 99 | 100 | $Result = Invoke-WSAPI -uri $uri -type 'GET' -WsapiConnection $WsapiConnection 101 | if($Result.StatusCode -eq 200) 102 | { 103 | $dataPS = $Result.content | ConvertFrom-Json 104 | } 105 | } 106 | else 107 | { 108 | #Request 109 | 110 | $Result = Invoke-WSAPI -uri '/aoconfigurations' -type 'GET' -WsapiConnection $WsapiConnection 111 | if($Result.StatusCode -eq 200) 112 | { 113 | $dataPS = ($Result.content | ConvertFrom-Json).members 114 | } 115 | } 116 | 117 | if($Result.StatusCode -eq 200) 118 | { 119 | if($dataPS.Count -eq 0) 120 | { 121 | return "No data Fount." 122 | } 123 | write-host "" 124 | write-host "Cmdlet executed successfully" -foreground green 125 | write-host "" 126 | Write-DebugLog "SUCCESS: Command Get-AOConfiguration_WSAPI Successfully Executed" $Info 127 | 128 | return $dataPS 129 | } 130 | else 131 | { 132 | write-host "" 133 | write-host "FAILURE : While Executing Get-AOConfiguration_WSAPI." -foreground red 134 | write-host "" 135 | Write-DebugLog "FAILURE : While Executing Get-AOConfiguration_WSAPI." $Info 136 | 137 | return $Result.StatusDescription 138 | } 139 | } 140 | } 141 | #END Get-AOConfiguration_WSAPI 142 | 143 | 144 | Export-ModuleMember Get-AOConfiguration_WSAPI -------------------------------------------------------------------------------- /CLI/InventoryManagement.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: InventoryManagement.psm1 23 | ## Description: Inventory Management cmdlets 24 | ## 25 | ## Created: January 2020 26 | ## Last Modified: January 2020 27 | ## History: v3.0 - Created 28 | ##################################################################################### 29 | 30 | $Info = "INFO:" 31 | $Debug = "DEBUG:" 32 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 33 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 34 | 35 | ############################################################################################################################################ 36 | ## FUNCTION Test-CLIObject 37 | ############################################################################################################################################ 38 | Function Test-CLIObject 39 | { 40 | Param( 41 | [string]$ObjectType, 42 | [string]$ObjectName , 43 | [string]$ObjectMsg = $ObjectType, 44 | $SANConnection = $global:SANConnection 45 | ) 46 | 47 | $IsObjectExisted = $True 48 | $ObjCmd = $ObjectType -replace ' ', '' 49 | $Cmds = "show$ObjCmd $ObjectName" 50 | 51 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $Cmds 52 | if ($Result -like "no $ObjectMsg listed") 53 | { 54 | $IsObjectExisted = $false 55 | } 56 | return $IsObjectExisted 57 | 58 | } # End FUNCTION Test-CLIObject 59 | 60 | ########################################################################## 61 | ######################### FUNCTION Get-Inventory ##################### 62 | ########################################################################## 63 | Function Get-Inventory() 64 | { 65 | <# 66 | .SYNOPSIS 67 | Get-Inventory - show hardware inventory 68 | 69 | .DESCRIPTION 70 | Shows information about all the hardware components in the system. 71 | 72 | .EXAMPLE 73 | 74 | .PARAMETER Svc 75 | Displays inventory information with HPE serial number, spare part number, 76 | and so on. It is not supported on HPE 3PAR 10000 systems. 77 | 78 | .Notes 79 | NAME: Get-Inventory 80 | LASTEDIT January 2020 81 | KEYWORDS: Get-Inventory 82 | 83 | .Link 84 | http://www.hpe.com 85 | 86 | #Requires PS -Version 3.0 87 | #> 88 | [CmdletBinding()] 89 | param( 90 | [Parameter(Position=0, Mandatory=$false)] 91 | [switch] 92 | $Svc, 93 | 94 | [Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)] 95 | $SANConnection = $global:SANConnection 96 | ) 97 | 98 | Write-DebugLog "Start: In Get-Inventory - validating input values" $Debug 99 | #check if connection object contents are null/empty 100 | if(!$SANConnection) 101 | { 102 | #check if connection object contents are null/empty 103 | $Validate1 = Test-CLIConnection $SANConnection 104 | if($Validate1 -eq "Failed") 105 | { 106 | #check if global connection object contents are null/empty 107 | $Validate2 = Test-CLIConnection $global:SANConnection 108 | if($Validate2 -eq "Failed") 109 | { 110 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" " ERR: " 111 | Write-DebugLog "Stop: Exiting Get-Inventory since SAN connection object values are null/empty" $Debug 112 | Return "Unable to execute the cmdlet Get-Inventory since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 113 | } 114 | } 115 | } 116 | 117 | $plinkresult = Test-PARCli -SANConnection $SANConnection 118 | if($plinkresult -match "FAILURE :") 119 | { 120 | write-debuglog "$plinkresult" 121 | Return $plinkresult 122 | } 123 | 124 | $Cmd = " showinventory " 125 | 126 | if($Svc) 127 | { 128 | $Cmd += " -svc " 129 | } 130 | 131 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $Cmd 132 | Write-DebugLog "Executing Function : Get-Inventory Command -->" INFO: 133 | 134 | Return $Result 135 | } ## End-of Get-Inventory 136 | 137 | 138 | Export-ModuleMember Get-Inventory -------------------------------------------------------------------------------- /WSAPI/SystemEvents.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: SystemEvents.psm1 23 | ## Description: System Events cmdlets 24 | ## 25 | ## Created: February 2020 26 | ## Last Modified: February 2020 27 | ## History: v3.0 - Created 28 | ##################################################################################### 29 | 30 | $Info = "INFO:" 31 | $Debug = "DEBUG:" 32 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 33 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 34 | 35 | ############################################################################################################################################ 36 | ## FUNCTION Open-SSE_WSAPI 37 | ############################################################################################################################################ 38 | Function Open-SSE_WSAPI 39 | { 40 | <# 41 | .SYNOPSIS 42 | Establishing a communication channel for Server-Sent Event (SSE). 43 | 44 | .DESCRIPTION 45 | Establishing a communication channel for Server-Sent Event (SSE) 46 | 47 | .PARAMETER WsapiConnection 48 | WSAPI Connection object created with Connection command 49 | 50 | .EXAMPLE 51 | Open-SSE_WSAPI 52 | 53 | .Notes 54 | NAME : Open-SSE_WSAPI 55 | LASTEDIT: 06/06/2018 56 | KEYWORDS: Open-SSE_WSAPI 57 | 58 | .Link 59 | http://www.hpe.com 60 | 61 | #Requires PS -Version 3.0 62 | 63 | #> 64 | [CmdletBinding()] 65 | Param( 66 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 67 | $WsapiConnection = $global:WsapiConnection 68 | ) 69 | 70 | Begin 71 | { 72 | #Test if connection exist 73 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 74 | } 75 | 76 | Process 77 | { 78 | $Result = $null 79 | $dataPS = $null 80 | 81 | 82 | #Request 83 | 84 | $Result = Invoke-WSAPI -uri '/eventstream' -type 'GET' -WsapiConnection $WsapiConnection 85 | if($Result.StatusCode -eq 200) 86 | { 87 | $dataPS = ($Result.content | ConvertFrom-Json).members 88 | } 89 | 90 | 91 | if($Result.StatusCode -eq 200) 92 | { 93 | write-host "" 94 | write-host "Cmdlet executed successfully" -foreground green 95 | write-host "" 96 | Write-DebugLog "SUCCESS: Command Open-SSE_WSAPI Successfully Executed" $Info 97 | 98 | return $dataPS 99 | } 100 | else 101 | { 102 | write-host "" 103 | write-host "FAILURE : While Executing Open-SSE_WSAPI." -foreground red 104 | write-host "" 105 | Write-DebugLog "FAILURE : While Executing Open-SSE_WSAPI." $Info 106 | 107 | return $Result.StatusDescription 108 | } 109 | } 110 | } 111 | #END Open-SSE_WSAPI 112 | 113 | ############################################################################################################################################ 114 | ## FUNCTION Get-EventLogs_WSAPI 115 | ############################################################################################################################################ 116 | Function Get-EventLogs_WSAPI 117 | { 118 | <# 119 | 120 | .SYNOPSIS 121 | Get all past events from system event logs or a logged event information for the available resources. 122 | 123 | .DESCRIPTION 124 | Get all past events from system event logs or a logged event information for the available resources. 125 | 126 | .EXAMPLE 127 | Get-EventLogs_WSAPI 128 | 129 | .PARAMETER WsapiConnection 130 | WSAPI Connection object created with Connection command 131 | 132 | .Notes 133 | NAME : Get-EventLogs_WSAPI 134 | LASTEDIT: 20/02/2018 135 | KEYWORDS: Get-EventLogs_WSAPI 136 | 137 | .Link 138 | http://www.hpe.com 139 | 140 | #Requires PS -Version 3.0 141 | 142 | #> 143 | [CmdletBinding()] 144 | Param( 145 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 146 | $WsapiConnection = $global:WsapiConnection 147 | ) 148 | 149 | Begin 150 | { 151 | #Test if connection exist 152 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 153 | } 154 | 155 | Process 156 | { 157 | $Result = $null 158 | $dataPS = $null 159 | 160 | 161 | #Request 162 | 163 | $Result = Invoke-WSAPI -uri '/eventlog' -type 'GET' -WsapiConnection $WsapiConnection 164 | if($Result.StatusCode -eq 200) 165 | { 166 | $dataPS = ($Result.content | ConvertFrom-Json).members 167 | } 168 | 169 | 170 | if($Result.StatusCode -eq 200) 171 | { 172 | write-host "" 173 | write-host "Cmdlet executed successfully" -foreground green 174 | write-host "" 175 | Write-DebugLog "SUCCESS: Command Get-EventLogs_WSAPI Successfully Executed" $Info 176 | 177 | return $dataPS 178 | } 179 | else 180 | { 181 | write-host "" 182 | write-host "FAILURE : While Executing Get-EventLogs_WSAPI." -foreground red 183 | write-host "" 184 | Write-DebugLog "FAILURE : While Executing Get-EventLogs_WSAPI." $Info 185 | 186 | return $Result.StatusDescription 187 | } 188 | } 189 | } 190 | #END Get-EventLogs_WSAPI 191 | 192 | Export-ModuleMember Open-SSE_WSAPI , Get-EventLogs_WSAPI -------------------------------------------------------------------------------- /HPEStoragePowerShellToolkit.psd1: -------------------------------------------------------------------------------- 1 | # 2 | # Module manifest for module 'HPEStoragePowerShellToolkit' 3 | # 4 | # Generated by: Hewlett Packard Enterprise Development LP 5 | # 6 | # Generated on: 10-06-2021 7 | # 8 | 9 | @{ 10 | 11 | # Script module or binary module file associated with this manifest. 12 | # RootModule = '' 13 | 14 | # Version number of this module. 15 | ModuleVersion = '3.1.0.0' 16 | 17 | # Supported PSEditions 18 | # CompatiblePSEditions = @() 19 | 20 | # ID used to uniquely identify this module 21 | GUID = '46a7e8f6-729c-45d0-b979-96c684fb28fe' 22 | 23 | # Author of this module 24 | Author = 'Hewlett Packard Enterprise Development LP' 25 | 26 | # Company or vendor of this module 27 | CompanyName = 'Hewlett Packard Enterprise Development LP' 28 | 29 | # Copyright statement for this module 30 | Copyright = '© 2020,2021 Hewlett Packard Enterprise Development LP' 31 | 32 | # Description of the functionality provided by this module 33 | Description = 'HPE Alletra 9000 and Primera and 3PAR PowerShell Toolkit provides storage administrators the convenience of managing HPE Alletra 9000 and HPE Primera and HPE 3PAR Storage Systems from a Microsoft Windows PowerShell environment.' 34 | 35 | # Minimum version of the Windows PowerShell engine required by this module 36 | PowerShellVersion = '3.0' 37 | 38 | # Name of the Windows PowerShell host required by this module 39 | # PowerShellHostName = '' 40 | 41 | # Minimum version of the Windows PowerShell host required by this module 42 | # PowerShellHostVersion = '' 43 | 44 | # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. 45 | # DotNetFrameworkVersion = '' 46 | 47 | # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. 48 | # CLRVersion = '' 49 | 50 | # Processor architecture (None, X86, Amd64) required by this module 51 | # ProcessorArchitecture = '' 52 | 53 | # Modules that must be imported into the global environment prior to importing this module 54 | # RequiredModules = @() 55 | 56 | # Assemblies that must be loaded prior to importing this module 57 | # RequiredAssemblies = @() 58 | 59 | # Script files (.ps1) that are run in the caller's environment prior to importing this module. 60 | # ScriptsToProcess = @() 61 | 62 | # Type files (.ps1xml) to be loaded when importing this module 63 | # TypesToProcess = @() 64 | 65 | # Format files (.ps1xml) to be loaded when importing this module 66 | # FormatsToProcess = @() 67 | 68 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 69 | NestedModules = @('.\GLOBAL\VS-Functions.psm1', 70 | '.\GLOBAL\Logger.psm1', 71 | '.\CLI\AdaptiveOptimization.psm1', 72 | '.\CLI\ConfigWebServicesAPI.psm1', 73 | '.\CLI\CPGManagement.psm1', 74 | '.\CLI\DiskEnclosureManagement.psm1', 75 | '.\CLI\DomainManagement.psm1', 76 | '.\CLI\FilePersonaManagement.psm1', 77 | '.\CLI\Flashcache.psm1', 78 | '.\CLI\HealthAndAlertManagement.psm1', 79 | '.\CLI\HostManagement.psm1', 80 | '.\CLI\Internal.psm1', 81 | '.\CLI\InventoryManagement.psm1', 82 | '.\CLI\MaintenanceMode.psm1', 83 | '.\CLI\NodeSubsystemManagement.psm1', 84 | '.\CLI\PerformanceManagement.psm1', 85 | '.\CLI\Replication.psm1', 86 | '.\CLI\ServiceCommands.psm1', 87 | '.\CLI\SnapShotManagement.psm1', 88 | '.\CLI\Sparing.psm1', 89 | '.\CLI\SystemManager.psm1', 90 | '.\CLI\SystemReporter.psm1', 91 | '.\CLI\TaskManagement.psm1', 92 | '.\CLI\CimManagement.psm1', 93 | '.\CLI\UserManagement.psm1', 94 | '.\CLI\Vasa.psm1', 95 | '.\CLI\StorageFederation.psm1', 96 | '.\CLI\VirtualVolumeManagement.psm1', 97 | '.\CLI\vLunManagement.psm1', 98 | '.\WSAPI\AoConfigurationInformation.psm1', 99 | '.\WSAPI\AvailableSpace.psm1', 100 | '.\WSAPI\CopyOperations.psm1', 101 | '.\WSAPI\CpgManagement.psm1', 102 | '.\WSAPI\FilePersona.psm1', 103 | '.\WSAPI\FlashCacheOperations.psm1', 104 | '.\WSAPI\HostManagement.psm1', 105 | '.\WSAPI\HostSetsAndVirtualVolumeSets.psm1', 106 | '.\WSAPI\PortsAndSwitches.psm1', 107 | '.\WSAPI\RemoteCopy.psm1', 108 | '.\WSAPI\SessionKeysAndWsapiSystemAccess.psm1', 109 | '.\WSAPI\StorageVolumes.psm1', 110 | '.\WSAPI\SystemEvents.psm1', 111 | '.\WSAPI\SystemInformationQueriesAndManagement.psm1', 112 | '.\WSAPI\SystemReporter.psm1', 113 | '.\WSAPI\VirtualLUNs.psm1', 114 | '.\WSAPI\WsapiUserAndRoleInformation.psm1') 115 | 116 | # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. 117 | FunctionsToExport = '*' 118 | 119 | # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. 120 | CmdletsToExport = '*' 121 | 122 | # Variables to export from this module 123 | VariablesToExport = '*' 124 | 125 | # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. 126 | AliasesToExport = '*' 127 | 128 | # DSC resources to export from this module 129 | # DscResourcesToExport = @() 130 | 131 | # List of all modules packaged with this module 132 | # ModuleList = @() 133 | 134 | # List of all files packaged with this module 135 | # FileList = @() 136 | 137 | # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. 138 | PrivateData = @{ 139 | 140 | PSData = @{ 141 | 142 | # Tags applied to this module. These help with module discovery in online galleries. 143 | Tags = 'HPE Alletra PS Cmdlets', 'HPE Primera PS Cmdlets', 'HPE 3PAR PS Cmdlets', 'HPE Alletra CLI', 'HPE Primera CLI', 144 | 'HPE 3PAR CLI', 'HPE Alletra WSAPI', 'HPE Primera WSAPI', 'HPE 3PAR WSAPI', '3PAR PSTK', 145 | 'PRIMERA PSTK', 'ALLETRA PSTK' 146 | 147 | # A URL to the license for this module. 148 | # LicenseUri = 'https://github.com/HewlettPackard/hpe3par_pstoolkit/blob/master/LICENSE.txt' 149 | 150 | # A URL to the main website for this project. 151 | # ProjectUri = '' 152 | 153 | # A URL to an icon representing this module. 154 | # IconUri = '' 155 | 156 | # ReleaseNotes of this module 157 | # ReleaseNotes = '' 158 | 159 | } # End of PSData hashtable 160 | 161 | } # End of PrivateData hashtable 162 | 163 | # HelpInfo URI of this module 164 | # HelpInfoURI = '' 165 | 166 | # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. 167 | # DefaultCommandPrefix = '' 168 | } 169 | 170 | -------------------------------------------------------------------------------- /WSAPI/WsapiUserAndRoleInformation.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: WsapiUserAndRoleInformation.psm1 23 | ## Description: WSAPI user and role information cmdlets 24 | ## 25 | ## Created: February 2020 26 | ## Last Modified: February 2020 27 | ## History: v3.0 - Created 28 | ##################################################################################### 29 | 30 | $Info = "INFO:" 31 | $Debug = "DEBUG:" 32 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 33 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 34 | 35 | ############################################################################################################################################ 36 | ## FUNCTION Get-Users_WSAPI 37 | ############################################################################################################################################ 38 | Function Get-Users_WSAPI 39 | { 40 | <# 41 | .SYNOPSIS 42 | Get all or single WSAPI users information. 43 | 44 | .DESCRIPTION 45 | Get all or single WSAPI users information. 46 | 47 | .EXAMPLE 48 | Get-Users_WSAPI 49 | Get all WSAPI users information. 50 | 51 | .EXAMPLE 52 | Get-Users_WSAPI -UserName XYZ 53 | Get single WSAPI users information. 54 | 55 | .PARAMETER UserName 56 | Name Of The User. 57 | 58 | .PARAMETER WsapiConnection 59 | WSAPI Connection object created with Connection command 60 | 61 | .Notes 62 | NAME : Get-Users_WSAPI 63 | LASTEDIT: February 2020 64 | KEYWORDS: Get-Users_WSAPI 65 | 66 | .Link 67 | http://www.hpe.com 68 | 69 | #Requires PS -Version 3.0 70 | 71 | #> 72 | [CmdletBinding()] 73 | Param( 74 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 75 | [System.String] 76 | $UserName, 77 | 78 | [Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)] 79 | $WsapiConnection = $global:WsapiConnection 80 | ) 81 | 82 | Begin 83 | { 84 | #Test if connection exist 85 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 86 | } 87 | 88 | Process 89 | { 90 | $Result = $null 91 | $dataPS = $null 92 | 93 | if($UserName) 94 | { 95 | #Request 96 | $uri = '/users/'+$UserName 97 | 98 | $Result = Invoke-WSAPI -uri $uri -type 'GET' -WsapiConnection $WsapiConnection 99 | if($Result.StatusCode -eq 200) 100 | { 101 | $dataPS = $Result.content | ConvertFrom-Json 102 | } 103 | } 104 | else 105 | { 106 | #Request 107 | 108 | $Result = Invoke-WSAPI -uri '/users' -type 'GET' -WsapiConnection $WsapiConnection 109 | if($Result.StatusCode -eq 200) 110 | { 111 | $dataPS = ($Result.content | ConvertFrom-Json).members 112 | } 113 | } 114 | 115 | if($Result.StatusCode -eq 200) 116 | { 117 | if($dataPS.Count -eq 0) 118 | { 119 | return "No data Fount." 120 | } 121 | write-host "" 122 | write-host "Cmdlet executed successfully" -foreground green 123 | write-host "" 124 | Write-DebugLog "SUCCESS: Command Get-Users_WSAPI Successfully Executed" $Info 125 | 126 | return $dataPS 127 | } 128 | else 129 | { 130 | write-host "" 131 | write-host "FAILURE : While Executing Get-Users_WSAPI." -foreground red 132 | write-host "" 133 | Write-DebugLog "FAILURE : While Executing Get-Users_WSAPI." $Info 134 | 135 | return $Result.StatusDescription 136 | } 137 | } 138 | } 139 | #END Get-Users_WSAPI 140 | 141 | ############################################################################################################################################ 142 | ## FUNCTION Get-Roles_WSAPI 143 | ############################################################################################################################################ 144 | Function Get-Roles_WSAPI 145 | { 146 | <# 147 | .SYNOPSIS 148 | Get all or single WSAPI role information. 149 | 150 | .DESCRIPTION 151 | Get all or single WSAPI role information. 152 | 153 | .EXAMPLE 154 | Get-Roles_WSAPI 155 | Get all WSAPI role information. 156 | 157 | .EXAMPLE 158 | Get-Roles_WSAPI -RoleName XYZ 159 | Get single WSAPI role information. 160 | 161 | .PARAMETER WsapiConnection 162 | Name of the Role. 163 | 164 | .PARAMETER WsapiConnection 165 | WSAPI Connection object created with Connection command 166 | 167 | .Notes 168 | NAME : Get-Roles_WSAPI 169 | LASTEDIT: February 2020 170 | KEYWORDS: Get-Roles_WSAPI 171 | 172 | .Link 173 | http://www.hpe.com 174 | 175 | #Requires PS -Version 3.0 176 | 177 | #> 178 | [CmdletBinding()] 179 | Param( 180 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 181 | [System.String] 182 | $RoleName, 183 | 184 | [Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)] 185 | $WsapiConnection = $global:WsapiConnection 186 | ) 187 | 188 | Begin 189 | { 190 | #Test if connection exist 191 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 192 | } 193 | 194 | Process 195 | { 196 | $Result = $null 197 | $dataPS = $null 198 | 199 | if($RoleName) 200 | { 201 | #Request 202 | $uri = '/roles/'+$RoleName 203 | 204 | $Result = Invoke-WSAPI -uri $uri -type 'GET' -WsapiConnection $WsapiConnection 205 | if($Result.StatusCode -eq 200) 206 | { 207 | $dataPS = $Result.content | ConvertFrom-Json 208 | } 209 | } 210 | else 211 | { 212 | #Request 213 | 214 | $Result = Invoke-WSAPI -uri '/roles' -type 'GET' -WsapiConnection $WsapiConnection 215 | if($Result.StatusCode -eq 200) 216 | { 217 | $dataPS = ($Result.content | ConvertFrom-Json).members 218 | } 219 | } 220 | 221 | if($Result.StatusCode -eq 200) 222 | { 223 | if($dataPS.Count -eq 0) 224 | { 225 | return "No data Fount." 226 | } 227 | write-host "" 228 | write-host "Cmdlet executed successfully" -foreground green 229 | write-host "" 230 | Write-DebugLog "SUCCESS: Command Get-Roles_WSAPI Successfully Executed" $Info 231 | 232 | return $dataPS 233 | } 234 | else 235 | { 236 | write-host "" 237 | write-host "FAILURE : While Executing Get-Roles_WSAPI." -foreground red 238 | write-host "" 239 | Write-DebugLog "FAILURE : While Executing Get-Roles_WSAPI." $Info 240 | 241 | return $Result.StatusDescription 242 | } 243 | } 244 | } 245 | #END Get-Roles_WSAPI 246 | 247 | 248 | Export-ModuleMember Get-Users_WSAPI , Get-Roles_WSAPI -------------------------------------------------------------------------------- /CLI/FilePersonaManagement.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: FilePersonaManagement.psm1 23 | ## Description: File Persona Management cmdlets 24 | ## 25 | ## Created: November 2019 26 | ## Last Modified: November 2019 27 | ## History: v3.0 - Created 28 | ##################################################################################### 29 | 30 | $Info = "INFO:" 31 | $Debug = "DEBUG:" 32 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 33 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 34 | 35 | ############################################################################################################################################ 36 | ## FUNCTION Test-CLIObject 37 | ############################################################################################################################################ 38 | Function Test-CLIObject 39 | { 40 | Param( 41 | [string]$ObjectType, 42 | [string]$ObjectName , 43 | [string]$ObjectMsg = $ObjectType, 44 | $SANConnection = $global:SANConnection 45 | ) 46 | 47 | $IsObjectExisted = $True 48 | $ObjCmd = $ObjectType -replace ' ', '' 49 | $Cmds = "show$ObjCmd $ObjectName" 50 | 51 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $Cmds 52 | if ($Result -like "no $ObjectMsg listed") 53 | { 54 | $IsObjectExisted = $false 55 | } 56 | return $IsObjectExisted 57 | 58 | } # End FUNCTION Test-CLIObject 59 | 60 | #################################################################################################################### 61 | ########################################### FUNCTION Start-FSNDMP ############################################## 62 | #################################################################################################################### 63 | Function Start-FSNDMP 64 | { 65 | <# 66 | .SYNOPSIS 67 | The Start-FSNDMP command is used to start both NDMP service and ISCSI 68 | service. 69 | 70 | .DESCRIPTION 71 | The Start-FSNDMP command is used to start both NDMP service and ISCSI 72 | service. 73 | 74 | .EXAMPLE 75 | Start-FSNDMP 76 | 77 | .PARAMETER SANConnection 78 | Specify the SAN Connection object created with New-CLIConnection or New-PoshSshConnection 79 | 80 | .Notes 81 | NAME: Start-FSNDMP 82 | LASTEDIT: 19/11/2019 83 | KEYWORDS: Start-FSNDMP 84 | 85 | .Link 86 | http://www.hpe.com 87 | 88 | #Requires PS -Version 3.0 89 | #> 90 | [CmdletBinding()] 91 | param( 92 | 93 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 94 | $SANConnection = $global:SANConnection 95 | 96 | ) 97 | Write-DebugLog "Start: In Start-FSNDMP - validating input values" $Debug 98 | #check if connection object contents are null/empty 99 | if(!$SANConnection) 100 | { 101 | 102 | #check if connection object contents are null/empty 103 | $Validate1 = Test-CLIConnection $SANConnection 104 | if($Validate1 -eq "Failed") 105 | { 106 | #check if global connection object contents are null/empty 107 | $Validate2 = Test-CLIConnection $global:SANConnection 108 | if($Validate2 -eq "Failed") 109 | { 110 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" "ERR:" 111 | Write-DebugLog "Stop: Exiting Start-FSNDMP since SAN connection object values are null/empty" $Debug 112 | return "Unable to execute the cmdlet Start-FSNDMP since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 113 | } 114 | } 115 | } 116 | $plinkresult = Test-PARCli 117 | if($plinkresult -match "FAILURE :") 118 | { 119 | write-debuglog "$plinkresult" "ERR:" 120 | return $plinkresult 121 | } 122 | $cmd= "startfsndmp " 123 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $cmd 124 | write-debuglog " Executing Start-FSNDMP command that displays information iSNS table for iSCSI ports in the system " "INFO:" 125 | write-host "" 126 | Return $Result 127 | 128 | } # End Start-FSNDMP 129 | 130 | #################################################################################################################### 131 | ################################################ FUNCTION Stop-FSNDMP ############################################## 132 | #################################################################################################################### 133 | Function Stop-FSNDMP 134 | { 135 | <# 136 | .SYNOPSIS 137 | The Stop-FSNDMP command is used to stop both NDMP service and ISCSI 138 | service. 139 | 140 | .DESCRIPTION 141 | The Stop-FSNDMP command is used to stop both NDMP service and ISCSI 142 | service. 143 | 144 | .EXAMPLE 145 | Stop-FSNDMP 146 | 147 | .PARAMETER SANConnection 148 | Specify the SAN Connection object created with New-CLIConnection or New-PoshSshConnection 149 | 150 | .Notes 151 | NAME: Stop-FSNDMP 152 | LASTEDIT: 19/11/2019 153 | KEYWORDS: Stop-FSNDMP 154 | 155 | .Link 156 | http://www.hpe.com 157 | 158 | #Requires PS -Version 3.0 159 | #> 160 | [CmdletBinding()] 161 | param( 162 | 163 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 164 | $SANConnection = $global:SANConnection 165 | 166 | ) 167 | Write-DebugLog "Start: In Stop-FSNDMP - validating input values" $Debug 168 | #check if connection object contents are null/empty 169 | if(!$SANConnection) 170 | { 171 | 172 | #check if connection object contents are null/empty 173 | $Validate1 = Test-CLIConnection $SANConnection 174 | if($Validate1 -eq "Failed") 175 | { 176 | #check if global connection object contents are null/empty 177 | $Validate2 = Test-CLIConnection $global:SANConnection 178 | if($Validate2 -eq "Failed") 179 | { 180 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" "ERR:" 181 | Write-DebugLog "Stop: Exiting Stop-FSNDMP since SAN connection object values are null/empty" $Debug 182 | return "Unable to execute the cmdlet Stop-FSNDMP since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 183 | } 184 | } 185 | } 186 | 187 | $plinkresult = Test-PARCli 188 | if($plinkresult -match "FAILURE :") 189 | { 190 | write-debuglog "$plinkresult" "ERR:" 191 | return $plinkresult 192 | } 193 | 194 | $cmd= "stopfsndmp " 195 | 196 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $cmd 197 | 198 | write-debuglog " Executing Stop-FSNDMP command that displays information iSNS table for iSCSI ports in the system " "INFO:" 199 | write-host "" 200 | return $Result 201 | 202 | } # End Stop-FSNDMP 203 | 204 | 205 | Export-ModuleMember Start-FSNDMP , Stop-FSNDMP -------------------------------------------------------------------------------- /CLI/UserManagement.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: UserManagement.psm1 23 | ## Description: User Management cmdlets 24 | ## 25 | ## Created: January 2020 26 | ## Last Modified: January 2020 27 | ## History: v3.0 - Created 28 | ##################################################################################### 29 | 30 | $Info = "INFO:" 31 | $Debug = "DEBUG:" 32 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 33 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 34 | 35 | ############################################################################################################################################ 36 | ## FUNCTION Test-CLIObject 37 | ############################################################################################################################################ 38 | Function Test-CLIObject 39 | { 40 | Param( 41 | [string]$ObjectType, 42 | [string]$ObjectName , 43 | [string]$ObjectMsg = $ObjectType, 44 | $SANConnection = $global:SANConnection 45 | ) 46 | 47 | $IsObjectExisted = $True 48 | $ObjCmd = $ObjectType -replace ' ', '' 49 | $Cmds = "show$ObjCmd $ObjectName" 50 | 51 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $Cmds 52 | if ($Result -like "no $ObjectMsg listed") 53 | { 54 | $IsObjectExisted = $false 55 | } 56 | return $IsObjectExisted 57 | 58 | } # End FUNCTION Test-CLIObject 59 | 60 | ###################################################################################### 61 | ################################## FUNCTION Get-UserConnection ####################### 62 | ###################################################################################### 63 | Function Get-UserConnection{ 64 | <# 65 | .SYNOPSIS 66 | Displays information about users who are currently connected (logged in) to the storage system. 67 | 68 | .DESCRIPTION 69 | Displays information about users who are currently connected (logged in) to the storage system. 70 | 71 | .EXAMPLE 72 | Get-UserConnection 73 | Shows information about users who are currently connected (logged in) to the storage system. 74 | 75 | .EXAMPLE 76 | Get-UserConnection -Current 77 | Shows all information about the current connection only. 78 | 79 | .EXAMPLE 80 | Get-UserConnection -Detailed 81 | Specifies the more detailed information about the user connection 82 | 83 | .PARAMETER Current 84 | Shows all information about the current connection only. 85 | 86 | .PARAMETER Detailed 87 | Specifies the more detailed information about the user connection. 88 | 89 | .PARAMETER SANConnection 90 | Specify the SAN Connection object created with New-PoshSshConnection or New-CLIConnection 91 | 92 | .Notes 93 | NAME: Get-UserConnection 94 | LASTEDIT: January 2020 95 | KEYWORDS: Get-UserConnection 96 | 97 | .Link 98 | http://www.hpe.com 99 | 100 | #Requires PS -Version 3.0 101 | #Requires HPE 3par cli.exe 102 | #> 103 | 104 | [CmdletBinding()] 105 | param( 106 | [Parameter(Position=0,Mandatory=$false, ValueFromPipeline=$true)] 107 | [switch] 108 | $Current , 109 | 110 | [Parameter(Position=1,Mandatory=$false, ValueFromPipeline=$true)] 111 | [switch] 112 | $Detailed , 113 | 114 | [Parameter(Position=2, Mandatory=$false, ValueFromPipeline=$true)] 115 | $SANConnection = $global:SANConnection 116 | 117 | ) 118 | Write-DebugLog "Start: In Get-UserConnection - validating input values" $Debug 119 | #check if connection object contents are null/empty 120 | if(!$SANConnection) 121 | { 122 | #check if connection object contents are null/empty 123 | $Validate1 = Test-CLIConnection $SANConnection 124 | if($Validate1 -eq "Failed") 125 | { 126 | #check if global connection object contents are null/empty 127 | $Validate2 = Test-CLIConnection $global:SANConnection 128 | if($Validate2 -eq "Failed") 129 | { 130 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" "ERR:" 131 | Write-DebugLog "Stop: Exiting Get-UserConnection since SAN connection object values are null/empty" $Debug 132 | return "Unable to execute the cmdlet Get-UserConnection since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 133 | } 134 | } 135 | } 136 | $cliresult1 = Test-PARCli -SANConnection $SANConnection 137 | if(($cliresult1 -match "FAILURE :")) 138 | { 139 | write-debuglog "$cliresult1" "ERR:" 140 | return $cliresult1 141 | } 142 | $cmd2 = "showuserconn " 143 | 144 | if ($Current) 145 | { 146 | $cmd2 += " -current " 147 | } 148 | if($Detailed) 149 | { 150 | $cmd2 += " -d " 151 | $result = Invoke-CLICommand -Connection $SANConnection -cmds $cmd2 152 | return $result 153 | } 154 | $result = Invoke-CLICommand -Connection $SANConnection -cmds $cmd2 155 | $count = $result.count - 3 156 | $tempFile = [IO.Path]::GetTempFileName() 157 | Add-Content -Path $tempFile -Value "Id,Name,IP_Addr,Role,Connected_since_Date,Connected_since_Time,Connected_since_TimeZone,Current,Client,ClientName" 158 | foreach($s in $result[1..$count]) 159 | { 160 | $s= [regex]::Replace($s,"^ +","") 161 | $s= [regex]::Replace($s," +"," ") 162 | $s= [regex]::Replace($s," ",",") 163 | $s = $s.trim() 164 | Add-Content -Path $tempFile -Value $s 165 | } 166 | Import-CSV $tempFile 167 | del $tempFile 168 | } #End Get-UserConnection 169 | 170 | ################################################################################# 171 | ########################## FUNCTION Set-Password ################################ 172 | ################################################################################# 173 | Function Set-Password 174 | { 175 | <# 176 | .SYNOPSIS 177 | Creates a encrypted password file on client machine 178 | 179 | .DESCRIPTION 180 | Creates a encrypted password file on client machine 181 | 182 | .EXAMPLE 183 | Set-Password -CLIDir "C:\Program Files (x86)\Hewlett Packard Enterprise\HPE 3PAR CLI\bin" -ArrayNameOrIPAddress "15.212.196.218" -epwdFile "C:\HPE3paradmepwd.txt" 184 | This examples stores the encrypted password file HPE3paradmepwd.txt on client machine c:\ drive, subsequent commands uses this encryped password file 185 | 186 | .PARAMETER ArrayNameOrIPAddress 187 | Specify the SAN IP address. 188 | 189 | .PARAMETER CLIDir 190 | Specify the absolute path of HPE 3par cli.exe. Default is "C:\Program Files (x86)\Hewlett Packard Enterprise\HPE 3PAR CLI\bin" 191 | 192 | .PARAMETER epwdFile 193 | Specify the file location to create encrypted password file 194 | 195 | .Notes 196 | NAME: Set-Password 197 | LASTEDIT: January 2020 198 | KEYWORDS: Set-Password 199 | 200 | .Link 201 | http://www.hpe.com 202 | 203 | #Requires PS -Version 3.0 204 | #Requires HPE 3par cli.exe 205 | #> 206 | 207 | [CmdletBinding()] 208 | param( 209 | [Parameter(Position=0,Mandatory=$false, ValueFromPipeline=$true)] 210 | [System.string] 211 | $CLIDir="C:\Program Files (x86)\Hewlett Packard Enterprise\HPE 3PAR CLI\bin", 212 | [Parameter(Position=1,Mandatory=$true, ValueFromPipeline=$true)] 213 | [System.string] 214 | $ArrayNameOrIPAddress=$null, 215 | [Parameter(Position=2,Mandatory=$true, ValueFromPipeline=$true)] 216 | [System.string] 217 | $epwdFile ="C:\HPE3parepwdlogin.txt" 218 | 219 | ) 220 | #write-host "In connection" 221 | if( Test-Path $epwdFile) 222 | { 223 | Write-DebugLog "Running: Encrypted password file found. It will be overwritten" "INFO:" 224 | } 225 | $passwordFile = $epwdFile 226 | $cmd1 = $CLIDir+"\setpassword.bat" 227 | & $cmd1 -saveonly -sys $ArrayNameOrIPAddress -file $passwordFile 228 | if(!($? )) 229 | { 230 | Write-DebugLog "STOP: CLI directory path not founf or system is not accessible or the commands.bat file path not configured properly " "ERR:" 231 | return "`nFailure : FATAL ERROR" 232 | } 233 | #$cmd2 = "setpassword.bat -saveonly -sys $ArrayNameOrIPAddress -file $passwordFile" 234 | #Invoke-expression $cmd2 235 | $global:epwdFile = $passwordFile 236 | Write-DebugLog "Running: The encrypted password file is successfully created and the file is located in $passwordfile " "INFO:" 237 | return "Success : The encrypted password file is successfully created and the file is located in $passwordfile " 238 | 239 | } #End Set-Password 240 | 241 | Export-ModuleMember Get-UserConnection , Set-Password -------------------------------------------------------------------------------- /CLI/Flashcache.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: Flashcache.psm1 23 | ## Description: Flash cache cmdlets 24 | ## 25 | ## Created: November 2019 26 | ## Last Modified: November 2019 27 | ## History: v3.0 - Created 28 | ##################################################################################### 29 | 30 | $Info = "INFO:" 31 | $Debug = "DEBUG:" 32 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 33 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 34 | 35 | ############################################################################################################################################ 36 | ## FUNCTION Test-CLIObject 37 | ############################################################################################################################################ 38 | Function Test-CLIObject 39 | { 40 | Param( 41 | [string]$ObjectType, 42 | [string]$ObjectName , 43 | [string]$ObjectMsg = $ObjectType, 44 | $SANConnection = $global:SANConnection 45 | ) 46 | 47 | $IsObjectExisted = $True 48 | $ObjCmd = $ObjectType -replace ' ', '' 49 | $Cmds = "show$ObjCmd $ObjectName" 50 | 51 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $Cmds 52 | if ($Result -like "no $ObjectMsg listed") 53 | { 54 | $IsObjectExisted = $false 55 | } 56 | return $IsObjectExisted 57 | 58 | } # End FUNCTION Test-CLIObject 59 | 60 | ########################################################################## 61 | ######################### FUNCTION New-FlashCache #################### 62 | ########################################################################## 63 | Function New-FlashCache() 64 | { 65 | <# 66 | .SYNOPSIS 67 | New-FlashCache - Creates flash cache for the cluster. 68 | 69 | .DESCRIPTION 70 | The New-FlashCache command creates flash cache of for each node pair. The flash cache will be created from SSD drives. 71 | 72 | .EXAMPLE 73 | 74 | .PARAMETER Sim 75 | Specifies that the Adaptive Flash Cache will be run in simulator mode. The simulator mode does not require the use of SSD drives. 76 | 77 | .PARAMETER RAIDType 78 | Specifies the RAID type of the logical disks for Flash Cache; r0 for RAID-0 or r1 for RAID-1. If no RAID type is specified, the default is chosen by the storage system. 79 | 80 | .PARAMETER Size 81 | Specifies the size for the flash cache in MiB for each node pair. The flashcache size should be a multiple of 16384 (16GiB), and be an integer. 82 | The minimum size of the flash cache is 64GiB. The maximum size of the flash cache is based on the node types, ranging from 768GiB up to 12288GiB (12TiB). 83 | An optional suffix (with no whitespace before the suffix) will modify the units to GiB (g or G suffix) or TiB (t or T suffix). 84 | 85 | .Notes 86 | NAME: New-FlashCache 87 | LASTEDIT 19/11/2019 88 | KEYWORDS: New-FlashCache 89 | 90 | .Link 91 | http://www.hpe.com 92 | 93 | #Requires PS -Version 3.0 94 | #> 95 | [CmdletBinding()] 96 | param( 97 | [Parameter(Position=0, Mandatory=$false , ValueFromPipeline=$true)] 98 | [switch] 99 | $Sim, 100 | 101 | [Parameter(Position=1, Mandatory=$false , ValueFromPipeline=$true)] 102 | [System.String] 103 | $RAIDType, 104 | 105 | [Parameter(Position=2, Mandatory=$true , ValueFromPipeline=$true)] 106 | [System.String] 107 | $Size, 108 | 109 | [Parameter(Position=3, Mandatory=$false, ValueFromPipeline=$true)] 110 | $SANConnection = $global:SANConnection 111 | ) 112 | 113 | Write-DebugLog "Start: In New-FlashCache - validating input values" $Debug 114 | #check if connection object contents are null/empty 115 | if(!$SANConnection) 116 | { 117 | #check if connection object contents are null/empty 118 | $Validate1 = Test-CLIConnection $SANConnection 119 | if($Validate1 -eq "Failed") 120 | { 121 | #check if global connection object contents are null/empty 122 | $Validate2 = Test-CLIConnection $global:SANConnection 123 | if($Validate2 -eq "Failed") 124 | { 125 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" " ERR: " 126 | Write-DebugLog "Stop: Exiting New-FlashCache since SAN connection object values are null/empty" $Debug 127 | Return "Unable to execute the cmdlet New-FlashCache since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 128 | } 129 | } 130 | } 131 | 132 | $plinkresult = Test-PARCli -SANConnection $SANConnection 133 | if($plinkresult -match "FAILURE :") 134 | { 135 | write-debuglog "$plinkresult" 136 | Return $plinkresult 137 | } 138 | 139 | $Cmd = " createflashcache " 140 | 141 | if($Sim) 142 | { 143 | $Cmd += " -sim " 144 | } 145 | 146 | if($RAIDType) 147 | { 148 | $Cmd += " -t $RAIDType " 149 | } 150 | 151 | if($Size) 152 | { 153 | $Cmd += " $Size " 154 | } 155 | 156 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $Cmd 157 | Write-DebugLog "Executing Function : New-FlashCache Command -->" INFO: 158 | 159 | Return $Result 160 | } ## End-of New-FlashCache 161 | 162 | 163 | ########################################################################## 164 | ######################### FUNCTION Set-FlashCache #################### 165 | ########################################################################## 166 | Function Set-FlashCache() 167 | { 168 | <# 169 | .SYNOPSIS 170 | Set-FlashCache - Sets the flash cache policy for virtual volumes 171 | 172 | .DESCRIPTION 173 | The Set-FlashCache command allows you to set the policy of the flash cache for virtual volumes. The policy is set by using virtual volume sets(vvset). 174 | The sys:all is used to enable the policy on all virtual volumes in the system. 175 | 176 | .EXAMPLE 177 | Set-FlashCache 178 | 179 | .PARAMETER Enable 180 | Will turn on the flash cache policy for the target object. 181 | 182 | .PARAMETER Disable 183 | Will turn off flash cache policy for the target object. 184 | 185 | .PARAMETER Clear 186 | Will turn off policy and can only be issued against the sys:all target. 187 | 188 | .PARAMETER vvSet 189 | vvSet refers to the target object name as listed in the showvvset command. Pattern is glob-style (shell-style) patterns (see help on sub,globpat). 190 | Note(set Name Should de is the same formate Ex: vvset:vvset1 ) 191 | 192 | .PARAMETER All 193 | The policy is applied to all virtual volumes. 194 | 195 | .Notes 196 | NAME: Set-FlashCache 197 | LASTEDIT 19/11/2019 198 | KEYWORDS: 3parVersion 199 | 200 | .Link 201 | http://www.hpe.com 202 | 203 | #Requires PS -Version 3.0 204 | #> 205 | [CmdletBinding()] 206 | param( 207 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 208 | [switch] 209 | $Enable, 210 | 211 | [Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)] 212 | [switch] 213 | $Disable, 214 | 215 | [Parameter(Position=2, Mandatory=$false, ValueFromPipeline=$true)] 216 | [switch] 217 | $Clear, 218 | 219 | [Parameter(Position=3, Mandatory=$false, ValueFromPipeline=$true)] 220 | [System.String] 221 | $vvSet, 222 | 223 | [Parameter(Position=4, Mandatory=$false, ValueFromPipeline=$true)] 224 | [switch] 225 | $All, 226 | 227 | [Parameter(Position=5, Mandatory=$false, ValueFromPipeline=$true)] 228 | $SANConnection = $global:SANConnection 229 | ) 230 | 231 | Write-DebugLog "Start: In Set-FlashCache - validating input values" $Debug 232 | #check if connection object contents are null/empty 233 | if(!$SANConnection) 234 | { 235 | #check if connection object contents are null/empty 236 | $Validate1 = Test-CLIConnection $SANConnection 237 | if($Validate1 -eq "Failed") 238 | { 239 | #check if global connection object contents are null/empty 240 | $Validate2 = Test-CLIConnection $global:SANConnection 241 | if($Validate2 -eq "Failed") 242 | { 243 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" " ERR: " 244 | Write-DebugLog "Stop: Exiting Set-FlashCache since SAN connection object values are null/empty" $Debug 245 | Return "Unable to execute the cmdlet Set-FlashCache since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 246 | } 247 | } 248 | } 249 | 250 | $plinkresult = Test-PARCli -SANConnection $SANConnection 251 | if($plinkresult -match "FAILURE :") 252 | { 253 | write-debuglog "$plinkresult" 254 | Return $plinkresult 255 | } 256 | 257 | $Cmd = " setflashcache " 258 | 259 | if($Enable) 260 | { 261 | $Cmd += " enable " 262 | } 263 | elseif($Disable) 264 | { 265 | $Cmd += " disable " 266 | } 267 | 268 | elseif($Clear) 269 | { 270 | $Cmd += " clear " 271 | } 272 | else 273 | { 274 | return "Select at least one from [ Enable | Disable | Clear] " 275 | } 276 | 277 | if($vvSet) 278 | { 279 | $Cmd += " $vvSet " 280 | } 281 | 282 | if($All) 283 | { 284 | $Cmd += " sys:all " 285 | } 286 | 287 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $Cmd 288 | Write-DebugLog "Executing Function : Set-FlashCache Command -->" INFO: 289 | 290 | Return $Result 291 | } ## End-of Set-FlashCache 292 | 293 | ########################################################################## 294 | ######################### FUNCTION Remove-FlashCache ##################### 295 | ########################################################################## 296 | Function Remove-FlashCache() 297 | { 298 | <# 299 | .SYNOPSIS 300 | Remove-FlashCache - Removes flash cache from the cluster. 301 | 302 | .DESCRIPTION 303 | The Remove-FlashCache command removes the flash cache from the cluster and will stop use of the extended cache. 304 | 305 | .EXAMPLE 306 | Remove-FlashCache 307 | 308 | .PARAMETER F 309 | Specifies that the command is forced. If this option is not used, the command requires confirmation before proceeding with its operation. 310 | 311 | .Notes 312 | NAME: Remove-FlashCache 313 | LASTEDIT 19/11/2019 314 | KEYWORDS: Remove-FlashCache 315 | 316 | .Link 317 | http://www.hpe.com 318 | 319 | #Requires PS -Version 3.0 320 | #> 321 | [CmdletBinding()] 322 | param( 323 | [Parameter(Position=0, Mandatory=$false)] 324 | [switch] 325 | $F, 326 | 327 | [Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)] 328 | $SANConnection = $global:SANConnection 329 | ) 330 | 331 | Write-DebugLog "Start: In Remove-FlashCache - validating input values" $Debug 332 | #check if connection object contents are null/empty 333 | if(!$SANConnection) 334 | { 335 | #check if connection object contents are null/empty 336 | $Validate1 = Test-CLIConnection $SANConnection 337 | if($Validate1 -eq "Failed") 338 | { 339 | #check if global connection object contents are null/empty 340 | $Validate2 = Test-CLIConnection $global:SANConnection 341 | if($Validate2 -eq "Failed") 342 | { 343 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" " ERR: " 344 | Write-DebugLog "Stop: Exiting Remove-FlashCache since SAN connection object values are null/empty" $Debug 345 | Return "Unable to execute the cmdlet Remove-FlashCache since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 346 | } 347 | } 348 | } 349 | 350 | $plinkresult = Test-PARCli -SANConnection $SANConnection 351 | if($plinkresult -match "FAILURE :") 352 | { 353 | write-debuglog "$plinkresult" 354 | Return $plinkresult 355 | } 356 | 357 | $Cmd = " removeflashcache " 358 | 359 | if($F) 360 | { 361 | $Cmd += " -f " 362 | } 363 | 364 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $Cmd 365 | Write-DebugLog "Executing Function : Remove-FlashCache Command -->" INFO: 366 | 367 | Return $Result 368 | } ## End-of Remove-FlashCache 369 | 370 | 371 | Export-ModuleMember New-FlashCache , Set-FlashCache , Remove-FlashCache -------------------------------------------------------------------------------- /WSAPI/SessionKeysAndWsapiSystemAccess.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: SessionKeysAndWsapiSystemAccess.psm1 23 | ## Description: Session keys and WSAPI system access cmdlets 24 | ## 25 | ## Created: January 2020 26 | ## Last Modified: April 2021 27 | ## History: v3.0 - Created 28 | ## v3.1 - Added support for Primera 4.2 and Alletra 9000 storage system 29 | ##################################################################################### 30 | 31 | $Info = "INFO:" 32 | $Debug = "DEBUG:" 33 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 34 | $global:ArrayType = $null 35 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 36 | 37 | ############################################################################################################################################ 38 | ## New-WSAPIConnection 39 | ############################################################################################################################################ 40 | Function New-WSAPIConnection { 41 | <# 42 | .SYNOPSIS 43 | Create a WSAPI session key 44 | 45 | .DESCRIPTION 46 | To use Web Services, you must create a session key. Use the same username and password that you use to 47 | access the storage system through the 3PAR CLI or the 3PAR MC. Creating this authorization allows 48 | you to complete the same operations using WSAPI as you would the CLI or MC. 49 | 50 | .EXAMPLE 51 | New-WSAPIConnection -ArrayFQDNorIPAddress 10.10.10.10 -SANUserName XYZ -SANPassword XYZ@123 -ArrayType 3par 52 | create a session key with array. 53 | 54 | .EXAMPLE 55 | New-WSAPIConnection -ArrayFQDNorIPAddress 10.10.10.10 -SANUserName XYZ -SANPassword XYZ@123 -ArrayType primera 56 | create a session key with Primera array. 57 | 58 | .EXAMPLE 59 | New-WSAPIConnection -ArrayFQDNorIPAddress 10.10.10.10 -SANUserName XYZ -SANPassword XYZ@123 -ArrayType alletra9000 60 | create a session key with Alletra 9000 array. 61 | 62 | .PARAMETER ArrayFQDNorIPAddress 63 | Specify the Array FQDN or Array IP address. 64 | 65 | .PARAMETER UserName 66 | Specify the user name 67 | 68 | .PARAMETER Password 69 | Specify the password 70 | 71 | .PARAMETER ArrayType 72 | Specify the array type ie. 3Par, Primera or Alletra9000 73 | 74 | .Notes 75 | NAME : New-WSAPIConnection 76 | LASTEDIT: April 2021 77 | KEYWORDS: New-WSAPIConnection 78 | 79 | .Link 80 | http://www.hpe.com 81 | 82 | #Requires PS -Version 3.0 83 | #> 84 | [CmdletBinding()] 85 | param( 86 | [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] 87 | [System.String] 88 | $ArrayFQDNorIPAddress, 89 | 90 | [Parameter(Position=1, Mandatory=$true, ValueFromPipeline=$true)] 91 | [System.String] 92 | $SANUserName=$null, 93 | 94 | [Parameter(Position=2, Mandatory=$false, ValueFromPipeline=$true)] 95 | [System.String] 96 | $SANPassword=$null , 97 | 98 | [Parameter(Position=3, Mandatory=$true, ValueFromPipeline=$true, HelpMessage="Enter array type : 3par, primera or alletra9000")] 99 | [ValidateSet("3par", "primera", "alletra9000")] 100 | [System.String] 101 | $ArrayType 102 | ) 103 | #(self-signed) certificate, 104 | 105 | if ($PSEdition -eq 'Core') 106 | { 107 | 108 | } 109 | else 110 | { 111 | 112 | add-type @" 113 | using System.Net; 114 | using System.Security.Cryptography.X509Certificates; 115 | public class TrustAllCertsPolicy : ICertificatePolicy { 116 | public bool CheckValidationResult( 117 | ServicePoint srvPoint, X509Certificate certificate, 118 | WebRequest request, int certificateProblem) { 119 | return true; 120 | } 121 | } 122 | "@ 123 | [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy 124 | } 125 | 126 | #END of (self-signed) certificate, 127 | if(!($SANPassword)) 128 | { 129 | $SANPassword1 = Read-host "SANPassword" -assecurestring 130 | #$globalpwd = $SANPassword1 131 | $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SANPassword1) 132 | $SANPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) 133 | } 134 | 135 | #Write-DebugLog "start: Entering function New-WSAPIConnection. Validating IP Address format." $Debug 136 | #if(-not (Test-IPFormat $ArrayFQDNorIPAddress)) 137 | #{ 138 | # Write-DebugLog "Stop: Invalid IP Address $ArrayFQDNorIPAddress" "ERR:" 139 | # return "FAILURE : Invalid IP Address $ArrayFQDNorIPAddress" 140 | #} 141 | 142 | <# 143 | # -------- Check any active CLI/PoshSSH session exists ------------ starts 144 | if($global:SANConnection){ 145 | $confirm = Read-Host "An active CLI/PoshSSH session exists.`nDo you want to close the current CLI/PoshSSH session and start a new WSAPI session (Enter y=yes n=no)" 146 | if ($confirm.tolower() -eq 'y') { 147 | Close-Connection 148 | } 149 | elseif ($confirm.tolower() -eq 'n') { 150 | return 151 | } 152 | } 153 | # -------- Check any active CLI/PoshSSH session exists ------------ ends 154 | 155 | # -------- Check any active WSAPI session exists ------------------ starts 156 | if($global:WsapiConnection){ 157 | $confirm = Read-Host "An active WSAPI session exists.`nDo you want to close the current WSAPI session and start a new WSAPI session (Enter y=yes n=no)" 158 | if ($confirm.tolower() -eq 'y') { 159 | Close-WSAPIConnection 160 | } 161 | elseif ($confirm.tolower() -eq 'n') { 162 | return 163 | } 164 | } 165 | # -------- Check any active WSAPI session exists ------------------ ends 166 | #> 167 | 168 | #Write-DebugLog "Running: Completed validating IP address format." $Debug 169 | #Write-DebugLog "Running: Authenticating credentials - Invoke-WSAPI for user $SANUserName and SANIP= $ArrayFQDNorIPAddress" $Debug 170 | 171 | #URL 172 | $APIurl = $null 173 | if($ArrayType.ToLower() -eq "3par") 174 | { 175 | $global:ArrayType = "3par" 176 | $APIurl = "https://$($ArrayFQDNorIPAddress):8080/api/v1" 177 | } 178 | elseif($ArrayType.ToLower() -eq "primera") 179 | { 180 | $global:ArrayType = "Primera" 181 | $APIurl = "https://$($ArrayFQDNorIPAddress):443/api/v1" 182 | } 183 | elseif($ArrayType.ToLower() -eq "alletra9000") 184 | { 185 | $global:ArrayType = "Alletra9000" 186 | $APIurl = "https://$($ArrayFQDNorIPAddress):443/api/v1" 187 | } 188 | else 189 | { 190 | write-host " You have entered an unsupported Array type : $ArrayType. Please enter the array type as 3par, Primera or Alletra 9000." -foreground yellow 191 | Return 192 | } 193 | 194 | #connect to WSAPI 195 | $postParams = @{user=$SANUserName;password=$SANPassword} | ConvertTo-Json 196 | $headers = @{} 197 | $headers["Accept"] = "application/json" 198 | 199 | Try 200 | { 201 | Write-DebugLog "Running: Invoke-WebRequest for credential data." $Debug 202 | if ($PSEdition -eq 'Core') 203 | { 204 | $credentialdata = Invoke-WebRequest -Uri "$APIurl/credentials" -Body $postParams -ContentType "application/json" -Headers $headers -Method POST -UseBasicParsing -SkipCertificateCheck 205 | } 206 | else 207 | { 208 | $credentialdata = Invoke-WebRequest -Uri "$APIurl/credentials" -Body $postParams -ContentType "application/json" -Headers $headers -Method POST -UseBasicParsing 209 | } 210 | } 211 | catch 212 | { 213 | Write-DebugLog "Stop: Exception Occurs" $Debug 214 | Show-RequestException -Exception $_ 215 | write-host "" 216 | write-host "FAILURE : While establishing the connection " -foreground red 217 | write-host "" 218 | Write-DebugLog "FAILURE : While establishing the connection " $Info 219 | throw 220 | } 221 | 222 | #$global:3parArray = $ArrayFQDNorIPAddress 223 | $key = ($credentialdata.Content | ConvertFrom-Json).key 224 | #$global:3parKey = $key 225 | if(!$key) 226 | { 227 | Write-DebugLog "Stop: No key Generated" 228 | return "Error: No key Generated" 229 | } 230 | 231 | $SANC1 = New-Object "WSAPIconObject" 232 | 233 | $SANC1.IPAddress = $ArrayFQDNorIPAddress 234 | $SANC1.Key = $key 235 | 236 | $Result = Get-System_WSAPI -WsapiConnection $SANC1 237 | 238 | $SANC = New-Object "WSAPIconObject" 239 | 240 | $SANC.Id = $Result.id 241 | $SANC.Name = $Result.name 242 | $SANC.SystemVersion = $Result.systemVersion 243 | $SANC.Patches = $Result.patches 244 | $SANC.IPAddress = $ArrayFQDNorIPAddress 245 | $SANC.Model = $Result.model 246 | $SANC.SerialNumber = $Result.serialNumber 247 | $SANC.TotalCapacityMiB = $Result.totalCapacityMiB 248 | $SANC.AllocatedCapacityMiB = $Result.allocatedCapacityMiB 249 | $SANC.FreeCapacityMiB = $Result.freeCapacityMiB 250 | $SANC.Key = $key 251 | 252 | $global:WsapiConnection = $SANC 253 | 254 | $global:ArrayName = $Result.name 255 | 256 | # Set to the prompt as "Array Name:Connection Type (WSAPI|CLI)>" 257 | Function global:prompt { 258 | if ($global:WsapiConnection -ne $null){ 259 | $global:ArrayName + ":WSAPI>" 260 | } 261 | else{ 262 | (Get-Location).Path + ">" 263 | } 264 | } 265 | 266 | Write-DebugLog "End: If there are no errors reported on the console then the SAN connection object is set and ready to be used" $Info 267 | #Write-Verbose -Message "Acquired token: $global:3parKey" 268 | Write-Verbose -Message 'You are now connected to the HPE Storage system' 269 | Write-Verbose -Message 'Show array informations:' 270 | 271 | return $SANC 272 | } 273 | #End of New-WSAPIConnection 274 | 275 | ############################################################################################################################################ 276 | ## FUNCTION Close-WSAPIConnection 277 | ############################################################################################################################################ 278 | Function Close-WSAPIConnection 279 | { 280 | <# 281 | 282 | .SYNOPSIS 283 | Delete a WSAPI session key. 284 | 285 | .DESCRIPTION 286 | When finishes making requests to the server it should delete the session keys it created . 287 | Unused session keys expire automatically after the configured session times out. 288 | 289 | .PARAMETER WsapiConnection 290 | WSAPI Connection object created with Connection command 291 | 292 | .EXAMPLE 293 | Close-WSAPIConnection 294 | Delete a WSAPI session key. 295 | 296 | .Notes 297 | NAME : Close-WSAPIConnection 298 | LASTEDIT: January 2020 299 | KEYWORDS: Close-WSAPIConnection 300 | 301 | .Link 302 | http://www.hpe.com 303 | 304 | #Requires PS -Version 3.0 305 | 306 | #> 307 | [CmdletBinding(SupportsShouldProcess = $True,ConfirmImpact = 'High')] 308 | Param( 309 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 310 | $WsapiConnection = $global:WsapiConnection 311 | ) 312 | Begin 313 | { 314 | # Test if connection exist 315 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 316 | } 317 | 318 | Process 319 | { 320 | if ($pscmdlet.ShouldProcess($h.name,"Disconnect from array")) 321 | { 322 | #Build uri 323 | 324 | #$ip = $WsapiConnection.IPAddress 325 | $key = $WsapiConnection.Key 326 | 327 | Write-DebugLog "Running: Building uri to close wsapi connection cmdlet." $Debug 328 | $uri = '/credentials/'+$key 329 | 330 | #init the response var 331 | $data = $null 332 | 333 | #Request 334 | Write-DebugLog "Request: Request to close wsapi connection (Invoke-WSAPI)." $Debug 335 | $data = Invoke-WSAPI -uri $uri -type 'DELETE' -WsapiConnection $WsapiConnection 336 | 337 | $global:WsapiConnection = $null 338 | 339 | # Set to the default prompt as current path 340 | if ($global:WsapiConnection -eq $null) 341 | { 342 | Function global:prompt {(Get-Location).Path + ">"} 343 | } 344 | 345 | return $data 346 | <# 347 | If ($global:3parkey) 348 | { 349 | Write-Verbose -Message "Delete key session: $global:3parkey" 350 | Remove-Variable -name 3parKey -scope global 351 | Write-DebugLog "End: Key Deleted" $Debug 352 | } 353 | If ($global:3parArray) 354 | { 355 | Write-Verbose -Message "Delete Array: $global:3parArray" 356 | Remove-Variable -name 3parArray -scope global 357 | Write-DebugLog "End: Delete Array: $global:3parArray" $Debug 358 | } 359 | #> 360 | } 361 | Write-DebugLog "End: Close-WSAPIConnection" $Debug 362 | } 363 | End {} 364 | } 365 | #END Close-WSAPIConnection 366 | 367 | Export-ModuleMember New-WSAPIConnection , Close-WSAPIConnection -------------------------------------------------------------------------------- /WSAPI/FlashCacheOperations.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: FlashCacheOperations.psm1 23 | ## Description: Flash cache operations cmdlets 24 | ## 25 | ## Created: February 2020 26 | ## Last Modified: February 2020 27 | ## History: v3.0 - Created 28 | ##################################################################################### 29 | 30 | $Info = "INFO:" 31 | $Debug = "DEBUG:" 32 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 33 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 34 | 35 | 36 | ############################################################################################################################################ 37 | ## FUNCTION Set-FlashCache_WSAPI 38 | ############################################################################################################################################ 39 | Function Set-FlashCache_WSAPI 40 | { 41 | <# 42 | .SYNOPSIS 43 | Setting Flash Cache policy 44 | 45 | .DESCRIPTION 46 | Setting Flash Cache policy 47 | 48 | .EXAMPLE 49 | Set-FlashCache_WSAPI -Enable 50 | Enable Flash Cache policy 51 | 52 | .EXAMPLE 53 | Set-FlashCache_WSAPI -Disable 54 | Disable Flash Cache policy 55 | 56 | .PARAMETER Enable 57 | Enable Flash Cache policy 58 | 59 | .PARAMETER Disable 60 | Disable Flash Cache policy 61 | 62 | .PARAMETER WsapiConnection 63 | WSAPI Connection object created with Connection command 64 | 65 | .Notes 66 | NAME : Set-FlashCache_WSAPI 67 | LASTEDIT: February 2020 68 | KEYWORDS: Set-FlashCache_WSAPI 69 | 70 | .Link 71 | http://www.hpe.com 72 | 73 | #Requires PS -Version 3.0 74 | #> 75 | 76 | [CmdletBinding()] 77 | Param( 78 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 79 | [switch] 80 | $Enable, 81 | 82 | [Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)] 83 | [switch] 84 | $Disable, 85 | 86 | [Parameter(Position=2, Mandatory=$false, ValueFromPipeline=$true)] 87 | $WsapiConnection = $global:WsapiConnection 88 | ) 89 | 90 | Begin 91 | { 92 | # Test if connection exist 93 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 94 | } 95 | 96 | Process 97 | { 98 | $body = @{} 99 | 100 | If ($Enable) 101 | { 102 | $body["flashCachePolicy"] = 1 103 | } 104 | elseIf ($Disable) 105 | { 106 | $body["flashCachePolicy"] = 2 107 | } 108 | else 109 | { 110 | return "Please Select at-list any one from [Enable Or Disable]" 111 | } 112 | 113 | 114 | $Result = $null 115 | 116 | #Request 117 | Write-DebugLog "Request: Request to Set-FlashCache_WSAPI (Invoke-WSAPI)." $Debug 118 | $Result = Invoke-WSAPI -uri '/system' -type 'PUT' -body $body -WsapiConnection $WsapiConnection 119 | 120 | if($Result.StatusCode -eq 200) 121 | { 122 | write-host "" 123 | write-host "Cmdlet executed successfully" -foreground green 124 | write-host "" 125 | Write-DebugLog "SUCCESS: Successfully Set Flash Cache policy." $Info 126 | 127 | # Results 128 | return $Result 129 | Write-DebugLog "End: Set-FlashCache_WSAPI." $Debug 130 | } 131 | else 132 | { 133 | write-host "" 134 | write-host "FAILURE : While Setting Flash Cache policy." -foreground red 135 | write-host "" 136 | Write-DebugLog "FAILURE : While Setting Flash Cache policy." $Info 137 | 138 | return $Result.StatusDescription 139 | } 140 | } 141 | 142 | End { } 143 | 144 | }#END Set-FlashCache_WSAPI 145 | 146 | 147 | ############################################################################################################################################ 148 | ## FUNCTION New-FlashCache_WSAPI 149 | ############################################################################################################################################ 150 | Function New-FlashCache_WSAPI 151 | { 152 | <# 153 | .SYNOPSIS 154 | Creating a Flash Cache. 155 | 156 | .DESCRIPTION 157 | Creating a Flash Cache. 158 | 159 | .EXAMPLE 160 | New-FlashCache_WSAPI -SizeGiB 64 -Mode 1 -RAIDType R6 161 | 162 | .EXAMPLE 163 | New-FlashCache_WSAPI -SizeGiB 64 -Mode 1 -RAIDType R0 164 | 165 | .EXAMPLE 166 | New-FlashCache_WSAPI -NoCheckSCMSize "true" 167 | 168 | .EXAMPLE 169 | New-FlashCache_WSAPI -NoCheckSCMSize "false" 170 | 171 | .PARAMETER SizeGiB 172 | Specifies the node pair size of the Flash Cache on the system. 173 | 174 | .PARAMETER Mode 175 | Simulator: 1 Real: 2 (default) 176 | 177 | .PARAMETER RAIDType 178 | Raid Type of the logical disks for flash cache. When unspecified, storage system chooses the default(R0 Level0,R1 Level1). 179 | 180 | .PARAMETER NoCheckSCMSize 181 | Overrides the size comparison check to allow Adaptive Flash Cache creation with mismatched SCM device sizes. 182 | 183 | .PARAMETER WsapiConnection 184 | WSAPI Connection object created with Connection command 185 | 186 | .Notes 187 | NAME : New-FlashCache_WSAPI 188 | LASTEDIT: February 2020 189 | KEYWORDS: New-FlashCache_WSAPI 190 | 191 | .Link 192 | http://www.hpe.com 193 | 194 | #Requires PS -Version 3.0 195 | #> 196 | 197 | [CmdletBinding()] 198 | Param( 199 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 200 | [int] 201 | $SizeGiB, 202 | 203 | [Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)] 204 | [int] 205 | $Mode, 206 | 207 | [Parameter(Position=2, Mandatory=$false, ValueFromPipeline=$true)] 208 | [System.String] 209 | $RAIDType, 210 | 211 | [Parameter(Position=3, Mandatory=$false, ValueFromPipeline=$true)] 212 | [System.String] 213 | $NoCheckSCMSize, 214 | 215 | [Parameter(Position=3, Mandatory=$false, ValueFromPipeline=$true)] 216 | $WsapiConnection = $global:WsapiConnection 217 | ) 218 | 219 | Begin 220 | { 221 | # Test if connection exist 222 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 223 | } 224 | 225 | Process 226 | { 227 | Write-DebugLog "Running: Creation of the body hash" $Debug 228 | # Creation of the body hash 229 | $body = @{} 230 | $FlashCacheBody = @{} 231 | 232 | If($SizeGiB) 233 | { 234 | $FlashCacheBody["sizeGiB"] = $SizeGiB 235 | } 236 | If($Mode) 237 | { 238 | $FlashCacheBody["mode"] = $Mode 239 | } 240 | if($RAIDType) 241 | { 242 | if($RAIDType -eq "R0") 243 | { 244 | $FlashCacheBody["RAIDType"] = 1 245 | } 246 | elseif($RAIDType -eq "R1") 247 | { 248 | $FlashCacheBody["RAIDType"] = 2 249 | } 250 | else 251 | { 252 | Write-DebugLog "Stop: Exiting Update-Cpg_WSAPI since RAIDType $RAIDType in incorrect " 253 | Return "FAILURE : RAIDType :- $RAIDType is an Incorrect Please Use RAIDType R0 or R1 only. " 254 | } 255 | } 256 | If($NoCheckSCMSize) 257 | { 258 | $val = $NoCheckSCMSize.ToUpper() 259 | if($val -eq "TRUE") 260 | { 261 | $FlashCacheBody["noCheckSCMSize"] = $True 262 | } 263 | if($val -eq "FALSE") 264 | { 265 | $FlashCacheBody["noCheckSCMSize"] = $false 266 | } 267 | } 268 | 269 | 270 | if($FlashCacheBody.Count -gt 0){$body["flashCache"] = $FlashCacheBody } 271 | 272 | $Result = $null 273 | 274 | #Request 275 | Write-DebugLog "Request: Request to New-FlashCache_WSAPI(Invoke-WSAPI)." $Debug 276 | 277 | #Request 278 | $Result = Invoke-WSAPI -uri '/' -type 'POST' -body $body -WsapiConnection $WsapiConnection 279 | 280 | $status = $Result.StatusCode 281 | if($status -eq 201) 282 | { 283 | write-host "" 284 | write-host "Cmdlet executed successfully" -foreground green 285 | write-host "" 286 | Write-DebugLog "SUCCESS: Successfully Created Flash Cache." $Info 287 | 288 | # Results 289 | return $Result 290 | Write-DebugLog "End: New-FlashCache_WSAPI" $Debug 291 | } 292 | else 293 | { 294 | write-host "" 295 | write-host "FAILURE : While creating a Flash Cache." -foreground red 296 | write-host "" 297 | Write-DebugLog "FAILURE : While creating a Flash Cache." $Info 298 | 299 | return $Result.StatusDescription 300 | } 301 | } 302 | 303 | End { } 304 | 305 | }#END New-FlashCache_WSAPI 306 | 307 | ############################################################################################################################################ 308 | ## FUNCTION Remove-FlashCache_WSAPI 309 | ############################################################################################################################################ 310 | Function Remove-FlashCache_WSAPI 311 | { 312 | <# 313 | .SYNOPSIS 314 | Removing a Flash Cache. 315 | 316 | .DESCRIPTION 317 | Removing a Flash Cache. 318 | 319 | .EXAMPLE 320 | Remove-FlashCache_WSAPI 321 | 322 | .PARAMETER WsapiConnection 323 | WSAPI Connection object created with Connection command 324 | 325 | .Notes 326 | NAME : Remove-FlashCache_WSAPI 327 | LASTEDIT: February 2020 328 | KEYWORDS: Remove-FlashCache_WSAPI 329 | 330 | .Link 331 | http://www.hpe.com 332 | 333 | #Requires PS -Version 3.0 334 | #> 335 | 336 | [CmdletBinding()] 337 | Param( 338 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 339 | $WsapiConnection = $global:WsapiConnection 340 | ) 341 | 342 | Begin 343 | { 344 | # Test if connection exist 345 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 346 | } 347 | 348 | Process 349 | { 350 | #Request 351 | Write-DebugLog "Request: Request to Remove-FlashCache_WSAPI(Invoke-WSAPI)." $Debug 352 | 353 | #Request 354 | 355 | $Result = Invoke-WSAPI -uri '/flashcache' -type 'DELETE' -WsapiConnection $WsapiConnection 356 | 357 | $status = $Result.StatusCode 358 | if($status -eq 200) 359 | { 360 | write-host "" 361 | write-host "Cmdlet executed successfully" -foreground green 362 | write-host "" 363 | Write-DebugLog "SUCCESS: Successfully Removed Flash CacheD." $Info 364 | 365 | # Results 366 | return $Result 367 | Write-DebugLog "End: Remove-FlashCache_WSAPI" $Debug 368 | } 369 | else 370 | { 371 | write-host "" 372 | write-host "FAILURE : While Removing Flash Cache." -foreground red 373 | write-host "" 374 | Write-DebugLog "FAILURE : While Removing Flash Cache." $Info 375 | 376 | return $Result.StatusDescription 377 | } 378 | } 379 | 380 | End { } 381 | 382 | }#END Remove-FlashCache_WSAPI 383 | 384 | ############################################################################################################################################ 385 | ## FUNCTION Get-FlashCache_WSAPI 386 | ############################################################################################################################################ 387 | Function Get-FlashCache_WSAPI 388 | { 389 | <# 390 | 391 | .SYNOPSIS 392 | Get Flash Cache information. 393 | 394 | .DESCRIPTION 395 | Get Flash Cache information. 396 | 397 | .EXAMPLE 398 | Get-FlashCache_WSAPI 399 | Get Flash Cache information. 400 | 401 | .PARAMETER WsapiConnection 402 | WSAPI Connection object created with Connection command 403 | 404 | .Notes 405 | NAME : Get-FlashCache_WSAPI 406 | LASTEDIT: February 2020 407 | KEYWORDS: Get-FlashCache_WSAPI 408 | 409 | .Link 410 | http://www.hpe.com 411 | 412 | #Requires PS -Version 3.0 413 | 414 | #> 415 | [CmdletBinding()] 416 | Param( 417 | [Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)] 418 | $WsapiConnection = $global:WsapiConnection 419 | ) 420 | 421 | Begin 422 | { 423 | #Test if connection exist 424 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 425 | } 426 | 427 | Process 428 | { 429 | $Result = $null 430 | $dataPS = $null 431 | 432 | #Request 433 | 434 | $Result = Invoke-WSAPI -uri '/flashcache' -type 'GET' -WsapiConnection $WsapiConnection 435 | 436 | if($Result.StatusCode -eq 200) 437 | { 438 | $dataPS = $Result.content | ConvertFrom-Json 439 | } 440 | 441 | if($Result.StatusCode -eq 200) 442 | { 443 | write-host "" 444 | write-host "Cmdlet executed successfully" -foreground green 445 | write-host "" 446 | Write-DebugLog "SUCCESS: Command Get-FlashCache_WSAPI Successfully Executed" $Info 447 | 448 | return $dataPS 449 | } 450 | else 451 | { 452 | write-host "" 453 | write-host "FAILURE : While Executing Get-FlashCache_WSAPI." -foreground red 454 | write-host "" 455 | Write-DebugLog "FAILURE : While Executing Get-FlashCache_WSAPI." $Info 456 | 457 | return $Result.StatusDescription 458 | } 459 | } 460 | } 461 | #END Get-FlashCache_WSAPI 462 | 463 | 464 | Export-ModuleMember Set-FlashCache_WSAPI , New-FlashCache_WSAPI , Remove-FlashCache_WSAPI , Get-FlashCache_WSAPI -------------------------------------------------------------------------------- /CLI/MaintenanceMode.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: MaintenanceMode.psm1 23 | ## Description: Maintenance Mode cmdlets 24 | ## 25 | ## Created: January 2020 26 | ## Last Modified: January 2020 27 | ## History: v3.0- Created 28 | ##################################################################################### 29 | 30 | $Info = "INFO:" 31 | $Debug = "DEBUG:" 32 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 33 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 34 | 35 | ############################################################################################################################################ 36 | ## FUNCTION Test-CLIObject 37 | ############################################################################################################################################ 38 | Function Test-CLIObject 39 | { 40 | Param( 41 | [string]$ObjectType, 42 | [string]$ObjectName , 43 | [string]$ObjectMsg = $ObjectType, 44 | $SANConnection = $global:SANConnection 45 | ) 46 | 47 | $IsObjectExisted = $True 48 | $ObjCmd = $ObjectType -replace ' ', '' 49 | $Cmds = "show$ObjCmd $ObjectName" 50 | 51 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $Cmds 52 | if ($Result -like "no $ObjectMsg listed") 53 | { 54 | $IsObjectExisted = $false 55 | } 56 | return $IsObjectExisted 57 | 58 | } # End FUNCTION Test-CLIObject 59 | 60 | ########################################################################## 61 | ########################### FUNCTION Get-Maint ########################### 62 | ########################################################################## 63 | Function Get-Maint() 64 | { 65 | <# 66 | .SYNOPSIS 67 | Get-Maint - Show maintenance window records. 68 | 69 | .DESCRIPTION 70 | The Get-Maint command displays maintenance window records. 71 | 72 | .EXAMPLE 73 | Get-Maint 74 | 75 | .EXAMPLE 76 | Get-Maint -All 77 | 78 | .PARAMETER All 79 | Display all maintenance window records, including active and expired 80 | ones. If this option is not specified, only active window records will 81 | be displayed. 82 | 83 | .PARAMETER Sortcol 84 | Sorts command output based on column number (). Columns are 85 | numbered from left to right, beginning with 0. At least one column must 86 | be specified. In addition, the direction of sorting () can be 87 | specified as follows: 88 | inc 89 | Sort in increasing order (default). 90 | dec 91 | Sort in decreasing order. 92 | 93 | .Notes 94 | NAME: Get-Maint 95 | LASTEDIT January 2020 96 | KEYWORDS: Get-Maint 97 | 98 | .Link 99 | http://www.hpe.com 100 | 101 | #Requires PS -Version 3.0 102 | #> 103 | [CmdletBinding()] 104 | param( 105 | [Parameter(Position=0, Mandatory=$false)] 106 | [switch] 107 | $All, 108 | 109 | [Parameter(Position=1, Mandatory=$false)] 110 | [System.String] 111 | $Sortcol, 112 | 113 | [Parameter(Position=2, Mandatory=$false, ValueFromPipeline=$true)] 114 | $SANConnection = $global:SANConnection 115 | ) 116 | 117 | Write-DebugLog "Start: In Get-Maint - validating input values" $Debug 118 | #check if connection object contents are null/empty 119 | if(!$SANConnection) 120 | { 121 | #check if connection object contents are null/empty 122 | $Validate1 = Test-CLIConnection $SANConnection 123 | if($Validate1 -eq "Failed") 124 | { 125 | #check if global connection object contents are null/empty 126 | $Validate2 = Test-CLIConnection $global:SANConnection 127 | if($Validate2 -eq "Failed") 128 | { 129 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" " ERR: " 130 | Write-DebugLog "Stop: Exiting Get-Maint since SAN connection object values are null/empty" $Debug 131 | Return "Unable to execute the cmdlet Get-Maint since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 132 | } 133 | } 134 | } 135 | 136 | $plinkresult = Test-PARCli -SANConnection $SANConnection 137 | if($plinkresult -match "FAILURE :") 138 | { 139 | write-debuglog "$plinkresult" 140 | Return $plinkresult 141 | } 142 | 143 | $Cmd = " showmaint " 144 | 145 | if($All) 146 | { 147 | $Cmd += " -all " 148 | } 149 | 150 | if($Sortcol) 151 | { 152 | $Cmd += " -sortcol $Sortcol " 153 | } 154 | 155 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $Cmd 156 | Write-DebugLog "Executing Function : Get-Maint Command -->" INFO: 157 | 158 | if($Result.count -gt 1) 159 | { 160 | $Cnt = $Result.count 161 | 162 | $tempFile = [IO.Path]::GetTempFileName() 163 | $LastItem = $Result.Count -2 164 | 165 | foreach ($s in $Result[0..$LastItem] ) 166 | { 167 | $s= [regex]::Replace($s,"^ ","") 168 | $s= [regex]::Replace($s,"^ ","") 169 | $s= [regex]::Replace($s," +",",") 170 | $s= [regex]::Replace($s,"-","") 171 | $s= $s.Trim() 172 | 173 | $temp1 = $s -replace 'StartTime','S-Date,S-Time,S-Zone' 174 | $temp2 = $temp1 -replace 'EndTime','E-Date,E-Time,E-Zone' 175 | $s = $temp2 176 | 177 | Add-Content -Path $tempfile -Value $s 178 | } 179 | Import-Csv $tempFile 180 | del $tempFile 181 | } 182 | 183 | if($Result.count -gt 1) 184 | { 185 | return " Success : Executing Get-Maint" 186 | } 187 | else 188 | { 189 | return $Result 190 | } 191 | 192 | } ## End-of Get-Maint 193 | 194 | ########################################################################## 195 | ######################### FUNCTION New-Maint ######################### 196 | ########################################################################## 197 | Function New-Maint() 198 | { 199 | <# 200 | .SYNOPSIS 201 | New-Maint - Create a maintenance window record. 202 | 203 | .DESCRIPTION 204 | The New-Maint command creates a maintenance window record with the 205 | specified options and maintenance type. 206 | 207 | .EXAMPLE 208 | New-Maint -Duration 1m -MaintType Node 209 | 210 | .PARAMETER Comment 211 | Specifies any comment or additional information for the maintenance 212 | window record. The comment can be up to 255 characters long. Unprintable 213 | characters are not allowed. 214 | 215 | .PARAMETER Duration 216 | Sets the duration of the maintenance window record. May be specified in 217 | minutes (e.g. 20m) or hours (e.g. 6h). Value is not to exceed 218 | 24 hours. The default is 4 hours. 219 | 220 | .PARAMETER MaintType 221 | Specify the maintenance type. 222 | Maintenance type can be Other, Node, Restart, Disk, Cage, Cabling, Upgrade, DiskFirmware, or CageFirmware. 223 | 224 | .Notes 225 | NAME: New-Maint 226 | LASTEDIT January 2020 227 | KEYWORDS: New-Maint 228 | 229 | .Link 230 | http://www.hpe.com 231 | 232 | #Requires PS -Version 3.0 233 | #> 234 | [CmdletBinding()] 235 | param( 236 | 237 | [Parameter(Position=0, Mandatory=$false)] 238 | [System.String] 239 | $Comment, 240 | 241 | [Parameter(Position=1, Mandatory=$false)] 242 | [System.String] 243 | $Duration, 244 | 245 | [Parameter(Position=2, Mandatory=$true)] 246 | [System.String] 247 | $MaintType, 248 | 249 | [Parameter(Position=3, Mandatory=$false, ValueFromPipeline=$true)] 250 | $SANConnection = $global:SANConnection 251 | ) 252 | 253 | Write-DebugLog "Start: In New-Maint - validating input values" $Debug 254 | #check if connection object contents are null/empty 255 | if(!$SANConnection) 256 | { 257 | #check if connection object contents are null/empty 258 | $Validate1 = Test-CLIConnection $SANConnection 259 | if($Validate1 -eq "Failed") 260 | { 261 | #check if global connection object contents are null/empty 262 | $Validate2 = Test-CLIConnection $global:SANConnection 263 | if($Validate2 -eq "Failed") 264 | { 265 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" " ERR: " 266 | Write-DebugLog "Stop: Exiting New-Maint since SAN connection object values are null/empty" $Debug 267 | Return "Unable to execute the cmdlet New-Maint since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 268 | } 269 | } 270 | } 271 | 272 | $plinkresult = Test-PARCli -SANConnection $SANConnection 273 | if($plinkresult -match "FAILURE :") 274 | { 275 | write-debuglog "$plinkresult" 276 | Return $plinkresult 277 | } 278 | 279 | $Cmd = " createmaint -f " 280 | 281 | if($Comment) 282 | { 283 | $Cmd += " -comment $Comment " 284 | } 285 | 286 | if($Duration) 287 | { 288 | $Cmd += " -duration $Duration " 289 | } 290 | 291 | if($MaintType) 292 | { 293 | $Cmd += " $MaintType " 294 | } 295 | 296 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $Cmd 297 | Write-DebugLog "Executing function : New-Maint command -->" INFO: 298 | 299 | Return $Result 300 | } ## End-of New-Maint 301 | 302 | ########################################################################## 303 | ######################### FUNCTION Set-Maint ######################### 304 | ########################################################################## 305 | Function Set-Maint() 306 | { 307 | <# 308 | .SYNOPSIS 309 | Set-Maint - Modify a maintenance window record with the specified options for 310 | the maintenance type. 311 | 312 | .DESCRIPTION 313 | Allows modification of the Maintenance window record with the specified 314 | options for the maintenance type. 315 | 316 | .EXAMPLE 317 | 318 | .PARAMETER Comment 319 | Specifies any comment or additional information for the maintenance 320 | window record. The comment can be up to 255 characters long. Unprintable 321 | characters are not allowed. 322 | 323 | .PARAMETER Duration 324 | Extends the duration of the maintenance window record by the specified 325 | time. May be specified in minutes (e.g. 20m) or hours (e.g. 6h). If 326 | unspecified, the window duration is unchanged. This option cannot be 327 | specified with the -end option. 328 | 329 | .PARAMETER End 330 | Ends the window record for the specified maintenance type. If the 331 | maintenance window record has been created more than once with 332 | "createmaint", this option reduces its reference count by 1 without 333 | ending the window record. This option cannot be specified with the 334 | Duration Option. 335 | 336 | .PARAMETER MaintType 337 | The maintenance type for the maintenance window record to be modified. 338 | Maintenance type can be Other, Node, Restart, Disk, Cage, Cabling, 339 | Upgrade, DiskFirmware, CageFirmware, or all. "all" can only be 340 | specified with option -end, which ends all maintenance window records, 341 | regardless of their reference counts. 342 | 343 | .Notes 344 | NAME: Set-Maint 345 | LASTEDIT January 2020 346 | KEYWORDS: Set-Maint 347 | 348 | .Link 349 | http://www.hpe.com 350 | 351 | #Requires PS -Version 3.0 352 | #> 353 | [CmdletBinding()] 354 | param( 355 | [Parameter(Position=0, Mandatory=$false)] 356 | [System.String] 357 | $Comment, 358 | 359 | [Parameter(Position=1, Mandatory=$false)] 360 | [System.String] 361 | $Duration, 362 | 363 | [Parameter(Position=2, Mandatory=$false)] 364 | [switch] 365 | $End, 366 | 367 | [Parameter(Position=3, Mandatory=$true)] 368 | [System.String] 369 | $MaintType, 370 | 371 | [Parameter(Position=4, Mandatory=$false, ValueFromPipeline=$true)] 372 | $SANConnection = $global:SANConnection 373 | ) 374 | 375 | Write-DebugLog "Start: In Set-Maint - validating input values" $Debug 376 | #check if connection object contents are null/empty 377 | if(!$SANConnection) 378 | { 379 | #check if connection object contents are null/empty 380 | $Validate1 = Test-CLIConnection $SANConnection 381 | if($Validate1 -eq "Failed") 382 | { 383 | #check if global connection object contents are null/empty 384 | $Validate2 = Test-CLIConnection $global:SANConnection 385 | if($Validate2 -eq "Failed") 386 | { 387 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" " ERR: " 388 | Write-DebugLog "Stop: Exiting Set-Maint since SAN connection object values are null/empty" $Debug 389 | Return "Unable to execute the cmdlet Set-Maint since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 390 | } 391 | } 392 | } 393 | 394 | $plinkresult = Test-PARCli -SANConnection $SANConnection 395 | if($plinkresult -match "FAILURE :") 396 | { 397 | write-debuglog "$plinkresult" 398 | Return $plinkresult 399 | } 400 | 401 | $Cmd = " setmaint " 402 | 403 | if($Comment) 404 | { 405 | $Cmd += " -comment $Comment " 406 | } 407 | 408 | if($Duration) 409 | { 410 | $Cmd += " -duration $Duration " 411 | } 412 | 413 | if($End) 414 | { 415 | $Cmd += " -end " 416 | } 417 | 418 | if($MaintType) 419 | { 420 | $Cmd += " $MaintType " 421 | } 422 | 423 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $Cmd 424 | Write-DebugLog "Executing Function : Set-Maint Command -->" INFO: 425 | 426 | Return $Result 427 | } ## End-of Set-Maint 428 | 429 | Export-ModuleMember Get-Maint , New-Maint , Set-Maint -------------------------------------------------------------------------------- /CLI/Vasa.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: Vasa.psm1 23 | ## Description: VASA cmdlets 24 | ## 25 | ## Created: January 2020 26 | ## Last Modified: January 2020 27 | ## History: v3.0 - Created 28 | ##################################################################################### 29 | 30 | $Info = "INFO:" 31 | $Debug = "DEBUG:" 32 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 33 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 34 | 35 | ############################################################################################################################################ 36 | ## FUNCTION Test-CLIObject 37 | ############################################################################################################################################ 38 | Function Test-CLIObject 39 | { 40 | Param( 41 | [string]$ObjectType, 42 | [string]$ObjectName , 43 | [string]$ObjectMsg = $ObjectType, 44 | $SANConnection = $global:SANConnection 45 | ) 46 | 47 | $IsObjectExisted = $True 48 | $ObjCmd = $ObjectType -replace ' ', '' 49 | $Cmds = "show$ObjCmd $ObjectName" 50 | 51 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $Cmds 52 | if ($Result -like "no $ObjectMsg listed") 53 | { 54 | $IsObjectExisted = $false 55 | } 56 | return $IsObjectExisted 57 | 58 | } # End FUNCTION Test-CLIObject 59 | 60 | #################################################################################################################### 61 | ## FUNCTION Show-vVolvm 62 | #################################################################################################################### 63 | Function Show-vVolvm 64 | { 65 | <# 66 | .SYNOPSIS 67 | The Show-vVolvm command displays information about all virtual machines 68 | (VVol-based) or a specific virtual machine in a system. This command 69 | can be used to determine the association between virtual machines and 70 | their associated virtual volumes. showvvolvm will also show the 71 | accumulation of space usage information for a virtual machine. 72 | 73 | .DESCRIPTION 74 | The Show-vVolvm command displays information about all virtual machines 75 | (VVol-based) or a specific virtual machine in a system. This command 76 | can be used to determine the association between virtual machines and 77 | their associated virtual volumes. showvvolvm will also show the 78 | accumulation of space usage information for a virtual machine. 79 | 80 | .EXAMPLE 81 | Show-vVolvm -container_name XYZ -option listcols 82 | 83 | .EXAMPLE 84 | Show-vVolvm -container_name XYZ -Detailed 85 | 86 | .EXAMPLE 87 | Show-vVolvm -container_name XYZ -StorageProfiles 88 | 89 | .EXAMPLE 90 | Show-vVolvm -container_name XYZ -Summary 91 | 92 | .EXAMPLE 93 | Show-vVolvm -container_name XYZ -Binding 94 | 95 | .EXAMPLE 96 | Show-vVolvm -container_name XYZ -VVAssociatedWithVM 97 | 98 | .PARAMETER container_name 99 | The name of the virtual volume storage container. May be "sys:all" to display all VMs. 100 | 101 | .PARAMETER Listcols 102 | List the columns available to be shown in the -showcols option 103 | below (see "clihelp -col showvvolvm" for help on each column). 104 | 105 | By default with mandatory option -sc, (if none of the information selection options 106 | below are specified) the following columns are shown: 107 | VM_Name GuestOS VM_State Num_vv Physical Logical 108 | 109 | .PARAMETER Detailed 110 | Displays detailed information about the VMs. The following columns are shown: 111 | VM_Name UUID Num_vv Num_snap Physical Logical GuestOS VM_State UsrCPG SnpCPG Container CreationTime 112 | 113 | .PARAMETER StorageProfiles 114 | Shows the storage profiles with constraints associated with the VM. 115 | Often, all VVols associated with a VM will use the same storage profile. 116 | However, if vSphere has provisioned different VMDK volumes with different 117 | storage profiles, only the storage profile for the first virtual disk 118 | (VMDK) VVol will be displayed. In this case, use the -vv option to display 119 | storage profiles for individual volumes associated with the VM. Without 120 | the -vv option, the following columns are shown: 121 | VM_Name SP_Name SP_Constraint_List 122 | 123 | .PARAMETER Summary 124 | Shows the summary of virtual machines (VM) in the system, including 125 | the total number of the following: VMs, VVs, and total physical and 126 | exported space used. The following columns are shown: 127 | Num_vm Num_vv Physical Logical 128 | 129 | .PARAMETER Binding 130 | Shows the detailed binding information for the VMs. The binding could 131 | be PoweredOn, Bound (exported), or Unbound. When it is bound, 132 | showvvolvm displays host names to which it is bound. When it is bound 133 | and -vv option is used, showvvolvm displays the exported LUN templates 134 | for each volume, and the state for actively bound VVols. PoweredOn 135 | means the VM is powered on. Bound means the VM is not powered on, 136 | but either being created, modified, queried or changing powered state 137 | from on to off or off to on. Unbound means the VM is powered off. 138 | The following columns are shown: 139 | VM_Name VM_State Last_Host Last_State_Time Last_Pwr_Time 140 | 141 | With the -vv option, the following columns are shown: 142 | VM_Name VVol_Name VVol_Type VVol_State VVol_LunId Bind_Host Last_State_Time 143 | 144 | .PARAMETER VVAssociatedWithVM 145 | Shows all the VVs (Virtual Volumes) associated with the VM. 146 | The following columns are shown: 147 | VM_Name VV_ID VVol_Name VVol_Type Prov Physical Logical 148 | 149 | The columns displayed can change when used with other options. 150 | See the -binding option above. 151 | 152 | .PARAMETER RemoteCopy 153 | Shows the remote copy group name, sync status, role, and last sync time of the 154 | volumes associated with a VM. Note that if a VM does not report as synced, the 155 | last sync time for the VM DOES NOT represent a consistency point. True 156 | consistency points are only represented by the showrcopy LastSyncTime. This 157 | option may be combined with the -vv, -binding, -d, and -sp options. 158 | 159 | .PARAMETER AutoDismissed 160 | Shows only VMs containing automatically dismissed volumes. Shows only 161 | automatically dismissed volumes when combined with the -vv option. 162 | 163 | .PARAMETER VM_name 164 | Specifies the VMs with the specified name (up to 80 characters in length). 165 | This specifier can be repeated to display information about multiple VMs. 166 | This specifier is not required. If not specified, showvvolvm displays 167 | information for all VMs in the specified storage container. 168 | 169 | .PARAMETER SANConnection 170 | Specify the SAN Connection object created with New-CLIConnection or New-PoshSshConnection 171 | 172 | .Notes 173 | NAME: Show-vVolvm 174 | LASTEDIT: January 2020 175 | KEYWORDS: Show-vVolvm 176 | 177 | .Link 178 | http://www.hpe.com 179 | 180 | #Requires PS -Version 3.0 181 | 182 | #> 183 | [CmdletBinding()] 184 | param( 185 | 186 | [Parameter(Position=0, Mandatory=$false)] 187 | [System.String] 188 | $container_name, 189 | 190 | [Parameter(Position=1, Mandatory=$false)] 191 | [switch] 192 | $ListCols, 193 | 194 | [Parameter(Position=2, Mandatory=$false)] 195 | [System.String] 196 | $ShowCols, 197 | 198 | [Parameter(Position=3, Mandatory=$false)] 199 | [switch] 200 | $Detailed, 201 | 202 | [Parameter(Position=4, Mandatory=$false)] 203 | [switch] 204 | $StorageProfiles, 205 | 206 | [Parameter(Position=5, Mandatory=$false)] 207 | [switch] 208 | $Summary, 209 | 210 | [Parameter(Position=6, Mandatory=$false)] 211 | [switch] 212 | $Binding, 213 | 214 | [Parameter(Position=7, Mandatory=$false)] 215 | [switch] 216 | $VVAssociatedWithVM, 217 | 218 | [Parameter(Position=8, Mandatory=$false)] 219 | [switch] 220 | $RemoteCopy, 221 | 222 | [Parameter(Position=9, Mandatory=$false)] 223 | [switch] 224 | $AutoDismissed, 225 | 226 | [Parameter(Position=10, Mandatory=$false,ValueFromPipeline=$true)] 227 | [System.String] 228 | $VM_name, 229 | 230 | [Parameter(Position=11, Mandatory=$false, ValueFromPipeline=$true)] 231 | $SANConnection = $global:SANConnection 232 | ) 233 | 234 | Write-DebugLog "Start: In Show-vVolvm - validating input values" $Debug 235 | #check if connection object contents are null/empty 236 | if(!$SANConnection) 237 | { 238 | #check if connection object contents are null/empty 239 | $Validate1 = Test-CLIConnection $SANConnection 240 | if($Validate1 -eq "Failed") 241 | { 242 | #check if global connection object contents are null/empty 243 | $Validate2 = Test-CLIConnection $global:SANConnection 244 | if($Validate2 -eq "Failed") 245 | { 246 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" "ERR:" 247 | Write-DebugLog "Stop: Exiting Show-vVolvm since SAN connection object values are null/empty" $Debug 248 | return "Unable to execute the cmdlet Show-vVolvm since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 249 | } 250 | } 251 | } 252 | $plinkresult = Test-PARCli 253 | if($plinkresult -match "FAILURE :") 254 | { 255 | write-debuglog "$plinkresult" "ERR:" 256 | return $plinkresult 257 | } 258 | 259 | $cmd = "showvvolvm " 260 | 261 | if($ListCols) 262 | { 263 | $cmd +=" -listcols " 264 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $cmd 265 | write-debuglog " The Show-vVolvm command creates and admits physical disk definitions to enable the use of those disks " "INFO:" 266 | return $Result 267 | } 268 | if ($ShowCols) 269 | { 270 | $cmd +=" -showcols $ShowCols " 271 | } 272 | if ($Detailed) 273 | { 274 | $cmd +=" -d " 275 | } 276 | if ($StorageProfiles) 277 | { 278 | $cmd +=" -sp " 279 | } 280 | if ($Summary) 281 | { 282 | $cmd +=" -summary " 283 | } 284 | if ($Binding) 285 | { 286 | $cmd +=" -binding " 287 | } 288 | if ($VVAssociatedWithVM) 289 | { 290 | $cmd +=" -vv " 291 | } 292 | if ($RemoteCopy) 293 | { 294 | $cmd +=" -rcopy " 295 | } 296 | if ($AutoDismissed) 297 | { 298 | $cmd +=" -autodismissed " 299 | } 300 | if ($container_name) 301 | { 302 | $cmd+=" -sc $container_name " 303 | } 304 | else 305 | { 306 | return " FAILURE : container_name is mandatory to execute Show-vVolvm command " 307 | } 308 | if ($VM_name) 309 | { 310 | $cmd+=" $VM_name " 311 | } 312 | 313 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $cmd 314 | write-debuglog " The Show-vVolvm command creates and admits physical disk definitions to enable the use of those disks " "INFO:" 315 | return $Result 316 | } # End Show-vVolvm 317 | 318 | #################################################################################################################### 319 | ## FUNCTION Get-vVolSc 320 | #################################################################################################################### 321 | Function Get-vVolSc 322 | { 323 | <# 324 | .SYNOPSIS 325 | The Get-vVolSc command displays VVol storage containers, used to contain 326 | VMware Volumes for Virtual Machines (VVols). 327 | 328 | .DESCRIPTION 329 | The Get-vVolSc command displays VVol storage containers, used to contain 330 | VMware Volumes for Virtual Machines (VVols). 331 | 332 | .EXAMPLE 333 | Get-vVolSc 334 | 335 | .EXAMPLE 336 | Get-vVolSc -Detailed -SC_name test 337 | 338 | .PARAMETER Listcols 339 | List the columns available to be shown in the -showcols option described 340 | below. 341 | 342 | .PARAMETER Detailed 343 | Displays detailed information about the storage containers, including any 344 | VVols that have been auto-dismissed by remote copy DR operations. 345 | 346 | 347 | .PARAMETER SC_name 348 | Storage Container 349 | 350 | .PARAMETER SANConnection 351 | Specify the SAN Connection object created with New-CLIConnection or New-PoshSshConnection 352 | 353 | .Notes 354 | NAME: Get-vVolSc 355 | LASTEDIT: January 2020 356 | KEYWORDS: Get-vVolSc 357 | 358 | .Link 359 | http://www.hpe.com 360 | 361 | #Requires PS -Version 3.0 362 | 363 | #> 364 | [CmdletBinding()] 365 | param( 366 | 367 | [Parameter(Position=0, Mandatory=$false)] 368 | [switch] 369 | $Detailed, 370 | 371 | [Parameter(Position=1, Mandatory=$false)] 372 | [switch] 373 | $Listcols, 374 | 375 | [Parameter(Position=2, Mandatory=$false)] 376 | [System.String] 377 | $SC_name, 378 | 379 | [Parameter(Position=3, Mandatory=$false, ValueFromPipeline=$true)] 380 | $SANConnection = $global:SANConnection 381 | ) 382 | 383 | Write-DebugLog "Start: In Get-vVolSc - validating input values" $Debug 384 | #check if connection object contents are null/empty 385 | if(!$SANConnection) 386 | { 387 | #check if connection object contents are null/empty 388 | $Validate1 = Test-CLIConnection $SANConnection 389 | if($Validate1 -eq "Failed") 390 | { 391 | #check if global connection object contents are null/empty 392 | $Validate2 = Test-CLIConnection $global:SANConnection 393 | if($Validate2 -eq "Failed") 394 | { 395 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" "ERR:" 396 | Write-DebugLog "Stop: Exiting Get-vVolSc since SAN connection object values are null/empty" $Debug 397 | return "Unable to execute the cmdlet Get-vVolSc since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 398 | } 399 | } 400 | } 401 | $plinkresult = Test-PARCli 402 | if($plinkresult -match "FAILURE :") 403 | { 404 | write-debuglog "$plinkresult" "ERR:" 405 | return $plinkresult 406 | } 407 | $cmd= "showvvolsc " 408 | 409 | if ($Listcols) 410 | { 411 | $cmd+=" -listcols " 412 | } 413 | if ($Detailed) 414 | { 415 | $cmd+=" -d " 416 | } 417 | if ($SC_name) 418 | { 419 | $cmd+=" $SC_name " 420 | } 421 | 422 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $cmd 423 | write-debuglog " The Get-vVolSc command creates and admits physical disk definitions to enable the use of those disks " "INFO:" 424 | return $Result 425 | } # End Get-vVolSc 426 | 427 | #################################################################################################################### 428 | ## FUNCTION Set-VVolSC 429 | #################################################################################################################### 430 | Function Set-VVolSC 431 | { 432 | <# 433 | .SYNOPSIS 434 | Set-VVolSC can be used to create and remove storage containers for VMware Virtual Volumes (VVols). 435 | 436 | VVols are managed by the vSphere environment, and storage containers are 437 | used to maintain a logical collection of them. No physical space is 438 | pre-allocated for a storage container. Special VV sets (see showvvset) are 439 | used to manage VVol storage containers. 440 | 441 | .DESCRIPTION 442 | Set-VVolSC can be used to create and remove storage containers for 443 | VMware Virtual Volumes (VVols). 444 | 445 | VVols are managed by the vSphere environment, and storage containers are 446 | used to maintain a logical collection of them. No physical space is 447 | pre-allocated for a storage container. The special VV sets (see showvvset) 448 | are used to manage VVol storage containers. 449 | 450 | .EXAMPLE 451 | Set-VVolSC -vvset XYZ (Note: set: already include in code please dont add with vvset) 452 | 453 | .EXAMPLE 454 | Set-VVolSC -Create -vvset XYZ 455 | 456 | .PARAMETER Create 457 | An empty existing not already marked as a VVol Storage 458 | Container will be updated. The VV set should not contain any 459 | existing volumes (see -keep option below), must not be already 460 | marked as a storage container, nor may it be in use for other 461 | services, such as for remote copy groups, QoS, etc. 462 | 463 | .PARAMETER Remove 464 | If the specified VV set is a VVol storage container, this option will remove the VV set storage container and remove all of the associated volumes. The user will be asked to confirm that the associated volumes 465 | in this storage container should be removed. 466 | 467 | .PARAMETER Keep 468 | Used only with the -create option. If specified, allows a VV set with existing volumes to be marked as a VVol storage container. However, 469 | this option should only be used if the existing volumes in the VV set 470 | are VVols. 471 | 472 | .PARAMETER vvset 473 | The Virtual Volume set (VV set) name, which is used, or to be used, as a VVol storage container. 474 | 475 | .PARAMETER SANConnection 476 | Specify the SAN Connection object created with New-CLIConnection or New-PoshSshConnection 477 | 478 | .Notes 479 | NAME: Set-VVolSC 480 | LASTEDIT: 03/08/2017 481 | KEYWORDS: Set-VVolSC 482 | 483 | .Link 484 | http://www.hpe.com 485 | 486 | #Requires PS -Version 3.0 487 | 488 | #> 489 | [CmdletBinding()] 490 | param( 491 | 492 | [Parameter(Position=0, Mandatory=$false)] 493 | [System.String] 494 | $vvset, 495 | 496 | [Parameter(Position=1, Mandatory=$false)] 497 | [switch] 498 | $Create, 499 | 500 | [Parameter(Position=2, Mandatory=$false)] 501 | [switch] 502 | $Remove, 503 | 504 | [Parameter(Position=3, Mandatory=$false)] 505 | [switch] 506 | $Keep, 507 | 508 | [Parameter(Position=4, Mandatory=$false, ValueFromPipeline=$true)] 509 | $SANConnection = $global:SANConnection 510 | ) 511 | 512 | Write-DebugLog "Start: In Set-VVolSC - validating input values" $Debug 513 | #check if connection object contents are null/empty 514 | if(!$SANConnection) 515 | { 516 | #check if connection object contents are null/empty 517 | $Validate1 = Test-CLIConnection $SANConnection 518 | if($Validate1 -eq "Failed") 519 | { 520 | #check if global connection object contents are null/empty 521 | $Validate2 = Test-CLIConnection $global:SANConnection 522 | if($Validate2 -eq "Failed") 523 | { 524 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" "ERR:" 525 | Write-DebugLog "Stop: Exiting Set-VVolSC since SAN connection object values are null/empty" $Debug 526 | return "Unable to execute the cmdlet Set-VVolSC since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 527 | } 528 | } 529 | } 530 | $plinkresult = Test-PARCli 531 | if($plinkresult -match "FAILURE :") 532 | { 533 | write-debuglog "$plinkresult" "ERR:" 534 | return $plinkresult 535 | } 536 | $cmd= " setvvolsc -f" 537 | 538 | if ($Create) 539 | { 540 | $cmd += " -create " 541 | } 542 | if ($Remove) 543 | { 544 | $cmd += " -remove " 545 | } 546 | if($Keep) 547 | { 548 | $cmd += " -keep " 549 | } 550 | if ($vvset) 551 | { 552 | $cmd +=" set:$vvset " 553 | } 554 | else 555 | { 556 | return " FAILURE : vvset is mandatory to execute Set-VVolSC command" 557 | } 558 | 559 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $cmd 560 | write-debuglog " The Set-VVolSC command creates and admits physical disk definitions to enable the use of those disks" "INFO:" 561 | return $Result 562 | 563 | } # End Set-VVolSC 564 | 565 | Export-ModuleMember Show-vVolvm , Get-vVolSc , Set-VVolSC -------------------------------------------------------------------------------- /CLI/CimManagement.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: CimManagement.psm1 23 | ## Description: CIM Management cmdlets 24 | ## 25 | ## Created: May 2021 26 | ## Last Modified: May 2021 27 | ## History: v3.1 - Created 28 | ##################################################################################### 29 | 30 | $Info = "INFO:" 31 | $Debug = "DEBUG:" 32 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 33 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 34 | 35 | ############################################################################################################################################ 36 | ## FUNCTION Test-CLIObject 37 | ############################################################################################################################################ 38 | Function Test-CLIObject 39 | { 40 | Param( 41 | [string]$ObjectType, 42 | [string]$ObjectName , 43 | [string]$ObjectMsg = $ObjectType, 44 | $SANConnection = $global:SANConnection 45 | ) 46 | 47 | $IsObjectExisted = $True 48 | $ObjCmd = $ObjectType -replace ' ', '' 49 | $Cmds = "show$ObjCmd $ObjectName" 50 | 51 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $Cmds 52 | if ($Result -like "no $ObjectMsg listed") 53 | { 54 | $IsObjectExisted = $false 55 | } 56 | return $IsObjectExisted 57 | 58 | } # End FUNCTION Test-CLIObject 59 | 60 | #################################################################################################################### 61 | ## FUNCTION Show-CIM 62 | #################################################################################################################### 63 | Function Show-CIM { 64 | <# 65 | .SYNOPSIS 66 | Show the CIM server information 67 | . 68 | .DESCRIPTION 69 | The Show-CIM cmdlet displays the CIM server service state being configured, 70 | either enabled or disabled. It also displays the server current running 71 | status, either active or inactive. It displays the current status of the 72 | HTTP and HTTPS ports and their port numbers. In addition, it shows the 73 | current status of the SLP port, that is either enabled or disabled. 74 | 75 | .PARAMETER Pol 76 | Show CIM server policy information 77 | 78 | .EXAMPLES 79 | The following example shows the current CIM status: 80 | 81 | Show-CIM 82 | 83 | -Service- -State-- --SLP-- SLPPort -HTTP-- HTTPPort -HTTPS- HTTPSPort PGVer CIMVer 84 | Enabled Active Enabled 427 Enabled 5988 Enabled 5989 2.14.1 3.3.1 85 | 86 | The following example shows the current CIM policy: 87 | 88 | Show-CIM -Pol 89 | 90 | --------------Policy--------------- 91 | replica_entity,one_hwid_per_view,use_pegasus_interop_namespace,no_tls_strict 92 | 93 | .NOTES 94 | 95 | NAME: Show-CIM 96 | LASTEDIT: 25/04/2021 97 | KEYWORDS: Show-CIM 98 | 99 | .Link 100 | http://www.hpe.com 101 | 102 | #Requires PS -Version 3.0 103 | 104 | #> 105 | [CmdletBinding()] 106 | param( 107 | [Parameter(Position = 0, Mandatory = $false)] 108 | [Switch] 109 | $Pol, 110 | 111 | [Parameter(Position = 1, Mandatory = $false, ValueFromPipeline = $true)] 112 | $SANConnection = $global:SANConnection 113 | ) 114 | 115 | Write-DebugLog "Start: In Show-CIM - validating input values" $Debug 116 | #check if connection object contents are null/empty 117 | if (!$SANConnection) { 118 | #check if connection object contents are null/empty 119 | $Validate1 = Test-CLIConnection $SANConnection 120 | if ($Validate1 -eq "Failed") { 121 | #check if global connection object contents are null/empty 122 | $Validate2 = Test-CLIConnection $global:SANConnection 123 | if ($Validate2 -eq "Failed") { 124 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" "ERR:" 125 | Write-DebugLog "Stop: Exiting Show-CIM since SAN connection object values are null/empty" $Debug 126 | return "Unable to execute the cmdlet Show-CIM since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 127 | } 128 | } 129 | } 130 | $plinkresult = Test-PARCli 131 | if ($plinkresult -match "FAILURE :") { 132 | write-debuglog "$plinkresult" "ERR:" 133 | return $plinkresult 134 | } 135 | 136 | $cmd = "showcim " 137 | 138 | if ($Pol) { 139 | $cmd += " -pol " 140 | } 141 | 142 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $cmd 143 | 144 | write-debuglog " Executed the Show-CIM cmdlet" "INFO:" 145 | 146 | return $Result 147 | 148 | } # End Show-CIM 149 | 150 | #################################################################################################################### 151 | ## FUNCTION Start-CIM 152 | #################################################################################################################### 153 | Function Start-CIM { 154 | <# 155 | .SYNOPSIS 156 | Start the CIM server to service CIM requests 157 | . 158 | .DESCRIPTION 159 | The Start-CIM cmdlet starts the CIM server to service CIM requests. By 160 | default, the CIM server is not started until this command is issued. 161 | 162 | .EXAMPLES 163 | The following example starts the CIM server: 164 | 165 | Start-CIM 166 | CIM server will start shortly. 167 | 168 | .NOTES 169 | Access to all domains is required to run this command. 170 | 171 | By default, the CIM server is not started until this command is issued. 172 | 173 | Use Stop-CIM to stop the CIM server. 174 | 175 | NAME: Start-CIM 176 | LASTEDIT: 25/04/2021 177 | KEYWORDS: Start-CIM 178 | 179 | .Link 180 | http://www.hpe.com 181 | 182 | #Requires PS -Version 3.0 183 | 184 | #> 185 | [CmdletBinding()] 186 | param( 187 | [Parameter(Position = 0, Mandatory = $false, ValueFromPipeline = $true)] 188 | $SANConnection = $global:SANConnection 189 | ) 190 | 191 | Write-DebugLog "Start: In Start-CIM - validating input values" $Debug 192 | #check if connection object contents are null/empty 193 | if (!$SANConnection) { 194 | #check if connection object contents are null/empty 195 | $Validate1 = Test-CLIConnection $SANConnection 196 | if ($Validate1 -eq "Failed") { 197 | #check if global connection object contents are null/empty 198 | $Validate2 = Test-CLIConnection $global:SANConnection 199 | if ($Validate2 -eq "Failed") { 200 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" "ERR:" 201 | Write-DebugLog "Stop: Exiting Start-CIM since SAN connection object values are null/empty" $Debug 202 | return "Unable to execute the cmdlet Start-CIM since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 203 | } 204 | } 205 | } 206 | $plinkresult = Test-PARCli 207 | if ($plinkresult -match "FAILURE :") { 208 | write-debuglog "$plinkresult" "ERR:" 209 | return $plinkresult 210 | } 211 | $cmd = "startcim " 212 | 213 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $cmd 214 | 215 | write-debuglog " Executed the Start-CIM cmdlet" "INFO:" 216 | 217 | return $Result 218 | 219 | } # End Start-CIM 220 | 221 | #################################################################################################################### 222 | ## FUNCTION Set-CIM 223 | #################################################################################################################### 224 | Function Set-CIM { 225 | <# 226 | .SYNOPSIS 227 | Set the CIM server properties 228 | . 229 | .DESCRIPTION 230 | The Set-CIM cmdlet sets properties of the CIM server, including options to 231 | enable/disable the HTTP and HTTPS ports for the CIM server. setcim allows 232 | a user to enable/disable the SLP port. The command also sets the CIM server 233 | policy. 234 | 235 | .PARAMETER F 236 | Forces the operation of the setcim command, bypassing the typical 237 | confirmation message. 238 | 239 | .PARAMETER Slp 240 | Enables or disables the SLP port 427. 241 | 242 | .PARAMETER Http 243 | Enables or disables the HTTP port 5988 244 | 245 | .PARAMETER Https 246 | Enables or disables the HTTPS port 5989 247 | 248 | .PARAMETER Pol 249 | Sets the cim server policy: 250 | 251 | replica_entity - complies with SMI-S standard for usage of 252 | Replication Entity objects in associations. 253 | This is the default policy setting. 254 | no_replica_entity- does not comply with SMI-S standard for 255 | Replication Entity usage. Use only as directed 256 | by HPE support personnel or Release Notes. 257 | one_hwid_per_view - calling exposePaths with multiple 258 | initiatorPortIDs to create new view will result 259 | in the creation of multiple 260 | SCSCIProtocolControllers (SPC), one 261 | StorageHardwareID per SPC. Multiple hosts will 262 | be created each containing one FC WWN or 263 | iscsiname. This is the default policy setting. 264 | This is the default policy setting. 265 | no_one_hwid_per_view - calling exposePaths with multiple 266 | initiatorPortIDs to create new view will result 267 | in the creation of only one 268 | SCSCIProtocolController (SPC) that contains all 269 | the StorageHardwareIDs. One host will be created 270 | that contains all the FC WWNs or iscsinames. 271 | use_pegasus_interop_namespace - use the pegasus defined interop 272 | namespace root/PG_interop. This is the default 273 | policy setting. 274 | no_use_pegasus_interop_namespace - use the SMI-S conformant 275 | interop namespace root/interop. 276 | tls_strict - Only TLS connections using TLS 1.2 with 277 | secure ciphers will be accepted if HTTPS is 278 | enabled. 279 | no_tls_strict - TLS connections using TLS 1.0 - 1.2 will be 280 | accepted if HTTPS is enabled. This is the 281 | default policy setting. 282 | 283 | .EXAMPLES 284 | To disable the HTTPS ports: 285 | 286 | Set-CIM -F -Https Disable 287 | 288 | To enable the HTTPS port: 289 | 290 | Set-CIM -F -Https Enable 291 | 292 | To disable the HTTP port and enable the HTTPS port: 293 | 294 | Set-CIM -F -Http Disable -Https Enable 295 | 296 | To set the no_use_pegasus_interop_namespace policy: 297 | 298 | Set-CIM -F -Pol no_use_pegasus_interop_namespace 299 | 300 | To set the replica_entity policy: 301 | 302 | Set-CIM -F -Pol replica_entity 303 | 304 | .NOTES 305 | Access to all domains is required to run this command. 306 | 307 | You cannot disable both of the HTTP and HTTPS ports. 308 | 309 | When the CIM server is active, a warning message will be prompted to inform 310 | you of the current status of the CIM server and asks for the confirmation to 311 | continue or not. The -F option forces the action without a warning message. 312 | 313 | NAME: Set-CIM 314 | LASTEDIT: 25/04/2021 315 | KEYWORDS: Set-CIM 316 | 317 | .Link 318 | http://www.hpe.com 319 | 320 | #Requires PS -Version 3.0 321 | 322 | #> 323 | [CmdletBinding()] 324 | param( 325 | [Parameter(Position = 0, Mandatory = $false, HelpMessage = "To forces the operation")] 326 | [Switch] 327 | $F, 328 | 329 | [Parameter(Position = 1, Mandatory = $false, HelpMessage = "To enables or disables the SLP port 427")] 330 | [ValidateSet("enable", "disable")] 331 | [System.String] 332 | $Slp, 333 | 334 | [Parameter(Position = 2, Mandatory = $false, HelpMessage = "To enables or disables the HTTP port 5988")] 335 | [ValidateSet("enable", "disable")] 336 | [System.String] 337 | $Http, 338 | 339 | [Parameter(Position = 3, Mandatory = $false, HelpMessage = "To enables or disables the HTTPS port 5989")] 340 | [ValidateSet("enable", "disable")] 341 | [System.String] 342 | $Https, 343 | 344 | [Parameter(Position = 4, Mandatory = $false, HelpMessage = "To sets the cim server policy")] 345 | [ValidateSet("replica_entity", "no_replica_entity", "one_hwid_per_view", "no_one_hwid_per_view", "use_pegasus_interop_namespace", "no_use_pegasus_interop_namespace", "tls_strict", "no_tls_strict")] 346 | [System.String] 347 | $Pol, 348 | 349 | [Parameter(Position = 5, Mandatory = $false, ValueFromPipeline = $true)] 350 | $SANConnection = $global:SANConnection 351 | ) 352 | 353 | Write-DebugLog "Start: In Set-CIM - validating input values" $Debug 354 | #check if connection object contents are null/empty 355 | if (!$SANConnection) { 356 | #check if connection object contents are null/empty 357 | $Validate1 = Test-CLIConnection $SANConnection 358 | if ($Validate1 -eq "Failed") { 359 | #check if global connection object contents are null/empty 360 | $Validate2 = Test-CLIConnection $global:SANConnection 361 | if ($Validate2 -eq "Failed") { 362 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" "ERR:" 363 | Write-DebugLog "Stop: Exiting Set-CIM since SAN connection object values are null/empty" $Debug 364 | return "Unable to execute the cmdlet Set-CIM since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 365 | } 366 | } 367 | } 368 | $plinkresult = Test-PARCli 369 | if ($plinkresult -match "FAILURE :") { 370 | write-debuglog "$plinkresult" "ERR:" 371 | return $plinkresult 372 | } 373 | 374 | $cmd = "setcim " 375 | 376 | if ($F) { 377 | $cmd += " -f " 378 | } 379 | else { 380 | Return "Force set option is only supported with the Set-CIM cmdlet." 381 | } 382 | 383 | if (($Slp) -or ($Http) -or ($Https) -or ($Pol)) { 384 | 385 | if ($Slp) { 386 | $cmd += " -slp $Slp" 387 | } 388 | 389 | if ($Http) { 390 | $cmd += " -http $Http" 391 | } 392 | 393 | if ($Https) { 394 | $cmd += " -https $Https" 395 | } 396 | 397 | if ($Pol) { 398 | $cmd += " -pol $Pol" 399 | } 400 | } 401 | else { 402 | Return "At least one of the options -Slp, -Http, -Https, or -Pol are required." 403 | } 404 | 405 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $cmd 406 | 407 | write-debuglog " Executed the Set-CIM cmdlet" "INFO:" 408 | 409 | return $Result 410 | 411 | } # End Set-CIM 412 | 413 | #################################################################################################################### 414 | ## FUNCTION Stop-CIM 415 | #################################################################################################################### 416 | Function Stop-CIM { 417 | <# 418 | .SYNOPSIS 419 | Stop the CIM server. Future CIM requests will be not supported. 420 | . 421 | .DESCRIPTION 422 | The Stop-CIM cmdlet stops the CIM server from servicing CIM requests. 423 | 424 | .PARAMETER F 425 | Specifies that the operation is forced. If this option is not used, 426 | the command requires confirmation before proceeding with its 427 | operation. 428 | 429 | .PARAMETER X 430 | Specifies that the operation terminates the server immediately 431 | without graceful shutdown notice. 432 | 433 | .EXAMPLES 434 | The following example stops the CIM server without confirmation 435 | 436 | Stop-CIM -F 437 | 438 | The following example stops the CIM server immediately without graceful 439 | shutdown notice and confirmation: 440 | 441 | Stop-CIM -F -X 442 | 443 | .NOTES 444 | Access to all domains is required to run this command. 445 | By default, the CIM server is not started until the Start-CIM cmdlet is issued. 446 | 447 | NAME: Stop-CIM 448 | LASTEDIT: 25/04/2021 449 | KEYWORDS: Stop-CIM 450 | 451 | .Link 452 | http://www.hpe.com 453 | 454 | #Requires PS -Version 3.0 455 | 456 | #> 457 | [CmdletBinding()] 458 | param( 459 | [Parameter(Position = 0, Mandatory = $false, HelpMessage = "To forces the operation")] 460 | [Switch] 461 | $F, 462 | 463 | [Parameter(Position = 1, Mandatory = $false, HelpMessage = "To terminates the server immediately without graceful shutdown notice")] 464 | [Switch] 465 | $X, 466 | 467 | [Parameter(Position = 5, Mandatory = $false, ValueFromPipeline = $true)] 468 | $SANConnection = $global:SANConnection 469 | ) 470 | 471 | Write-DebugLog "Start: In Stop-CIM - validating input values" $Debug 472 | #check if connection object contents are null/empty 473 | if (!$SANConnection) { 474 | #check if connection object contents are null/empty 475 | $Validate1 = Test-CLIConnection $SANConnection 476 | if ($Validate1 -eq "Failed") { 477 | #check if global connection object contents are null/empty 478 | $Validate2 = Test-CLIConnection $global:SANConnection 479 | if ($Validate2 -eq "Failed") { 480 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" "ERR:" 481 | Write-DebugLog "Stop: Exiting Stop-CIM since SAN connection object values are null/empty" $Debug 482 | return "Unable to execute the cmdlet Stop-CIM since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 483 | } 484 | } 485 | } 486 | $plinkresult = Test-PARCli 487 | if ($plinkresult -match "FAILURE :") { 488 | write-debuglog "$plinkresult" "ERR:" 489 | return $plinkresult 490 | } 491 | 492 | $cmd = "setcim " 493 | 494 | if ($F) { 495 | $cmd += " -f " 496 | } 497 | else { 498 | Return "Force set option is only supported with the Stop-CIM cmdlet." 499 | } 500 | 501 | if ($X) { 502 | $cmd += " -x " 503 | } 504 | 505 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $cmd 506 | 507 | write-debuglog " Executed the Stop-CIM cmdlet" "INFO:" 508 | 509 | return $Result 510 | 511 | } # End Stop-CIM 512 | 513 | Export-ModuleMember Show-CIM , Start-CIM , Set-CIM , Stop-CIM -------------------------------------------------------------------------------- /WSAPI/VirtualLUNs.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: VirtualLUNs.psm1 23 | ## Description: Virtual LUNs cmdlets 24 | ## 25 | ## Created: February 2020 26 | ## Last Modified: February 2020 27 | ## History: v3.0 - Created 28 | ##################################################################################### 29 | 30 | $Info = "INFO:" 31 | $Debug = "DEBUG:" 32 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 33 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 34 | 35 | ############################################################################################################################################ 36 | ## FUNCTION New-vLun_WSAPI 37 | ############################################################################################################################################ 38 | Function New-vLun_WSAPI 39 | { 40 | <# 41 | 42 | .SYNOPSIS 43 | Creating a VLUN 44 | 45 | .DESCRIPTION 46 | Creating a VLUN 47 | Any user with Super or Edit role, or any role granted vlun_create permission, can perform this operation. 48 | 49 | .EXAMPLE 50 | New-vLun_WSAPI -VolumeName xxx -LUNID x -HostName xxx 51 | 52 | .EXAMPLE 53 | New-vLun_WSAPI -VolumeName xxx -LUNID x -HostName xxx -NSP 1:1:1 54 | 55 | .PARAMETER VolumeName 56 | Name of the volume or VV set to export. 57 | 58 | .PARAMETER LUNID 59 | LUN ID. 60 | 61 | .PARAMETER HostName 62 | Name of the host or host set to which the volume or VV set is to be exported. 63 | The host set should be in set:hostset_name format. 64 | 65 | .PARAMETER NSP 66 | System port of VLUN exported to. It includes node number, slot number, and card port number. 67 | 68 | .PARAMETER NoVcn 69 | Specifies that a VCN not be issued after export (-novcn). Default: false. 70 | 71 | .PARAMETER WsapiConnection 72 | WSAPI Connection object created with Connection command 73 | 74 | .Notes 75 | NAME : New-vLun_WSAPI 76 | LASTEDIT: February 2020 77 | KEYWORDS: New-vLun_WSAPI 78 | 79 | .Link 80 | http://www.hpe.com 81 | 82 | #Requires PS -Version 3.0 83 | 84 | #> 85 | [CmdletBinding()] 86 | Param( 87 | [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] 88 | [System.String] 89 | $VolumeName, 90 | 91 | [Parameter(Position=1, Mandatory=$true, ValueFromPipeline=$true)] 92 | [int] 93 | $LUNID, 94 | 95 | [Parameter(Position=2, Mandatory=$true, ValueFromPipeline=$true)] 96 | [System.String] 97 | $HostName, 98 | 99 | [Parameter(Position=3, Mandatory=$false, ValueFromPipeline=$true)] 100 | [System.String] 101 | $NSP, 102 | 103 | [Parameter(Position=4, Mandatory=$false, ValueFromPipeline=$true)] 104 | [Boolean] 105 | $NoVcn = $false, 106 | 107 | [Parameter(Position=5, Mandatory=$false, ValueFromPipeline=$true)] 108 | $WsapiConnection = $global:WsapiConnection 109 | ) 110 | 111 | Begin 112 | { 113 | # Test if connection exist 114 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 115 | } 116 | 117 | Process 118 | { 119 | # Creation of the body hash 120 | Write-DebugLog "Running: Creation of the body hash" $Debug 121 | $body = @{} 122 | 123 | If ($VolumeName) 124 | { 125 | $body["volumeName"] ="$($VolumeName)" 126 | } 127 | If ($LUNID) 128 | { 129 | $body["lun"] =$LUNID 130 | } 131 | If ($HostName) 132 | { 133 | $body["hostname"] ="$($HostName)" 134 | } 135 | If ($NSP) 136 | { 137 | $NSPbody = @{} 138 | 139 | $list = $NSP.split(":") 140 | 141 | $NSPbody["node"] = [int]$list[0] 142 | $NSPbody["slot"] = [int]$list[1] 143 | $NSPbody["cardPort"] = [int]$list[2] 144 | 145 | $body["portPos"] = $NSPbody 146 | } 147 | If ($NoVcn) 148 | { 149 | $body["noVcn"] = $NoVcn 150 | } 151 | 152 | 153 | $Result = $null 154 | 155 | #Request 156 | $Result = Invoke-WSAPI -uri '/vluns' -type 'POST' -body $body -WsapiConnection $WsapiConnection 157 | $status = $Result.StatusCode 158 | if($status -eq 201) 159 | { 160 | write-host "" 161 | write-host "Cmdlet executed successfully" -foreground green 162 | #write-host "SUCCESS: Status Code : $Result.StatusCode ." -foreground green 163 | #write-host "SUCCESS: Status Description : $Result.StatusDescription." -foreground green 164 | write-host "" 165 | Write-DebugLog "SUCCESS: Successfully Created a VLUN" $Info 166 | Get-vLun_WSAPI -VolumeName $VolumeName -LUNID $LUNID -HostName $HostName 167 | 168 | Write-DebugLog "End: New-vLun_WSAPI" $Debug 169 | } 170 | else 171 | { 172 | write-host "" 173 | write-host "FAILURE : While Creating a VLUN" -foreground red 174 | write-host "" 175 | Write-DebugLog "FAILURE : Creating a VLUN" $Info 176 | Write-DebugLog "End: New-vLun_WSAPI" $Debug 177 | 178 | return $Result.StatusDescription 179 | } 180 | } 181 | End 182 | { 183 | } 184 | } 185 | #ENG New-vLun_WSAPI 186 | 187 | ############################################################################################################################################ 188 | ## FUNCTION Remove-vLun_WSAPI 189 | ############################################################################################################################################ 190 | Function Remove-vLun_WSAPI 191 | { 192 | <# 193 | 194 | .SYNOPSIS 195 | Removing a VLUN. 196 | 197 | .DESCRIPTION 198 | Removing a VLUN 199 | Any user with the Super or Edit role, or any role granted with the vlun_remove right, can perform this operation. 200 | 201 | .EXAMPLE 202 | Remove-vLun_WSAPI -VolumeName xxx -LUNID xx -HostName xxx 203 | 204 | .EXAMPLE 205 | Remove-vLun_WSAPI -VolumeName xxx -LUNID xx -HostName xxx -NSP x:x:x 206 | 207 | .PARAMETER VolumeName 208 | Name of the volume or VV set to be exported. 209 | The VV set should be in set: format. 210 | 211 | .PARAMETER LUNID 212 | Lun Id 213 | 214 | .PARAMETER HostName 215 | Name of the host or host set to which the volume or VV set is to be exported. For VLUN of port type, the value is empty. 216 | The host set should be in set: format.required if volume is exported to host or host set,or to both the host or host set and port 217 | 218 | .PARAMETER NSP 219 | Specifies the system port of the VLUN export. It includes the system node number, PCI bus slot number, and card port number on the FC card in the format::: 220 | required if volume is exported to port, or to both host and port .Notes NAME : Remove-vLun_WSAPI 221 | 222 | .PARAMETER WsapiConnection 223 | WSAPI Connection object created with Connection command 224 | 225 | .Notes 226 | NAME : Remove-vLun_WSAPI 227 | LASTEDIT: February 2020 228 | KEYWORDS: Remove-vLun_WSAPI 229 | 230 | .Link 231 | http://www.hpe.com 232 | 233 | #Requires PS -Version 3.0 234 | 235 | #> 236 | [CmdletBinding(SupportsShouldProcess = $True,ConfirmImpact = 'High')] 237 | Param( 238 | [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] 239 | [System.String] 240 | $VolumeName, 241 | 242 | [Parameter(Position=1, Mandatory=$true, ValueFromPipeline=$true)] 243 | [int] 244 | $LUNID, 245 | 246 | [Parameter(Position=2, Mandatory=$true, ValueFromPipeline=$true)] 247 | [System.String] 248 | $HostName, 249 | 250 | [Parameter(Position=3, Mandatory=$false, ValueFromPipeline=$true)] 251 | [System.String] 252 | $NSP, 253 | 254 | [Parameter(Position=4, Mandatory=$false, ValueFromPipeline=$true)] 255 | $WsapiConnection = $global:WsapiConnection 256 | ) 257 | 258 | Begin 259 | { 260 | # Test if connection exist 261 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 262 | } 263 | 264 | Process 265 | { 266 | #Build uri 267 | Write-DebugLog "Running: Building uri to Remove-vLun_WSAPI ." $Debug 268 | $uri = "/vluns/"+$VolumeName+","+$LUNID+","+$HostName 269 | 270 | if($NSP) 271 | { 272 | $uri = $uri+","+$NSP 273 | } 274 | 275 | #init the response var 276 | $Result = $null 277 | 278 | #Request 279 | Write-DebugLog "Request: Request to Remove-vLun_WSAPI : $CPGName (Invoke-WSAPI)." $Debug 280 | $Result = Invoke-WSAPI -uri $uri -type 'DELETE' -WsapiConnection $WsapiConnection 281 | 282 | $status = $Result.StatusCode 283 | if($status -eq 200) 284 | { 285 | write-host "" 286 | write-host "Cmdlet executed successfully" -foreground green 287 | write-host "" 288 | Write-DebugLog "SUCCESS: VLUN Successfully removed with Given Values [ VolumeName : $VolumeName | LUNID : $LUNID | HostName : $HostName | NSP : $NSP ]." $Info 289 | Write-DebugLog "End: Remove-vLun_WSAPI" $Debug 290 | return $Result 291 | } 292 | else 293 | { 294 | write-host "" 295 | write-host "FAILURE : While Removing VLUN with Given Values [ VolumeName : $VolumeName | LUNID : $LUNID | HostName : $HostName | NSP : $NSP ]. " -foreground red 296 | write-host "" 297 | Write-DebugLog "FAILURE : While Removing VLUN with Given Values [ VolumeName : $VolumeName | LUNID : $LUNID | HostName : $HostName | NSP : $NSP ]." $Info 298 | Write-DebugLog "End: Remove-vLun_WSAPI" $Debug 299 | 300 | return $Result.StatusDescription 301 | } 302 | 303 | } 304 | End {} 305 | } 306 | #END Remove-vLun_WSAPI 307 | 308 | ############################################################################################################################################ 309 | ## FUNCTION Get-vLun_WSAPI 310 | ############################################################################################################################################ 311 | Function Get-vLun_WSAPI 312 | { 313 | <# 314 | .SYNOPSIS 315 | Get Single or list of VLun. 316 | 317 | .DESCRIPTION 318 | Get Single or list of VLun 319 | 320 | .EXAMPLE 321 | Get-vLun_WSAPI 322 | Display a list of VLun. 323 | 324 | .EXAMPLE 325 | Get-vLun_WSAPI -VolumeName xxx -LUNID x -HostName xxx 326 | Display a list of VLun. 327 | 328 | .PARAMETER VolumeName 329 | Name of the volume to be exported. 330 | 331 | .PARAMETER LUNID 332 | Lun 333 | 334 | .PARAMETER HostName 335 | Name of the host to which the volume is to be exported. For VLUN of port type, the value is empty. 336 | 337 | .PARAMETER NSP 338 | The variable identifies the node, slot, and port of the device. 339 | 340 | .PARAMETER WsapiConnection 341 | WSAPI Connection object created with Connection command 342 | 343 | .Notes 344 | NAME : Get-vLun_WSAPI 345 | LASTEDIT: February 2020 346 | KEYWORDS: Get-vLun_WSAPI 347 | 348 | .Link 349 | http://www.hpe.com 350 | 351 | #Requires PS -Version 3.0 352 | #> 353 | 354 | [CmdletBinding()] 355 | Param( 356 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 357 | [System.String] 358 | $Vlun_id, 359 | 360 | [Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)] 361 | [System.String] 362 | $VolumeName, 363 | 364 | [Parameter(Position=2, Mandatory=$false, ValueFromPipeline=$true)] 365 | [int] 366 | $LUNID, 367 | 368 | [Parameter(Position=3, Mandatory=$false, ValueFromPipeline=$true)] 369 | [System.String] 370 | $HostName, 371 | 372 | [Parameter(Position=4, Mandatory=$false, ValueFromPipeline=$true)] 373 | [System.String] 374 | $NSP, 375 | 376 | [Parameter(Position=5, Mandatory=$false, ValueFromPipeline=$true)] 377 | $WsapiConnection = $global:WsapiConnection 378 | ) 379 | 380 | Begin 381 | { 382 | # Test if connection exist 383 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 384 | } 385 | 386 | Process 387 | { 388 | Write-DebugLog "Request: Request to Get-vLun_WSAPI [ VolumeName : $VolumeName | LUNID : $LUNID | HostName : $HostName | NSP : $NSP] (Invoke-WSAPI)." $Debug 389 | #Request 390 | 391 | $Result = $null 392 | $dataPS = $null 393 | $uri = "/vluns/"+$Vlun_id+"/" 394 | # Results 395 | if($VolumeName) 396 | { 397 | #Build uri 398 | $uri = $uri+$VolumeName 399 | } 400 | if($LUNID) 401 | { 402 | if($VolumeName) 403 | { 404 | #Build uri 405 | $uri = $uri+","+$LUNID 406 | } 407 | else 408 | { 409 | $uri = $uri+$LUNID 410 | } 411 | 412 | } 413 | if($HostName) 414 | { 415 | if($VolumeName -Or $LUNID) 416 | { 417 | #Build uri 418 | $uri = $uri+","+$HostName 419 | } 420 | else 421 | { 422 | $uri = $uri+$HostName 423 | } 424 | } 425 | if($NSP) 426 | { 427 | if($VolumeName -Or $LUNID -Or $HostName) 428 | { 429 | #Build uri 430 | $uri = $uri+","+$NSP 431 | } 432 | else 433 | { 434 | $uri = $uri+$NSP 435 | } 436 | } 437 | if($Vlun_id -Or $VolumeName -Or $LUNID -Or $HostName -Or $NSP) 438 | { 439 | #Request 440 | $Result = Invoke-WSAPI -uri $uri -type 'GET' -WsapiConnection $WsapiConnection 441 | If($Result.StatusCode -eq 200) 442 | { 443 | $dataPS = ($Result.content | ConvertFrom-Json).members 444 | } 445 | } 446 | else 447 | { 448 | #Request 449 | $Result = Invoke-WSAPI -uri '/vluns' -type 'GET' -WsapiConnection $WsapiConnection 450 | If($Result.StatusCode -eq 200) 451 | { 452 | $dataPS = ($Result.content | ConvertFrom-Json).members 453 | } 454 | } 455 | 456 | If($Result.StatusCode -eq 200) 457 | { 458 | if($dataPS.Count -gt 0) 459 | { 460 | write-host "" 461 | write-host "Cmdlet executed successfully" -foreground green 462 | write-host "" 463 | Write-DebugLog "SUCCESS: Get-vLun_WSAPI successfully Executed." $Info 464 | 465 | return $dataPS 466 | } 467 | else 468 | { 469 | write-host "" 470 | write-host "FAILURE : While Executing Get-vLun_WSAPI. Expected Result Not Found [ VolumeName : $VolumeName | LUNID : $LUNID | HostName : $HostName | NSP : $NSP]." -foreground red 471 | write-host "" 472 | Write-DebugLog "FAILURE : While Executing Get-vLun_WSAPI. Expected Result Not Found [ VolumeName : $VolumeName | LUNID : $LUNID | HostName : $HostName | NSP : $NSP]" $Info 473 | 474 | return 475 | } 476 | } 477 | else 478 | { 479 | write-host "" 480 | write-host "FAILURE : While Executing Get-vLun_WSAPI." -foreground red 481 | write-host "" 482 | Write-DebugLog "FAILURE : While Executing Get-vLun_WSAPI. " $Info 483 | 484 | return $Result.StatusDescription 485 | } 486 | } 487 | End {} 488 | }#END Get-vLun_WSAPI 489 | 490 | 491 | ############################################################################################################################################ 492 | ## FUNCTION Get-vLunUsingFilters_WSAPI 493 | ############################################################################################################################################ 494 | Function Get-vLunUsingFilters_WSAPI 495 | { 496 | <# 497 | .SYNOPSIS 498 | Get VLUNs using filters. 499 | 500 | .DESCRIPTION 501 | Get VLUNs using filters. 502 | Available filters for VLUN queries 503 | Use the following filters to query VLUNs: 504 | • volumeWWN 505 | • remoteName 506 | • volumeName 507 | • hostname 508 | • serial 509 | 510 | .EXAMPLE 511 | Get-vLunUsingFilters_WSAPI -VolumeWWN "xxx" 512 | 513 | .EXAMPLE 514 | Get-vLunUsingFilters_WSAPI -VolumeWWN "xxx,yyy,zzz" 515 | 516 | .EXAMPLE 517 | Get-vLunUsingFilters_WSAPI -RemoteName "xxx" 518 | 519 | .EXAMPLE 520 | Get-vLunUsingFilters_WSAPI -RemoteName "xxx,yyy,zzz" 521 | 522 | .EXAMPLE 523 | Get-vLunUsingFilters_WSAPI -RemoteName "xxx" -VolumeWWN "xxx" 524 | Supporting single or multipule values using "," 525 | 526 | .EXAMPLE 527 | Get-vLunUsingFilters_WSAPI -RemoteName "xxx" -VolumeWWN "xxx" -VolumeName "xxx" 528 | Supporting single or multipule values using "," 529 | 530 | .EXAMPLE 531 | Get-vLunUsingFilters_WSAPI -RemoteName "xxx" -VolumeWWN "xxx" -VolumeName "xxx" -HostName "xxx" 532 | Supporting single or multipule values using "," 533 | 534 | .EXAMPLE 535 | Get-vLunUsingFilters_WSAPI -RemoteName "xxx" -VolumeWWN "xxx" -VolumeName "xxx" -HostName "xxx" -Serial "xxx" 536 | Supporting single or multipule values using "," 537 | 538 | .PARAMETER VolumeWWN 539 | The value of is the WWN of the exported volume 540 | 541 | .PARAMETER RemoteName 542 | the value is the host WWN or an iSCSI pathname. 543 | 544 | .PARAMETER VolumeName 545 | Volume Name 546 | 547 | .PARAMETER HostName 548 | Host Name 549 | 550 | .PARAMETER Serial 551 | To Get volumes using a serial number 552 | 553 | .PARAMETER WsapiConnection 554 | WSAPI Connection object created with Connection command 555 | 556 | .Notes 557 | NAME : Get-vLunUsingFilters_WSAPI 558 | LASTEDIT: February 2020 559 | KEYWORDS: Get-vLunUsingFilters_WSAPI 560 | 561 | .Link 562 | http://www.hpe.com 563 | 564 | #Requires PS -Version 3.0 565 | #> 566 | 567 | [CmdletBinding()] 568 | Param( 569 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 570 | [System.String] 571 | $VolumeWWN, 572 | 573 | [Parameter(Position=2, Mandatory=$false, ValueFromPipeline=$true)] 574 | [System.String] 575 | $RemoteName, 576 | 577 | [Parameter(Position=3, Mandatory=$false, ValueFromPipeline=$true)] 578 | [System.String] 579 | $VolumeName, 580 | 581 | [Parameter(Position=4, Mandatory=$false, ValueFromPipeline=$true)] 582 | [System.String] 583 | $HostName, 584 | 585 | [Parameter(Position=5, Mandatory=$false, ValueFromPipeline=$true)] 586 | [System.String] 587 | $Serial, 588 | 589 | [Parameter(Position=6, Mandatory=$false, ValueFromPipeline=$true)] 590 | $WsapiConnection = $global:WsapiConnection 591 | ) 592 | 593 | Begin 594 | { 595 | # Test if connection exist 596 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 597 | } 598 | 599 | Process 600 | { 601 | Write-DebugLog "Request: Request to Get-vLunUsingFilters_WSAPI VVSetName : $VVSetName (Invoke-WSAPI)." $Debug 602 | #Request 603 | 604 | $Result = $null 605 | $dataPS = $null 606 | $Query="?query="" """ 607 | 608 | # Results 609 | if($VolumeWWN) 610 | { 611 | $Query = LoopingFunction -Value $VolumeWWN -condition "volumeWWN" -flg $false -Query $Query 612 | } 613 | if($RemoteName) 614 | { 615 | if($VolumeWWN) 616 | { 617 | $Query = LoopingFunction -Value $RemoteName -condition "remoteName" -flg $true -Query $Query 618 | } 619 | else 620 | { 621 | $Query = LoopingFunction -Value $RemoteName -condition "remoteName" -flg $false -Query $Query 622 | } 623 | } 624 | if($VolumeName) 625 | { 626 | if($VolumeWWN -or $RemoteName) 627 | { 628 | $Query = LoopingFunction -Value $VolumeName -condition "volumeName" -flg $true -Query $Query 629 | } 630 | else 631 | { 632 | $Query = LoopingFunction -Value $VolumeName -condition "volumeName" -flg $false -Query $Query 633 | } 634 | } 635 | if($HostName) 636 | { 637 | if($VolumeWWN -or $RemoteName -or $VolumeName) 638 | { 639 | $Query = LoopingFunction -Value $HostName -condition "hostname" -flg $true -Query $Query 640 | } 641 | else 642 | { 643 | $Query = LoopingFunction -Value $HostName -condition "hostname" -flg $false -Query $Query 644 | } 645 | } 646 | if($Serial) 647 | { 648 | if($VolumeWWN -or $RemoteName -or $VolumeName -or $HostName) 649 | { 650 | $Query = LoopingFunction -Value $Serial -condition "serial" -flg $true -Query $Query 651 | } 652 | else 653 | { 654 | $Query = LoopingFunction -Value $Serial -condition "serial" -flg $false -Query $Query 655 | } 656 | } 657 | 658 | if($VolumeWWN -or $RemoteName -or $VolumeName -or $HostName -or $Serial) 659 | { 660 | #Build uri 661 | $uri = '/vluns/'+$Query 662 | 663 | #write-host "uri = $uri" 664 | 665 | #Request 666 | $Result = Invoke-WSAPI -uri $uri -type 'GET' -WsapiConnection $WsapiConnection 667 | If($Result.StatusCode -eq 200) 668 | { 669 | $dataPS = ($Result.content | ConvertFrom-Json).members 670 | } 671 | } 672 | 673 | If($Result.StatusCode -eq 200) 674 | { 675 | if($dataPS.Count -gt 0) 676 | { 677 | write-host "" 678 | write-host "Cmdlet executed successfully" -foreground green 679 | write-host "" 680 | Write-DebugLog "SUCCESS: Get-vLunUsingFilters_WSAPI successfully Executed." $Info 681 | 682 | return $dataPS 683 | } 684 | else 685 | { 686 | write-host "" 687 | write-host "FAILURE : While Executing Get-vLunUsingFilters_WSAPI. Expected Result Not Found with Given Filter Option : VolumeWWN/$VolumeWWN RemoteName/$RemoteName VolumeName/$VolumeName HostName/$HostName Serial/$Serial." -foreground red 688 | write-host "" 689 | Write-DebugLog "FAILURE : While Executing Get-vLunUsingFilters_WSAPI. Expected Result Not Found with Given Filter Option : VolumeWWN/$VolumeWWN RemoteName/$RemoteName VolumeName/$VolumeName HostName/$HostName Serial/$Serial." $Info 690 | 691 | return 692 | } 693 | } 694 | else 695 | { 696 | write-host "" 697 | write-host "FAILURE : While Executing Get-vLunUsingFilters_WSAPI." -foreground red 698 | write-host "" 699 | Write-DebugLog "FAILURE : While Executing Get-vLunUsingFilters_WSAPI. " $Info 700 | 701 | return $Result.StatusDescription 702 | } 703 | } 704 | End {} 705 | }#END Get-vLunUsingFilters_WSAPI 706 | 707 | 708 | Export-ModuleMember New-vLun_WSAPI , Remove-vLun_WSAPI , Get-vLun_WSAPI , Get-vLunUsingFilters_WSAPI -------------------------------------------------------------------------------- /CLI/TaskManagement.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: TaskManagement.psm1 23 | ## Description: Task Management cmdlets 24 | ## 25 | ## Created: January 2020 26 | ## Last Modified: January 2020 27 | ## History: v3.0 - Created 28 | ##################################################################################### 29 | 30 | $Info = "INFO:" 31 | $Debug = "DEBUG:" 32 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 33 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 34 | 35 | ############################################################################################################################################ 36 | ## FUNCTION Test-CLIObject 37 | ############################################################################################################################################ 38 | Function Test-CLIObject 39 | { 40 | Param( 41 | [string]$ObjectType, 42 | [string]$ObjectName , 43 | [string]$ObjectMsg = $ObjectType, 44 | $SANConnection = $global:SANConnection 45 | ) 46 | 47 | $IsObjectExisted = $True 48 | $ObjCmd = $ObjectType -replace ' ', '' 49 | $Cmds = "show$ObjCmd $ObjectName" 50 | 51 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $Cmds 52 | if ($Result -like "no $ObjectMsg listed") 53 | { 54 | $IsObjectExisted = $false 55 | } 56 | return $IsObjectExisted 57 | 58 | } # End FUNCTION Test-CLIObject 59 | 60 | ############################################################################ 61 | ########################### Function Get-Task ############################## 62 | ############################################################################ 63 | Function Get-Task 64 | { 65 | <# 66 | .SYNOPSIS 67 | Displays information about tasks. 68 | 69 | .DESCRIPTION 70 | Displays information about tasks. 71 | 72 | .EXAMPLE 73 | Get-Task 74 | Display all tasks. 75 | 76 | .EXAMPLE 77 | Get-Task -All 78 | Display all tasks. Unless the -all option is specified, system tasks 79 | are not displayed. 80 | 81 | .EXAMPLE 82 | Get-Task -Done 83 | Display includes only tasks that are successfully completed 84 | 85 | .EXAMPLE 86 | Get-Task -Failed 87 | Display includes only tasks that are unsuccessfully completed. 88 | 89 | .EXAMPLE 90 | Get-Task -Active 91 | Display includes only tasks that are currently in progress. 92 | 93 | .EXAMPLE 94 | Get-Task -Hours 10 95 | Show only tasks started within the past 96 | 97 | .EXAMPLE 98 | Get-Task -Task_type xyz 99 | Specifies that specified patterns are treated as glob-style patterns and that all tasks whose types match the specified pattern are displayed 100 | 101 | .EXAMPLE 102 | Get-Task -taskID 4 103 | Show detailed task status for specified task 4. 104 | 105 | .PARAMETER All 106 | Displays all tasks. 107 | 108 | .PARAMETER Done 109 | Displays only tasks that are successfully completed. 110 | 111 | .PARAMETER Failed 112 | Displays only tasks that are unsuccessfully completed. 113 | 114 | .PARAMETER Active 115 | Displays only tasks that are currently in progress 116 | 117 | .PARAMETER Hours 118 | Show only tasks started within the past , where is an integer from 1 through 99999. 119 | 120 | .PARAMETER Task_type 121 | Specifies that specified patterns are treated as glob-style patterns and that all tasks whose types match the specified pattern are displayed. To see the different task types use the showtask column help. 122 | 123 | .PARAMETER TaskID 124 | Show detailed task status for specified tasks. Tasks must be explicitly specified using their task IDs . Multiple task IDs can be specified. This option cannot be used in conjunction with other options. 125 | 126 | .PARAMETER SANConnection 127 | Specify the SAN Connection object created with New-CLIConnection or New-PoshSshConnection 128 | 129 | .Notes 130 | NAME: Get-Task 131 | LASTEDIT: January 2020 132 | KEYWORDS: Get-Task 133 | 134 | .Link 135 | http://www.hpe.com 136 | 137 | #Requires PS -Version 3.0 138 | 139 | #> 140 | [CmdletBinding()] 141 | param( 142 | [Parameter(Position=0, Mandatory=$false,ValueFromPipeline=$true)] 143 | [System.String] 144 | $TaskID, 145 | 146 | [Parameter(Position=1, Mandatory=$false,ValueFromPipeline=$true)] 147 | [System.String] 148 | $Task_type, 149 | 150 | [Parameter(Position=2, Mandatory=$false)] 151 | [Switch] 152 | $All, 153 | 154 | [Parameter(Position=3, Mandatory=$false)] 155 | [Switch] 156 | $Done, 157 | 158 | [Parameter(Position=4, Mandatory=$false)] 159 | [Switch] 160 | $Failed, 161 | 162 | [Parameter(Position=5, Mandatory=$false)] 163 | [Switch] 164 | $Active, 165 | 166 | [Parameter(Position=6, Mandatory=$false,ValueFromPipeline=$true)] 167 | [System.String] 168 | $Hours, 169 | 170 | [Parameter(Position=7, Mandatory=$false, ValueFromPipeline=$true)] 171 | $SANConnection = $global:SANConnection 172 | ) 173 | 174 | Write-DebugLog "Start: In Get-Task - validating input values" $Debug 175 | #check if connection object contents are null/empty 176 | if(!$SANConnection) 177 | { 178 | #check if connection object contents are null/empty 179 | $Validate1 = Test-CLIConnection $SANConnection 180 | if($Validate1 -eq "Failed") 181 | { 182 | #check if global connection object contents are null/empty 183 | $Validate2 = Test-CLIConnection $global:SANConnection 184 | if($Validate2 -eq "Failed") 185 | { 186 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" "ERR:" 187 | Write-DebugLog "Stop: Exiting Get-Task since SAN connection object values are null/empty" $Debug 188 | return "Unable to execute the cmdlet Get-Task since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 189 | } 190 | } 191 | } 192 | $plinkresult = Test-PARCli -SANConnection $SANConnection 193 | if($plinkresult -match "FAILURE :") 194 | { 195 | write-debuglog "$plinkresult" "ERR:" 196 | return $plinkresult 197 | } 198 | 199 | $taskcmd = "showtask " 200 | 201 | if($TaskID) 202 | { 203 | $taskcmd +=" -d $TaskID " 204 | } 205 | if($Task_type) 206 | { 207 | $taskcmd +=" -type $Task_type " 208 | } 209 | if($All) 210 | { 211 | $taskcmd +=" -all " 212 | } 213 | if($Done) 214 | { 215 | $taskcmd +=" -done " 216 | } 217 | if($Failed) 218 | { 219 | $taskcmd +=" -failed " 220 | } 221 | if($Active) 222 | { 223 | $taskcmd +=" -active " 224 | } 225 | if($Hours) 226 | { 227 | $taskcmd +=" -t $Hours " 228 | } 229 | 230 | $result = Invoke-CLICommand -Connection $SANConnection -cmds $taskcmd 231 | #write-host $result 232 | write-debuglog " Running get task status with the command --> $taskcmd" "INFO:" 233 | if($TaskID) 234 | { 235 | return $result 236 | } 237 | if($Result -match "Id" ) 238 | { 239 | $tempFile = [IO.Path]::GetTempFileName() 240 | $LastItem = $Result.Count 241 | $incre = "true" 242 | foreach ($s in $Result[0..$LastItem] ) 243 | { 244 | $s= [regex]::Replace($s,"^ ","") 245 | $s= [regex]::Replace($s," +",",") 246 | $s= [regex]::Replace($s,"-","") 247 | $s= $s.Trim() -replace 'StartTime,FinishTime','Date(ST),Time(ST),Zome(ST),Date(FT),Time(FT),Zome(FT)' 248 | if($incre -eq "true") 249 | { 250 | $s=$s.Substring(1) 251 | } 252 | Add-Content -Path $tempFile -Value $s 253 | $incre="false" 254 | } 255 | Import-Csv $tempFile 256 | del $tempFile 257 | } 258 | if($Result -match "Id") 259 | { 260 | return 261 | #return " Success : Executing Get-Task" 262 | } 263 | else 264 | { 265 | return $Result 266 | } 267 | } #END Get-Task 268 | 269 | #################################################################################################################### 270 | ## FUNCTION Remove-Task 271 | #################################################################################################################### 272 | Function Remove-Task { 273 | <# 274 | .SYNOPSIS 275 | Remove one or more tasks or task details. 276 | . 277 | .DESCRIPTION 278 | The Remove-Task command removes information about one or more completed tasks 279 | and their details. 280 | 281 | .PARAMETER A 282 | Remove all tasks including details. 283 | 284 | .PARAMETER D 285 | Remove task details only. 286 | 287 | .PARAMETER F 288 | Specifies that the command is to be forced. You are not prompted for 289 | confirmation before the task is removed. 290 | 291 | .PARAMETER T 292 | Removes tasks that have not been active within the past , where 293 | is an integer from 1 through 99999. 294 | 295 | .PARAMETER TaskID 296 | Allows you to specify tasks to be removed using their task IDs. 297 | 298 | .EXAMPLES 299 | Remove a task based on the task ID 300 | 301 | Remove-Task 2 302 | 303 | Remove the following tasks? 304 | 2 305 | select q=quit y=yes n=no: y 306 | 307 | .EXAMPLES 308 | Remove all tasks, including details 309 | 310 | Remove-Task -A 311 | 312 | Remove all tasks? 313 | select q=quit y=yes n=no: y 314 | 315 | .NOTES 316 | With this command, the specified task ID and any information associated with 317 | it are removed from the system. However, task IDs are not recycled, so the 318 | next task started on the system uses the next whole integer that has not 319 | already been used. Task IDs roll over at 29999. The system stores 320 | information for the most recent 2000 tasks. 321 | 322 | NAME: Remove-Task 323 | LASTEDIT: 25/04/2021 324 | KEYWORDS: Remove-Task 325 | 326 | .Link 327 | http://www.hpe.com 328 | 329 | #Requires PS -Version 3.0 330 | 331 | #> 332 | [CmdletBinding()] 333 | param( 334 | [Parameter(Position = 0, Mandatory = $false, HelpMessage="specify tasks to be removed using their task ID")] 335 | [System.String] 336 | $TaskID, 337 | 338 | [Parameter(Position = 1, Mandatory = $false, HelpMessage="Remove all tasks including details")] 339 | [Switch] 340 | $A, 341 | 342 | [Parameter(Position = 2, Mandatory = $false, HelpMessage="Remove task details only")] 343 | [Switch] 344 | $D, 345 | 346 | [Parameter(Position = 3, Mandatory = $false, HelpMessage="Specifies that the command is to be forced")] 347 | [Switch] 348 | $F, 349 | 350 | [Parameter(Position = 4, Mandatory = $false, HelpMessage="Remove tasks that have not been active within the past , where 351 | is an integer from 1 through 99999")] 352 | [System.String] 353 | $T, 354 | 355 | [Parameter(Position = 5, Mandatory = $false, ValueFromPipeline = $true)] 356 | $SANConnection = $global:SANConnection 357 | ) 358 | 359 | Write-DebugLog "Start: In Remove-Task - validating input values" $Debug 360 | #check if connection object contents are null/empty 361 | if (!$SANConnection) { 362 | #check if connection object contents are null/empty 363 | $Validate1 = Test-CLIConnection $SANConnection 364 | if ($Validate1 -eq "Failed") { 365 | #check if global connection object contents are null/empty 366 | $Validate2 = Test-CLIConnection $global:SANConnection 367 | if ($Validate2 -eq "Failed") { 368 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" "ERR:" 369 | Write-DebugLog "Stop: Exiting Remove-Task since SAN connection object values are null/empty" $Debug 370 | return "Unable to execute the cmdlet Remove-Task since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 371 | } 372 | } 373 | } 374 | $plinkresult = Test-PARCli 375 | if ($plinkresult -match "FAILURE :") { 376 | write-debuglog "$plinkresult" "ERR:" 377 | return $plinkresult 378 | } 379 | $cmd = "removetask " 380 | 381 | if ($F) { 382 | $cmd += " -f " 383 | } 384 | else { 385 | Return "Force removal is only supported with the Remove-Task cmdlet." 386 | } 387 | if ($TaskID) { 388 | $cmd += "$TaskID" 389 | } 390 | if ($A) { 391 | $cmd += " -a" 392 | } 393 | elseif ($D) { 394 | $cmd += " -d" 395 | } 396 | elseif ($T) { 397 | $cmd += " -t $T" 398 | } 399 | 400 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $cmd 401 | 402 | write-debuglog " The Remove-Task command removes hosts from a remote copy group" "INFO:" 403 | return $Result 404 | 405 | } # End Remove-Task 406 | 407 | #################################################################################################################### 408 | ## FUNCTION Stop-Task 409 | #################################################################################################################### 410 | Function Stop-Task { 411 | <# 412 | .SYNOPSIS 413 | Cancel one or more tasks 414 | . 415 | .DESCRIPTION 416 | The Stop-Task command cancels one or more tasks. 417 | 418 | .PARAMETER F 419 | Forces the command. The command completes the process without prompting 420 | for confirmation. 421 | 422 | .PARAMETER ALL 423 | Cancels all active tasks. If not specified, a task ID(s) must be 424 | specified. 425 | 426 | .PARAMETER TaskID 427 | Cancels only tasks identified by their task IDs. 428 | TaskID must be an unsigned integer within 1-29999 range. 429 | 430 | .EXAMPLES 431 | Cancel a task using the task ID 432 | 433 | Stop-Task 1 434 | 435 | .NOTES 436 | The Stop-Task command can return before a cancellation is completed. Thus, 437 | resources reserved for a task might not be immediately available. This can 438 | prevent actions like restarting the canceled task. Use the waittask command 439 | to ensure orderly completion of the cancellation before taking other 440 | actions. See waittask for more details. 441 | 442 | A Service user is only allowed to cancel tasks started by that specific user. 443 | 444 | NAME: Stop-Task 445 | LASTEDIT: 25/04/2021 446 | KEYWORDS: Stop-Task 447 | 448 | .Link 449 | http://www.hpe.com 450 | 451 | #Requires PS -Version 3.0 452 | 453 | #> 454 | [CmdletBinding()] 455 | param( 456 | 457 | [Parameter(Position = 0, Mandatory = $false)] 458 | [System.String] 459 | $TaskID, 460 | 461 | 462 | [Parameter(Position = 1, Mandatory = $false)] 463 | [Switch] 464 | $F, 465 | 466 | [Parameter(Position = 2, Mandatory = $false)] 467 | [System.String] 468 | $ALL, 469 | 470 | [Parameter(Position = 3, Mandatory = $false, ValueFromPipeline = $true)] 471 | $SANConnection = $global:SANConnection 472 | ) 473 | 474 | Write-DebugLog "Start: In Stop-Task - validating input values" $Debug 475 | #check if connection object contents are null/empty 476 | if (!$SANConnection) { 477 | #check if connection object contents are null/empty 478 | $Validate1 = Test-CLIConnection $SANConnection 479 | if ($Validate1 -eq "Failed") { 480 | #check if global connection object contents are null/empty 481 | $Validate2 = Test-CLIConnection $global:SANConnection 482 | if ($Validate2 -eq "Failed") { 483 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" "ERR:" 484 | Write-DebugLog "Stop: Exiting Stop-Task since SAN connection object values are null/empty" $Debug 485 | return "Unable to execute the cmdlet Stop-Task since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 486 | } 487 | } 488 | } 489 | $plinkresult = Test-PARCli 490 | if ($plinkresult -match "FAILURE :") { 491 | write-debuglog "$plinkresult" "ERR:" 492 | return $plinkresult 493 | } 494 | $cmd = "canceltask " 495 | 496 | if ($F) { 497 | $cmd += " -f " 498 | } 499 | else { 500 | Return "Force cancellation is only supported with the Stop-Task cmdlet." 501 | } 502 | if ($TaskID) { 503 | $cmd += "$TaskID" 504 | } 505 | if ($ALL) { 506 | $cmd += " -all" 507 | } 508 | 509 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $cmd 510 | 511 | write-debuglog " The Stop-Task command removes hosts from a remote copy group" "INFO:" 512 | return $Result 513 | 514 | } # End Stop-Task 515 | 516 | #################################################################################################################### 517 | ## FUNCTION Wait-Task 518 | #################################################################################################################### 519 | Function Wait-Task { 520 | <# 521 | .SYNOPSIS 522 | Wait for tasks to complete. 523 | . 524 | .DESCRIPTION 525 | The Wait-Task cmdlet asks the CLI to wait for a task to complete before 526 | proceeding. The cmdlet automatically notifies you when the specified task 527 | is finished. 528 | 529 | .PARAMETER V 530 | Displays the detailed status of the task specified by as it 531 | executes. When the task completes, this command exits. 532 | 533 | .PARAMETER TaskID 534 | Indicates one or more tasks to wait for using their task IDs. When no 535 | task IDs are specified, the command waits for all non-system tasks 536 | to complete. To wait for system tasks, must be specified. 537 | 538 | .PARAMETER Q 539 | Quiet; do not report the end state of the tasks, only wait for them to 540 | exit. 541 | 542 | .EXAMPLES 543 | The following example shows how to wait for a task using the task ID. When 544 | successful, the command returns only after the task completes. 545 | 546 | Wait-Task 1 547 | Task 1 done 548 | 549 | .NOTES 550 | This cmdlet returns an error if any of the tasks it is waiting for fail. 551 | 552 | NAME: Wait-Task 553 | LASTEDIT: 25/04/2021 554 | KEYWORDS: Wait-Task 555 | 556 | .Link 557 | http://www.hpe.com 558 | 559 | #Requires PS -Version 3.0 560 | 561 | #> 562 | [CmdletBinding()] 563 | param( 564 | [Parameter(Position = 0, Mandatory = $false)] 565 | [Switch] 566 | $V, 567 | 568 | [Parameter(Position = 1, Mandatory = $false)] 569 | [System.String] 570 | $TaskID, 571 | 572 | [Parameter(Position = 2, Mandatory = $false)] 573 | [Switch] 574 | $Q, 575 | 576 | [Parameter(Position = 3, Mandatory = $false, ValueFromPipeline = $true)] 577 | $SANConnection = $global:SANConnection 578 | ) 579 | 580 | Write-DebugLog "Start: In Wait-Task - validating input values" $Debug 581 | #check if connection object contents are null/empty 582 | if (!$SANConnection) { 583 | #check if connection object contents are null/empty 584 | $Validate1 = Test-CLIConnection $SANConnection 585 | if ($Validate1 -eq "Failed") { 586 | #check if global connection object contents are null/empty 587 | $Validate2 = Test-CLIConnection $global:SANConnection 588 | if ($Validate2 -eq "Failed") { 589 | Write-DebugLog "Connection object is null/empty or the array address (FQDN/IP Address) or user credentials in the connection object are either null or incorrect. Create a valid connection object using New-CLIConnection or New-PoshSshConnection" "ERR:" 590 | Write-DebugLog "Stop: Exiting Wait-Task since SAN connection object values are null/empty" $Debug 591 | return "Unable to execute the cmdlet Wait-Task since no active storage connection session exists. `nUse New-PoshSSHConnection or New-CLIConnection to start a new storage connection session." 592 | } 593 | } 594 | } 595 | $plinkresult = Test-PARCli 596 | if ($plinkresult -match "FAILURE :") { 597 | write-debuglog "$plinkresult" "ERR:" 598 | return $plinkresult 599 | } 600 | $cmd = "waittask " 601 | 602 | if ($V) { 603 | $cmd += " -v " 604 | } 605 | if ($TaskID) { 606 | $cmd += "$TaskID" 607 | } 608 | if ($Q) { 609 | $cmd += " -q" 610 | } 611 | 612 | $Result = Invoke-CLICommand -Connection $SANConnection -cmds $cmd 613 | 614 | write-debuglog " Executed the Wait-Task cmdlet" "INFO:" 615 | 616 | return $Result 617 | 618 | } # End Wait-Task 619 | 620 | Export-ModuleMember Get-Task , Remove-Task , Stop-Task , Wait-Task -------------------------------------------------------------------------------- /WSAPI/SystemInformationQueriesAndManagement.psm1: -------------------------------------------------------------------------------- 1 | #################################################################################### 2 | ## © 2020,2021 Hewlett Packard Enterprise Development LP 3 | ## 4 | ## Permission is hereby granted, free of charge, to any person obtaining a 5 | ## copy of this software and associated documentation files (the "Software"), 6 | ## to deal in the Software without restriction, including without limitation 7 | ## the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | ## and/or sell copies of the Software, and to permit persons to whom the 9 | ## Software is furnished to do so, subject to the following conditions: 10 | ## 11 | ## The above copyright notice and this permission notice shall be included 12 | ## in all copies or substantial portions of the Software. 13 | ## 14 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | ## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | ## OTHER DEALINGS IN THE SOFTWARE. 21 | ## 22 | ## File Name: SystemInformationQueriesAndManagement.psm1 23 | ## Description: System information queries and management cmdlets 24 | ## 25 | ## Created: February 2020 26 | ## Last Modified: February 2020 27 | ## History: v3.0 - Created 28 | ##################################################################################### 29 | 30 | $Info = "INFO:" 31 | $Debug = "DEBUG:" 32 | $global:VSLibraries = Split-Path $MyInvocation.MyCommand.Path 33 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 34 | 35 | ############################################################################################################################################ 36 | ## FUNCTION Get-System_WSAPI 37 | ############################################################################################################################################ 38 | Function Get-System_WSAPI 39 | { 40 | <# 41 | 42 | .SYNOPSIS 43 | Retrieve informations about the array. 44 | 45 | .DESCRIPTION 46 | Retrieve informations about the array. 47 | 48 | .EXAMPLE 49 | Get-System_WSAPI 50 | Retrieve informations about the array. 51 | 52 | .PARAMETER WsapiConnection 53 | WSAPI Connection object created with Connection command 54 | 55 | .Notes 56 | NAME : Get-System_WSAPI 57 | LASTEDIT: February 2020 58 | KEYWORDS: Get-System_WSAPI 59 | 60 | .Link 61 | http://www.hpe.com 62 | 63 | #Requires PS -Version 3.0 64 | 65 | #> 66 | [CmdletBinding()] 67 | Param( 68 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 69 | $WsapiConnection = $global:WsapiConnection 70 | ) 71 | Begin 72 | { 73 | #Test if connection exist 74 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 75 | } 76 | 77 | Process 78 | { 79 | $Result = $null 80 | $dataPS = $null 81 | 82 | #Request 83 | $Result = Invoke-WSAPI -uri '/system' -type 'GET' -WsapiConnection $WsapiConnection 84 | 85 | if($Result.StatusCode -eq 200) 86 | { 87 | $dataPS = $Result.content | ConvertFrom-Json 88 | } 89 | 90 | if($Result.StatusCode -eq 200) 91 | { 92 | write-host "" 93 | write-host "Cmdlet executed successfully" -foreground green 94 | write-host "" 95 | Write-DebugLog "SUCCESS:successfully Executed" $Info 96 | 97 | return $dataPS 98 | } 99 | else 100 | { 101 | write-host "" 102 | write-host "FAILURE : While Executing Get-System_WSAPI" -foreground red 103 | write-host "" 104 | Write-DebugLog "FAILURE : While Executing Get-System_WSAPI" $Info 105 | 106 | return $Result.StatusDescription 107 | } 108 | } 109 | } 110 | #END Get-System_WSAPI 111 | 112 | ############################################################################################################################################ 113 | ## FUNCTION Update-System_WSAPI 114 | ############################################################################################################################################ 115 | Function Update-System_WSAPI 116 | { 117 | <# 118 | .SYNOPSIS 119 | Update storage system parameters 120 | 121 | .DESCRIPTION 122 | Update storage system parameters 123 | You can set all of the system parameters in one request, but some updates might fail. 124 | 125 | .EXAMPLE 126 | Update-System_WSAPI -RemoteSyslog $true 127 | 128 | .EXAMPLE 129 | Update-System_WSAPI -remoteSyslogHost "0.0.0.0" 130 | 131 | .EXAMPLE 132 | Update-System_WSAPI -PortFailoverEnabled $true 133 | 134 | .EXAMPLE 135 | Update-System_WSAPI -DisableDedup $true 136 | 137 | .EXAMPLE 138 | Update-System_WSAPI -OverProvRatioLimit 3 139 | 140 | .EXAMPLE 141 | Update-System_WSAPI -AllowR5OnFCDrives $true 142 | 143 | .PARAMETER RemoteSyslog 144 | Enable (true) or disable (false) sending events to a remote system as syslog messages. 145 | 146 | .PARAMETER RemoteSyslogHost 147 | IP address of the systems to which events are sent as syslog messages. 148 | 149 | .PARAMETER RemoteSyslogSecurityHost 150 | Sets the hostname or IP address, and optionally the port, of the remote syslog servers to which security events are sent as syslog messages. 151 | 152 | .PARAMETER PortFailoverEnabled 153 | Enable (true) or disable (false) the automatic fail over of target ports to their designated partner ports. 154 | 155 | .PARAMETER FailoverMatchedSet 156 | Enable (true) or disable (false) the automatic fail over of matched-set VLUNs during a persistent port fail over. This does not affect host-see VLUNs, which are always failed over. 157 | 158 | .PARAMETER DisableDedup 159 | Enable or disable new write requests to TDVVs serviced by the system to be deduplicated. 160 | true – Disables deduplication 161 | false – Enables deduplication 162 | 163 | .PARAMETER DisableCompr 164 | Enable or disable the compression of all new write requests to the compressed VVs serviced by the system. 165 | True - The new writes are not compressed. 166 | False - The new writes are compressed. 167 | 168 | .PARAMETER OverProvRatioLimit 169 | The system, device types, and all CPGs are limited to the specified overprovisioning ratio. 170 | 171 | .PARAMETER OverProvRatioWarning 172 | An overprovisioning ratio, which when exceeded by the system, a device type, or a CPG, results in a warning alert. 173 | 174 | .PARAMETER AllowR5OnNLDrives 175 | Enable (true) or disable (false) support for RAID-5 on NL drives. 176 | 177 | .PARAMETER AllowR5OnFCDrives 178 | Enable (true) or disable (false) support for RAID-5 on FC drives. 179 | 180 | .PARAMETER ComplianceOfficerApproval 181 | Enable (true) or disable (false) compliance officer approval mode. 182 | 183 | .PARAMETER WsapiConnection 184 | WSAPI Connection object created with Connection command 185 | 186 | .Notes 187 | NAME : Update-System_WSAPI 188 | LASTEDIT: February 2020 189 | KEYWORDS: Update-System_WSAPI 190 | 191 | .Link 192 | http://www.hpe.com 193 | 194 | #Requires PS -Version 3.0 195 | #> 196 | 197 | [CmdletBinding()] 198 | Param( 199 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 200 | [boolean] 201 | $RemoteSyslog, 202 | 203 | [Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)] 204 | [System.String] 205 | $RemoteSyslogHost, 206 | 207 | [Parameter(Position=2, Mandatory=$false, ValueFromPipeline=$true)] 208 | [System.String] 209 | $RemoteSyslogSecurityHost, 210 | 211 | [Parameter(Position=3, Mandatory=$false, ValueFromPipeline=$true)] 212 | [boolean] 213 | $PortFailoverEnabled, 214 | 215 | [Parameter(Position=4, Mandatory=$false, ValueFromPipeline=$true)] 216 | [boolean] 217 | $FailoverMatchedSet, 218 | 219 | [Parameter(Position=5, Mandatory=$false, ValueFromPipeline=$true)] 220 | [boolean] 221 | $DisableDedup, 222 | 223 | [Parameter(Position=6, Mandatory=$false, ValueFromPipeline=$true)] 224 | [boolean] 225 | $DisableCompr, 226 | 227 | [Parameter(Position=7, Mandatory=$false, ValueFromPipeline=$true)] 228 | [int] 229 | $OverProvRatioLimit, 230 | 231 | [Parameter(Position=8, Mandatory=$false, ValueFromPipeline=$true)] 232 | [int] 233 | $OverProvRatioWarning, 234 | 235 | [Parameter(Position=9, Mandatory=$false, ValueFromPipeline=$true)] 236 | [boolean] 237 | $AllowR5OnNLDrives, 238 | 239 | [Parameter(Position=10, Mandatory=$false, ValueFromPipeline=$true)] 240 | [boolean] 241 | $AllowR5OnFCDrives, 242 | 243 | [Parameter(Position=11, Mandatory=$false, ValueFromPipeline=$true)] 244 | [boolean] 245 | $ComplianceOfficerApproval, 246 | 247 | [Parameter(Position=12, Mandatory=$false, ValueFromPipeline=$true)] 248 | $WsapiConnection = $global:WsapiConnection 249 | ) 250 | 251 | Begin 252 | { 253 | # Test if connection exist 254 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 255 | } 256 | 257 | Process 258 | { 259 | $body = @{} 260 | $ObjMain=@{} 261 | 262 | If ($RemoteSyslog) 263 | { 264 | $Obj=@{} 265 | $Obj["remoteSyslog"] = $RemoteSyslog 266 | $ObjMain += $Obj 267 | } 268 | If ($RemoteSyslogHost) 269 | { 270 | $Obj=@{} 271 | $Obj["remoteSyslogHost"] = "$($RemoteSyslogHost)" 272 | $ObjMain += $Obj 273 | } 274 | If ($RemoteSyslogSecurityHost) 275 | { 276 | $Obj=@{} 277 | $Obj["remoteSyslogSecurityHost"] = "$($RemoteSyslogSecurityHost)" 278 | $ObjMain += $Obj 279 | } 280 | If ($PortFailoverEnabled) 281 | { 282 | $Obj=@{} 283 | $Obj["portFailoverEnabled"] = $PortFailoverEnabled 284 | $ObjMain += $Obj 285 | } 286 | If ($FailoverMatchedSet) 287 | { 288 | $Obj=@{} 289 | $Obj["failoverMatchedSet"] = $FailoverMatchedSet 290 | $ObjMain += $Obj 291 | } 292 | If ($DisableDedup) 293 | { 294 | $Obj=@{} 295 | $Obj["disableDedup"] = $DisableDedup 296 | $ObjMain += $Obj 297 | } 298 | If ($DisableCompr) 299 | { 300 | $Obj=@{} 301 | $Obj["disableCompr"] = $DisableCompr 302 | $ObjMain += $Obj 303 | } 304 | If ($OverProvRatioLimit) 305 | { 306 | $Obj=@{} 307 | $Obj["overProvRatioLimit"] = $OverProvRatioLimit 308 | $ObjMain += $Obj 309 | } 310 | If ($OverProvRatioWarning) 311 | { 312 | $Obj=@{} 313 | $Obj["overProvRatioWarning"] = $OverProvRatioWarning 314 | $ObjMain += $Obj 315 | } 316 | If ($AllowR5OnNLDrives) 317 | { 318 | $Obj=@{} 319 | $Obj["allowR5OnNLDrives"] = $AllowR5OnNLDrives 320 | $ObjMain += $Obj 321 | } 322 | If ($AllowR5OnFCDrives) 323 | { 324 | $Obj=@{} 325 | $Obj["allowR5OnFCDrives"] = $AllowR5OnFCDrives 326 | $ObjMain += $Obj 327 | } 328 | If ($ComplianceOfficerApproval) 329 | { 330 | $Obj=@{} 331 | $Obj["complianceOfficerApproval"] = $ComplianceOfficerApproval 332 | $ObjMain += $Obj 333 | } 334 | 335 | if($ObjMain.Count -gt 0) 336 | { 337 | $body["parameters"] = $ObjMain 338 | } 339 | 340 | $Result = $null 341 | #Request 342 | Write-DebugLog "Request: Request to Update-System_WSAPI (Invoke-WSAPI)." $Debug 343 | $Result = Invoke-WSAPI -uri '/system' -type 'PUT' -body $body -WsapiConnection $WsapiConnection 344 | 345 | if($Result.StatusCode -eq 200) 346 | { 347 | write-host "" 348 | write-host "Cmdlet executed successfully" -foreground green 349 | write-host "" 350 | Write-DebugLog "SUCCESS: Successfully Update storage system parameters." $Info 351 | 352 | # Results 353 | Get-System_WSAPI 354 | Write-DebugLog "End: Update-System_WSAPI" $Debug 355 | } 356 | else 357 | { 358 | write-host "" 359 | write-host "FAILURE : While Updating storage system parameters." -foreground red 360 | write-host "" 361 | Write-DebugLog "FAILURE : While Updating storage system parameters." $Info 362 | 363 | return $Result.StatusDescription 364 | } 365 | } 366 | 367 | End { } 368 | 369 | }#END Update-System_WSAPI 370 | 371 | ############################################################################################################################################ 372 | ## FUNCTION Get-Version_WSAPI 373 | ############################################################################################################################################ 374 | Function Get-Version_WSAPI 375 | { 376 | <# 377 | 378 | .SYNOPSIS 379 | Get version information. 380 | 381 | .DESCRIPTION 382 | Get version information. 383 | 384 | .EXAMPLE 385 | Get-Version_WSAPI 386 | Get version information. 387 | 388 | .PARAMETER WsapiConnection 389 | WSAPI Connection object created with Connection command 390 | 391 | .Notes 392 | NAME : Get-Version_WSAPI 393 | LASTEDIT: February 2020 394 | KEYWORDS: Get-Version_WSAPI 395 | 396 | .Link 397 | http://www.hpe.com 398 | 399 | #Requires PS -Version 3.0 400 | 401 | #> 402 | [CmdletBinding()] 403 | Param( 404 | [Parameter(Position=2, Mandatory=$false, ValueFromPipeline=$true)] 405 | $WsapiConnection = $global:WsapiConnection 406 | ) 407 | Begin 408 | { 409 | #Test if connection exist 410 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 411 | } 412 | 413 | Process 414 | { 415 | $Result = $null 416 | $dataPS = $null 417 | 418 | $ip = $WsapiConnection.IPAddress 419 | $key = $WsapiConnection.Key 420 | $arrtyp = $global:ArrayType 421 | 422 | $APIurl = $Null 423 | 424 | if($arrtyp.ToLower() -eq "3par") 425 | { 426 | #$APIurl = "https://$($SANIPAddress):8080/api/v1" 427 | $APIurl = 'https://'+$ip+':8080/api' 428 | } 429 | Elseif(($arrtyp.ToLower() -eq "primera") -or ($arrtyp.ToLower() -eq "alletra9000")) 430 | { 431 | #$APIurl = "https://$($SANIPAddress):443/api/v1" 432 | $APIurl = 'https://'+$ip+':443/api' 433 | } 434 | else 435 | { 436 | return "Array type is Null." 437 | } 438 | 439 | #Construct header 440 | Write-DebugLog "Running: Constructing header." $Debug 441 | $headers = @{} 442 | $headers["Accept"] = "application/json" 443 | $headers["Accept-Language"] = "en" 444 | $headers["Content-Type"] = "application/json" 445 | $headers["X-HP3PAR-WSAPI-SessionKey"] = $key 446 | 447 | #Request 448 | if ($PSEdition -eq 'Core') 449 | { 450 | $Result = Invoke-WebRequest -Uri "$APIurl" -Headers $headers -Method GET -UseBasicParsing -SkipCertificateCheck 451 | } 452 | else 453 | { 454 | $Result = Invoke-WebRequest -Uri "$APIurl" -Headers $headers -Method GET -UseBasicParsing 455 | } 456 | 457 | if($Result.StatusCode -eq 200) 458 | { 459 | $dataPS = $Result.content | ConvertFrom-Json 460 | } 461 | 462 | if($Result.StatusCode -eq 200) 463 | { 464 | write-host "" 465 | write-host "Cmdlet executed successfully" -foreground green 466 | write-host "" 467 | Write-DebugLog "SUCCESS:successfully Executed" $Info 468 | 469 | return $dataPS 470 | } 471 | else 472 | { 473 | write-host "" 474 | write-host "FAILURE : While Executing Get-Version_WSAPI" -foreground red 475 | write-host "" 476 | Write-DebugLog "FAILURE : While Executing Get-Version_WSAPI" $Info 477 | 478 | return $Result.StatusDescription 479 | } 480 | } 481 | } 482 | #END Get-Version_WSAPI 483 | 484 | ############################################################################################################################################ 485 | ## FUNCTION Get-WSAPIConfigInfo 486 | ############################################################################################################################################ 487 | Function Get-WSAPIConfigInfo 488 | { 489 | <# 490 | 491 | .SYNOPSIS 492 | Get Getting WSAPI configuration information 493 | 494 | .DESCRIPTION 495 | Get Getting WSAPI configuration information 496 | 497 | .EXAMPLE 498 | Get-WSAPIConfigInfo 499 | Get Getting WSAPI configuration information 500 | 501 | .PARAMETER WsapiConnection 502 | WSAPI Connection object created with Connection command 503 | 504 | .Notes 505 | NAME : Get-WSAPIConfigInfo 506 | LASTEDIT: February 2020 507 | KEYWORDS: Get-WSAPIConfigInfo 508 | 509 | .Link 510 | http://www.hpe.com 511 | 512 | #Requires PS -Version 3.0 513 | 514 | #> 515 | [CmdletBinding()] 516 | Param( 517 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 518 | $WsapiConnection = $global:WsapiConnection 519 | ) 520 | Begin 521 | { 522 | #Test if connection exist 523 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 524 | } 525 | 526 | Process 527 | { 528 | $Result = $null 529 | $dataPS = $null 530 | 531 | #Request 532 | $Result = Invoke-WSAPI -uri '/wsapiconfiguration' -type 'GET' -WsapiConnection $WsapiConnection 533 | if($Result.StatusCode -eq 200) 534 | { 535 | $dataPS = $Result.content | ConvertFrom-Json 536 | } 537 | 538 | if($Result.StatusCode -eq 200) 539 | { 540 | write-host "" 541 | write-host "Cmdlet executed successfully" -foreground green 542 | write-host "" 543 | Write-DebugLog "SUCCESS:successfully Executed" $Info 544 | 545 | return $dataPS 546 | } 547 | else 548 | { 549 | write-host "" 550 | write-host "FAILURE : While Executing Get-WSAPIConfigInfo" -foreground red 551 | write-host "" 552 | Write-DebugLog "FAILURE : While Executing Get-WSAPIConfigInfo" $Info 553 | 554 | return $Result.StatusDescription 555 | } 556 | } 557 | } 558 | #END Get-WSAPIConfigInfo 559 | 560 | ############################################################################################################################################ 561 | ## FUNCTION Get-Task_WSAPI 562 | ############################################################################################################################################ 563 | Function Get-Task_WSAPI 564 | { 565 | <# 566 | 567 | .SYNOPSIS 568 | Get the status of all or given tasks 569 | 570 | .DESCRIPTION 571 | Get the status of all or given tasks 572 | 573 | .EXAMPLE 574 | Get-Task_WSAPI 575 | Get the status of all tasks 576 | 577 | .EXAMPLE 578 | Get-Task_WSAPI -TaskID 101 579 | Get the status of given tasks 580 | 581 | .PARAMETER TaskID 582 | Task ID 583 | 584 | .PARAMETER WsapiConnection 585 | WSAPI Connection object created with Connection command 586 | 587 | .Notes 588 | NAME : Get-Task_WSAPI 589 | LASTEDIT: February 2020 590 | KEYWORDS: Get-Task_WSAPI 591 | 592 | .Link 593 | http://www.hpe.com 594 | 595 | #Requires PS -Version 3.0 596 | 597 | #> 598 | [CmdletBinding()] 599 | Param( 600 | [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 601 | [System.String] 602 | $TaskID, 603 | 604 | [Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)] 605 | $WsapiConnection = $global:WsapiConnection 606 | ) 607 | 608 | Begin 609 | { 610 | #Test if connection exist 611 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 612 | } 613 | 614 | Process 615 | { 616 | $Result = $null 617 | $dataPS = $null 618 | 619 | #Build uri 620 | if($TaskID) 621 | { 622 | $uri = '/tasks/'+$TaskID 623 | #Request 624 | $Result = Invoke-WSAPI -uri $uri -type 'GET' -WsapiConnection $WsapiConnection 625 | if($Result.StatusCode -eq 200) 626 | { 627 | $dataPS = $Result.content | ConvertFrom-Json 628 | } 629 | } 630 | else 631 | { 632 | #Request 633 | $Result = Invoke-WSAPI -uri '/tasks' -type 'GET' -WsapiConnection $WsapiConnection 634 | if($Result.StatusCode -eq 200) 635 | { 636 | $dataPS = ($Result.content | ConvertFrom-Json).members 637 | } 638 | } 639 | 640 | if($Result.StatusCode -eq 200) 641 | { 642 | write-host "" 643 | write-host "Cmdlet executed successfully" -foreground green 644 | write-host "" 645 | Write-DebugLog "SUCCESS: Command Get-Task_WSAPI Successfully Executed" $Info 646 | 647 | return $dataPS 648 | } 649 | else 650 | { 651 | write-host "" 652 | write-host "FAILURE : While Executing Get-Task_WSAPI." -foreground red 653 | write-host "" 654 | Write-DebugLog "FAILURE : While Executing Get-Task_WSAPI." $Info 655 | 656 | return $Result.StatusDescription 657 | } 658 | } 659 | } 660 | #END Get-Task_WSAPI 661 | 662 | ############################################################################################################################################ 663 | ## FUNCTION Stop-OngoingTask_WSAPI 664 | ############################################################################################################################################ 665 | Function Stop-OngoingTask_WSAPI 666 | { 667 | <# 668 | .SYNOPSIS 669 | Cancels the ongoing task. 670 | 671 | .DESCRIPTION 672 | Cancels the ongoing task. 673 | 674 | .EXAMPLE 675 | Stop-OngoingTask_WSAPI -TaskID 1 676 | 677 | .PARAMETER TaskID 678 | Task id. 679 | 680 | .PARAMETER WsapiConnection 681 | WSAPI Connection object created with Connection command 682 | 683 | .Notes 684 | NAME : Stop-OngoingTask_WSAPI 685 | LASTEDIT: February 2020 686 | KEYWORDS: Stop-OngoingTask_WSAPI 687 | 688 | .Link 689 | http://www.hpe.com 690 | 691 | #Requires PS -Version 3.0 692 | #> 693 | 694 | [CmdletBinding()] 695 | Param( 696 | [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] 697 | [System.String] 698 | $TaskID, 699 | 700 | [Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)] 701 | $WsapiConnection = $global:WsapiConnection 702 | ) 703 | 704 | Begin 705 | { 706 | # Test if connection exist 707 | Test-WSAPIConnection -WsapiConnection $WsapiConnection 708 | } 709 | 710 | Process 711 | { 712 | $body = @{} 713 | $body["action"] = 4 714 | 715 | $Result = $null 716 | $uri = "/tasks/" + $TaskID 717 | 718 | #Request 719 | Write-DebugLog "Request: Request to Stop-OngoingTask_WSAPI : $TaskID (Invoke-WSAPI)." $Debug 720 | $Result = Invoke-WSAPI -uri $uri -type 'PUT' -body $body -WsapiConnection $WsapiConnection 721 | 722 | if($Result.StatusCode -eq 200) 723 | { 724 | write-host "" 725 | write-host "Cmdlet executed successfully" -foreground green 726 | write-host "" 727 | Write-DebugLog "SUCCESS: Successfully Cancels the ongoing task : $TaskID ." $Info 728 | 729 | # Results 730 | return $Result 731 | Write-DebugLog "End: Stop-OngoingTask_WSAPI." $Debug 732 | } 733 | else 734 | { 735 | write-host "" 736 | write-host "FAILURE : While Cancelling the ongoing task : $TaskID " -foreground red 737 | write-host "" 738 | Write-DebugLog "FAILURE : While Cancelling the ongoing task : $TaskID " $Info 739 | 740 | return $Result.StatusDescription 741 | } 742 | } 743 | 744 | End { } 745 | 746 | }#END Stop-OngoingTask_WSAPI 747 | 748 | Export-ModuleMember Get-System_WSAPI , Update-System_WSAPI , Get-Version_WSAPI , Get-WSAPIConfigInfo , Get-Task_WSAPI , Stop-OngoingTask_WSAPI --------------------------------------------------------------------------------