Isilon:将 Powershell 与平台 API 配合使用 — 创建对象和 RAN

Summary: 本文介绍如何将 Powershell 与 OneFS 平台 API 配合使用,以创建对象和 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?describe

以下是相关的 Powershell 代码: 

#Get 配额的 PAPI 自我文档
$resource = “/platform/1/quota/quotas?describe”
$uri = $baseurl + $resource
$ISIObject = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get
$ISIObject

 

下面的示例输出概述了创建新配额时需要开机自检的内容。请注意所需的属性,因为它们可能不是相应 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 命名空间 (RAN) API 访问来获取每个用户主目录的路径。以下代码将获取指定路径的子目录,然后在每个子目录上设置目录配额:
 

# 获取指定
路径的子目录$resource = “/namespace/” + $path
$uri = $baseurl + $resource
$ISIObject = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get
#Loop 通过每个 目录并设置配额
ForEach($folder in $ISIObject.children) {

#Create quota
$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
}

以下是运行附加到此帖子的脚本的输出:

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.