Isilon:使用 Powershell 與平台應用程式發展介面 - 建立物件和 RAN

Summary: 本文說明如何使用Powershell與 OneFS 平臺應用程式發展介面來建立物件和 RAN。

This article applies to This article does not apply to This article is not tied to any specific product. Not all product versions are identified in this article.

Symptoms

不需要

Cause

不需要

Resolution

JSON 簡介

PAPI 使用 JSON 做為數據互換格式,您必須瞭解如何利用它來使用 PAPI 來建立、修改或刪除資源。您可以 www.json.org 進一步瞭解 JSON 但關鍵原則是,它是完整的獨立程式設計語言,並建立在兩種結構之上:
  • 名稱/值成對集合
  • 訂購的值清單

取得系統物件的輸出範例會如下所示:

{
“object>”<:{
「<property>」: <value>,
...
}

若要瞭解建立物件需要 POST 的 JSON 文字,請傳送下列要求來查看 PAPI 自我檔:
GET /platform/1/quota/quotas?說明 

以下為相關的 Powershell 程式代碼:

#Get 配額的
PAPI 自我說明檔$resource = 「/platform/1/quota/quotas??」說明「
$uri = $baseurl + $resource
$ISIObject = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get
$ISIObject

 

下方的範例輸出概述建立新配額所需的 POST。請注意所需屬性,因為這些內容可能與對應 的 isi 命令所需的屬性不同。

SLN319398_en_US__1i_isilon_1-powershell

使用範例內容,以下是可用於建立目錄硬配額的 JSON 字串範例:

$QuotaObject = @“
{”type“:”directory“,”include_snapshots“: false,container”: true, “path”:/ifs/home/user1“, ”enforced“: true, ”thresholds“:{“hard”:100000000},“thresholds_include_overhead”:false}
”@ 

JSON 字串完成後,剩下的就是建立 Invoke-RestMethod 參數並提交。在下面的範例代碼中,JSON 字串是 POST 的正文,內容類型為 application/json

$headers = @{“Authorization”=“Basic $($EncodedPassword)”}
$uri = $baseurl + $resource
$ISIObject = Invoke-RestMethod -Uri $uri -Headers $headers -Body $QuotaObject -ContentType “application/json;charset=utf-8“ -Method POST
Write-Host ” Resulting Quota ID:「 $ISIObject.id

將一切結合在一起

舉例來說,假設您的環境在單一父目錄下有許多使用者主目錄 (例如:/ifs/home) 和您想要為每個主目錄設定目錄配額。使用Isilon RESTful Namespace (RAN) 應用程式發展介面存取每個使用者主目錄的路徑。下列代碼會取得指定路徑的子目錄,然後在每個子目錄上設定目錄配額:
 

# 取得指定
路徑的子目錄$resource = '/namespace/' + $path
$uri = $baseurl + $resource
$ISIObject = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get
#Loop 目錄並設定 ForEach
($folder在 $ISIObject.children) {

#Create 配額
$resource =“/platform/1/quota/quotas”
Write-Host “Setting a $quotasize byte quota on $quotapath”
$QuotaObject = @“
{“type”:“directory”,“include_snapshots”: false,container“: true, ”path“:「$quotapath」,「強制」:true,「thresholds」:{“hard”:$quotasize},“thresholds_include_overhead”: false}
“@
$headers = @{”Authorization“=”Basic $($EncodedPassword)“}
$uri = $baseurl + $resource
$ISIObject 2 = Invoke-RestMethod -Uri $uri -Headers $headers -Body $QuotaObject -ContentType ”application/json;charset=utf-8“ -Method POST
Write-Host ” Resulting Quota ID:「$ISIObject2.id
}

以下是執行附加至此 Post 之腳本的輸出:

SLN319398_en_US__2i_isilon_2-powershell
SLN319398_en_US__3i_isilon_3-powershell

Affected Products

Isilon, PowerScale OneFS, Isilon Platform API
Article Properties
Article Number: 000132770
Article Type: Solution
Last Modified: 12 Oct 2023
Version:  5
Find answers to your questions from other Dell users
Support Services
Check if your device is covered by Support Services.