你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Azure NetApp 文件的 REST API 针对资源(例如 NetApp 帐户、容量池、卷和快照)定义 HTTP作。 本文可帮助你开始使用 Azure NetApp 文件 REST API。
Azure NetApp 文件 REST API 规范
Azure NetApp 文件的 REST API 规范通过 GitHub 发布:
https://github.com/Azure/azure-rest-api-specs/tree/main/specification/netapp/resource-manager
注意事项
超过 API 限制后,HTTP 响应代码为 429。 例如:
"Microsoft.Azure.ResourceProvider.Common.Exceptions.ResourceProviderException: Error getting Pool. Rate limit exceeded for this endpoint - try again later ---> CloudVolumes.Service.Client.Client.ApiException: Error calling V2DescribePool: {\"code\":429,\"message\":\"Rate limit exceeded for this endpoint - try again later\"}此响应代码可能来自限制或临时条件。 有关详细信息,请参阅 Azure 资源管理器 HTTP 429 响应代码 。
访问 Azure NetApp 文件 REST API
安装 Azure CLI(如果尚未安装)。
在 Microsoft Entra ID 中创建服务主体:
验证你是否具有 足够的权限。
在 Azure CLI 中输入以下命令:
az ad sp create-for-rbac --name $YOURSPNAMEGOESHERE --role Contributor --scopes /subscriptions/{subscription-id}命令输出类似于以下示例:
{ "appId": "appIDgoeshere", "displayName": "APPNAME", "name": "http://APPNAME", "password": "supersecretpassword", "tenant": "tenantIDgoeshere" }保留命令输出。 需要值
appIdpassword和tenant值。
请求 OAuth 访问令牌:
本文中的示例使用 cURL。 还可以使用各种 API 工具,例如 Postman、 失眠和 Paw。
将以下示例中的变量替换为上述步骤 2 的命令输出。
curl -X POST -d 'grant_type=client_credentials&client_id=[APP_ID]&client_secret=[PASSWORD]&resource=https%3A%2F%2Fmanagement.azure.com%2F' https://login.microsoftonline.com/[TENANT_ID]/oauth2/token输出提供类似于以下示例的访问令牌:
eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Im5iQ3dXMTF3M1hrQi14VWFYd0tSU0xqTUhHUSIsImtpZCI6Im5iQ3dXMTF3M1hrQi14VWFYd0tSU0xqTUhHUSJ9显示的令牌有效期为 3600 秒。 之后,需要请求新的令牌。 将令牌保存到文本编辑器。 下一步需要用到它。
发送测试调用并包括令牌,以验证对 REST API 的访问权限:
curl -X GET -H "Authorization: Bearer [TOKEN]" -H "Content-Type: application/json" https://management.azure.com/subscriptions/[SUBSCRIPTION_ID]/providers/Microsoft.Web/sites?api-version=2022-05-01
使用 API 的示例
本文对请求基线使用以下 URL。 此 URL 指向 Azure NetApp 文件命名空间的根目录。
https://management.azure.com/subscriptions/SUBIDGOESHERE/resourceGroups/RESOURCEGROUPGOESHERE/providers/Microsoft.NetApp/netAppAccounts?api-version=2022-05-01
应将以下示例中的和RESOURCEGROUPGOESHERE值替换为SUBIDGOESHERE自己的值。
GET 请求示例
使用 GET 请求查询订阅中 Azure NetApp 文件的对象,如以下示例所示:
#get NetApp accounts
curl -X GET -H "Authorization: Bearer TOKENGOESHERE" -H "Content-Type: application/json" https://management.azure.com/subscriptions/SUBIDGOESHERE/resourceGroups/RESOURCEGROUPGOESHERE/providers/Microsoft.NetApp/netAppAccounts?api-version=2022-05-01
#get capacity pools for NetApp account
curl -X GET -H "Authorization: Bearer TOKENGOESHERE" -H "Content-Type: application/json" https://management.azure.com/subscriptions/SUBIDGOESHERE/resourceGroups/RESOURCEGROUPGOESHERE/providers/Microsoft.NetApp/netAppAccounts/NETAPPACCOUNTGOESHERE/capacityPools?api-version=2022-05-01
#get volumes in NetApp account & capacity pool
curl -X GET -H "Authorization: Bearer TOKENGOESHERE" -H "Content-Type: application/json" https://management.azure.com/subscriptions/SUBIDGOESHERE/resourceGroups/RESOURCEGROUPGOESHERE/providers/Microsoft.NetApp/netAppAccounts/NETAPPACCOUNTGOESHERE/capacityPools/CAPACITYPOOLGOESHERE/volumes?api-version=2022-05-01
#get snapshots for a volume
curl -X GET -H "Authorization: Bearer TOKENGOESHERE" -H "Content-Type: application/json" https://management.azure.com/subscriptions/SUBIDGOESHERE/resourceGroups/RESOURCEGROUPGOESHERE/providers/Microsoft.NetApp/netAppAccounts/NETAPPACCOUNTGOESHERE/capacityPools/CAPACITYPOOLGOESHERE/volumes/VOLUMEGOESHERE/snapshots?api-version=2022-05-01
PUT 请求示例
使用 PUT 请求在 Azure NetApp 文件中创建新对象,如以下示例所示。 PUT 请求的正文可以包含更改的 JSON 格式数据。 它必须作为文本或作为文件引用包含在 curl 命令中。 若要将正文引用为文件,请将 json 示例保存到文件中并添加到 -d @<filename> curl 命令。
#create a NetApp account
curl -d @<filename> -X PUT -H "Authorization: Bearer TOKENGOESHERE" -H "Content-Type: application/json" https://management.azure.com/subscriptions/SUBIDGOESHERE/resourceGroups/RESOURCEGROUPGOESHERE/providers/Microsoft.NetApp/netAppAccounts/NETAPPACCOUNTGOESHERE?api-version=2022-05-01
#create a capacity pool
curl -d @<filename> -X PUT -H "Authorization: Bearer TOKENGOESHERE" -H "Content-Type: application/json" https://management.azure.com/subscriptions/SUBIDGOESHERE/resourceGroups/RESOURCEGROUPGOESHERE/providers/Microsoft.NetApp/netAppAccounts/NETAPPACCOUNTGOESHERE/capacityPools/CAPACITYPOOLGOESHERE?api-version=2022-05-01
#create a volume
curl -d @<filename> -X PUT -H "Authorization: Bearer TOKENGOESHERE" -H "Content-Type: application/json" https://management.azure.com/subscriptions/SUBIDGOESHERE/resourceGroups/RESOURCEGROUPGOESHERE/providers/Microsoft.NetApp/netAppAccounts/NETAPPACCOUNTGOESHERE/capacityPools/CAPACITYPOOLGOESHERE/volumes/MYNEWVOLUME?api-version=2022-05-01
#create a volume snapshot
curl -d @<filename> -X PUT -H "Authorization: Bearer TOKENGOESHERE" -H "Content-Type: application/json" https://management.azure.com/subscriptions/SUBIDGOESHERE/resourceGroups/RESOURCEGROUPGOESHERE/providers/Microsoft.NetApp/netAppAccounts/NETAPPACCOUNTGOESHERE/capacityPools/CAPACITYPOOLGOESHERE/volumes/MYNEWVOLUME/Snapshots/SNAPNAME?api-version=2022-05-01
JSON 示例
以下示例演示如何创建 NetApp 帐户:
{
"name": "MYNETAPPACCOUNT",
"type": "Microsoft.NetApp/netAppAccounts",
"location": "westus2",
"properties": {
"name": "MYNETAPPACCOUNT"
}
}
以下示例演示如何创建容量池:
{
"name": "MYNETAPPACCOUNT/POOLNAME",
"type": "Microsoft.NetApp/netAppAccounts/capacityPools",
"location": "westus2",
"properties": {
"name": "POOLNAME",
"size": "4398046511104",
"serviceLevel": "Premium"
}
}
以下示例演示如何创建新卷。 (卷的默认协议为 NFSV3。
{
"name": "MYNEWVOLUME",
"type": "Microsoft.NetApp/netAppAccounts/capacityPools/volumes",
"location": "westus2",
"properties": {
"serviceLevel": "Premium",
"usageThreshold": "322122547200",
"creationToken": "MY-FILEPATH",
"snapshotId": "",
"subnetId": "/subscriptions/SUBIDGOESHERE/resourceGroups/RESOURCEGROUPGOESHERE/providers/Microsoft.Network/virtualNetworks/VNETGOESHERE/subnets/MYDELEGATEDSUBNET.sn"
}
}
以下示例演示如何创建卷的快照:
{
"name": "apitest2/apiPool01/apiVol01/snap02",
"type": "Microsoft.NetApp/netAppAccounts/capacityPools/Volumes/Snapshots",
"location": "westus2",
"properties": {
"name": "snap02",
"fileSystemId": "0168704a-bbec-da81-2c29-503825fe7420"
}
}
注释
需要指定 fileSystemId 用于创建快照。 可以使用对卷的 GET 请求获取 fileSystemId 该值。