Skip to content

Commit aa34baa

Browse files
committed
restructed repository, added examples, updated Readme
1 parent 437fefe commit aa34baa

6 files changed

Lines changed: 140 additions & 140 deletions

File tree

OnCommand-Insight-Tutorial.md

Lines changed: 0 additions & 80 deletions
This file was deleted.

README.md

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
1-
OnCommand-Insight
2-
=================
1+
S3-Mgmt
2+
=======
33

4-
OnCommand-Insight PowerShell Module
4+
StorageGRID S3 Management PowerShell Module
55

66
Installation
77
------------
88

9-
Extract OnCommand-Insight.zip either to your preferred PowerShell Module location (e.g. `$HOME\WindowsPowershell\Documents\WindowsPowerShell\Modules` or `C:\Windows\System32\WindowsPowerShell\v1.0\Modules`).
9+
Extract S3-Mgmt.zip either to your preferred PowerShell Module location (e.g. `$HOME\WindowsPowershell\Documents\WindowsPowerShell\Modules` or `C:\Windows\System32\WindowsPowerShell\v1.0\Modules`).
1010

1111
Usage
1212
-----
1313

14-
Check if OnCommand-Insight Module can be found by PowerShell
14+
Check if S3-Mgmt Module can be found by PowerShell
1515

16-
Get-Module -ListAvailable OnCommand-Insight
16+
Get-Module -ListAvailable S3-Mgmt
1717

1818
Import PowerShell Module
1919

20-
Import-Module OnCommand-Insight
20+
Import-Module S3-Mgmt
2121

22-
List all Cmdlets included in the OnCommand-Insight Module
22+
List all Cmdlets included in the S3-Mgmt Module
2323

24-
Get-Command -Module OnCommand-Insight
24+
Get-Command -Module S3-Mgmt
2525

26-
Show help for Cmdlet to connect to OnCommand-Insight Server
26+
Show help for Cmdlet to connect to StorageGRID Management Server
2727

28-
Get-Help Connect-OciServer -Detailed
28+
Get-Help Connect-S3MgmtServer -Detailed
2929

30-
Connect to OnCommand Insight Server using the `-Insecure` Switch to skip checking the certificate of the server
30+
Connect to StorageGRID Management Server (use the `-Insecure` switch to skip checking the certificate of the server)
3131

3232
$Credential = Get-Credential
3333
Connect-OciServer -Name myserver.mydomain.tld -Credential $Credential -Insecure
3434

35-
List all Storage Arrays
35+
List all S3 Accounts
3636

37-
Get-OciStorageArrays
37+
Get-S3Accounts
38+
39+
Show Account Usage
40+
41+
Get-S3Accounts | Get-S3AccountUsage
3842

39-
Trusting the Publisher of the OnCommand Insight Cmdlets
43+
Trusting the Publisher of the S3-Mgmt Cmdlets
4044
-------------------------------------------------------
4145

4246
This PowerShell Module is signed with a code signing certificate issued by the *NetApp Corp Issuing CA 1*. If the PowerShell execution policy requires powershell scripts to be signed (see [about_Execution_Policies](technet.microsoft.com/library/hh847748.aspx) for details), two steps are required to run this PowerShell Module
@@ -54,26 +58,4 @@ This PowerShell Module is signed with a code signing certificate issued by the *
5458
10. Click Finish
5559
11. A *Security Warning* will be displayed. Click *Yes* to install the certificate. The *Thumbprint (sha1)* should be **9FFB6F1A 06BC0245 27368705 2E7309D3 6FF2CFD0**
5660
12. Click twice on *OK* to close the dialogs.
57-
2. When importing the PowerShell module via `Import-Module OnCommand-Insigh` a dialog is displayed asking if the publisher *CN=florianf-Florian-Feldhaus, OU=Users, OU=EMEA, OU=Sites, DC=hq, DC=netapp, DC=com* should be trusted. Select *[A] Always run* to permanently trust this publisher.
58-
59-
60-
Changelog
61-
---------
62-
63-
### Version 0.3
64-
65-
* Module is now signed
66-
* added instructions to trust the publisher of the Module
67-
* added ability for most cmdlets to accept pipeline input
68-
* streamlined usage of the parameter ID. All cmdlets accepting ID parameters now have named parameters like VolumeID or HostID and ID is an alias to these parameters (e.g. ID always works).
69-
* added formatting of OCI types
70-
71-
### Version 0.2
72-
73-
* improved Help and added Parameter Help
74-
* solved Namespace issues when changing server and introduced OCI namespace
75-
* improved build process
76-
77-
### Version 0.1
78-
79-
* First internal release with all Cmdlets implemented
61+
2. When importing the PowerShell module via `Import-Module S3-Mgmt` a dialog is displayed asking if the publisher *CN=florianf-Florian-Feldhaus, OU=Users, OU=EMEA, OU=Sites, DC=hq, DC=netapp, DC=com* should be trusted. Select *[A] Always run* to permanently trust this publisher.

S3-Mgmt-Tutorial.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# StorageGRID S3 Management PowerShell Cmdlet Tutorial
2+
3+
This tutorial will give an introduction to the StorageGRID S3 Management PowerShell Cmdlets
4+
5+
## Discovering the available Cmdlets
6+
7+
Load the S3-Mgmt Module
8+
9+
```powershell
10+
Import-Module S3-Mgmt
11+
```
12+
13+
Show all available Cmdlets from the S3-Mgmt Module
14+
15+
```powershell
16+
Get-Command -Module S3-Mgmt
17+
```
18+
19+
Show the syntax of all Cmdlets from the S3-Mgmt Module
20+
21+
```powershell
22+
Get-Command -Module S3-Mgmt
23+
```
24+
25+
To get detailed help including examples for a specific Cmdlet (e.g. for Connect-S3MgmtServer) run
26+
27+
```powershell
28+
Get-Help Connect-S3MgmtServer -Detailed
29+
```
30+
31+
## Connecting to a StorageGRID Management Server
32+
33+
For data retrieval a connection to the StorageGRID Management Server is required. The Connect-S3MgmtServer Cmdlet expects the hostname or IP and the credentials for authentication
34+
35+
```powershell
36+
$ServerName = 'nms.stroagegrid.example.com'
37+
$Credential = Get-Credential
38+
Connect-S3MgmtServer -Name $ServerName -Credential $Credential
39+
```
40+
41+
If the login fails, it is often due to an untrusted certificate of the StorageGRID Management Server. You can ignore the certificate check with the `-Insecure` option
42+
43+
```powershell
44+
Connect-S3MgmtServer -Name $ServerName -Credential $Credential -Insecure
45+
```
46+
47+
By default the connection to the S3Mgmt server is established through HTTPS. If that doesn't work, HTTP will be tried.
48+
49+
To force connections via HTTPS use the `-HTTPS` switch
50+
51+
```powershell
52+
Connect-S3MgmtServer -Name $ServerName -Credential $Credential -HTTPS
53+
```
54+
55+
To force connections via HTTP use the `-HTTP` switch
56+
57+
```powershell
58+
Connect-S3MgmtServer -Name $ServerName -Credential $Credential -HTTP
59+
```
60+
61+
## Simple workflow for exporting S3 account usage to CSV
62+
63+
In this simple workflow the S3 account usage data will be retrieved and exported as CSV to (C:\tmp\usage.csv).
64+
65+
```powershell
66+
$Accounting = foreach ($Account in Get-S3Accounts) {
67+
$Usage = Get-S3AccountUsage -id $Account.id
68+
$Output = New-Object -TypeName PSCustomObject -Property @{Name=$Account.name;ID=$Account.id;"Calculation Time"=$Usage.calculationTime;"Object Count"=$Usage.objectCount;"Data Bytes used"=$Usage.dataBytes}
69+
Write-Output $Output
70+
}
71+
72+
$Accounting | Export-Csv -Path C:\tmp\usage.csv -NoTypeInformation
73+
```

src/S3-Mgmt-examples.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
$Credential = Get-Credential
55

66
# Connect to StorageGRID NMS
7-
Connect-S3Mgmt -Name cbc-sg-adm1.muccbc.hq.netapp.com -Credential $credential -Insecure
7+
Connect-S3MgmtServer -Name cbc-sg-adm1.muccbc.hq.netapp.com -Credential $credential -Insecure
88

99
# retrieve all S3 Accounts
1010
Get-S3Accounts
@@ -20,4 +20,4 @@ $Accounting = foreach ($Account in Get-S3Accounts) {
2020
Write-Output $Output
2121
}
2222

23-
Export-Csv -Path C:\tmp\usage.csv -NoTypeInformation -InputObject $Accounting
23+
$Accounting | Export-Csv -Path C:\tmp\usage.csv -NoTypeInformation

src/S3-Mgmt.ps1 renamed to src/S3-Mgmt.psm1

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,36 @@ function global:Connect-S3MgmtServer {
145145
#>
146146
function Global:Get-S3Accounts {
147147
[CmdletBinding()]
148+
149+
PARAM ()
150+
151+
Begin {
152+
if (!$CurrentS3MgmtServer) {
153+
Write-Error "No S3 management server found. Please run Connect-S3MgtServer to continue."
154+
}
155+
$Result = $null
156+
}
148157

149-
$Uri = $CurrentS3MgmtServer.BaseURI + '/api/v1/service-provider/s3-accounts'
158+
Process {
159+
$Uri = $CurrentS3MgmtServer.BaseURI + '/api/v1/service-provider/s3-accounts'
160+
161+
150162

151-
try {
152-
$Result = Invoke-RestMethod -Method GET -Uri $Uri -Headers $CurrentS3MgmtServer.Headers
153-
}
154-
catch {
155-
$Response = $_.Exception.Response
156-
$Result = $Response.GetResponseStream()
157-
$Reader = New-Object System.IO.StreamReader($Result)
158-
$responseBody = $reader.ReadToEnd()
159-
Write-Error "GET to $Uri failed with response:`n$responseBody"
160-
}
163+
try {
164+
$Result = Invoke-RestMethod -Method GET -Uri $Uri -Headers $CurrentS3MgmtServer.Headers
165+
}
166+
catch {
167+
$Response = $_.Exception.Response
168+
if ($Response) {
169+
$Result = $Response.GetResponseStream()
170+
$Reader = New-Object System.IO.StreamReader($Result)
171+
$responseBody = $reader.ReadToEnd()
172+
}
173+
Write-Error "GET to $Uri failed with response:`n$responseBody"
174+
}
161175

162-
Write-Output $Result.data
176+
Write-Output $Result.data
177+
}
163178
}
164179

165180
<#
@@ -180,6 +195,9 @@ function Global:Get-S3Account {
180195
)
181196

182197
Begin {
198+
if (!$CurrentS3MgmtServer) {
199+
Write-Error "No S3 management server found. Please run Connect-S3MgtServer to continue."
200+
}
183201
$Result = $null
184202
}
185203

@@ -193,9 +211,11 @@ function Global:Get-S3Account {
193211
}
194212
catch {
195213
$Response = $_.Exception.Response
196-
$Result = $Response.GetResponseStream()
197-
$Reader = New-Object System.IO.StreamReader($Result)
198-
$responseBody = $reader.ReadToEnd()
214+
if ($Response) {
215+
$Result = $Response.GetResponseStream()
216+
$Reader = New-Object System.IO.StreamReader($Result)
217+
$responseBody = $reader.ReadToEnd()
218+
}
199219
Write-Error "GET to $Uri failed with response:`n$responseBody"
200220
}
201221

@@ -222,6 +242,9 @@ function Global:Get-S3AccountUsage {
222242
)
223243

224244
Begin {
245+
if (!$CurrentS3MgmtServer) {
246+
Write-Error "No S3 management server found. Please run Connect-S3MgtServer to continue."
247+
}
225248
$Result = $null
226249
}
227250

@@ -235,9 +258,11 @@ function Global:Get-S3AccountUsage {
235258
}
236259
catch {
237260
$Response = $_.Exception.Response
238-
$Result = $Response.GetResponseStream()
239-
$Reader = New-Object System.IO.StreamReader($Result)
240-
$responseBody = $reader.ReadToEnd()
261+
if ($Response) {
262+
$Result = $Response.GetResponseStream()
263+
$Reader = New-Object System.IO.StreamReader($Result)
264+
$responseBody = $reader.ReadToEnd()
265+
}
241266
Write-Error "GET to $Uri failed with response:`n$responseBody"
242267
}
243268

tools/release.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ New-ModuleManifest `
4848
-Author $Author `
4949
-CompanyName $Company `
5050
-Copyright "(c) $((Get-Date).Year) $Company. All rights reserved." `
51-
-Description 'OnCommand-Insight Powershell Cmdlet.' `
51+
-Description 'StorageGRID S3 Management Powershell Cmdlet.' `
5252
-PowerShellVersion '3.0' `
5353
-DotNetFrameworkVersion '4.0' `
5454
-NestedModules (Get-ChildItem $src\*.psm1 | % { $_.Name }) `
@@ -75,7 +75,7 @@ Write-Host "Creating the release archive..."
7575
# Requires .NET 4.5
7676
[Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null
7777

78-
$zipFileName = Join-Path ([System.IO.Path]::GetDirectoryName($dst)) "$([System.IO.Path]::GetFileNameWithoutExtension($manifestFileName))-$ModuleVersion.zip"
78+
$zipFileName = Join-Path ([System.IO.Path]::GetDirectoryName($dst)) "$([System.IO.Path]::GetFileNameWithoutExtension($manifestFileName)).zip"
7979

8080
# Overwrite the ZIP if it already exists.
8181
if (Test-Path $zipFileName) {

0 commit comments

Comments
 (0)