共用方式為


使用 REST API 為 Azure NetApp Files 進行開發

Azure NetApp Files 服務的 REST API,會根據 NetApp 帳戶、容量集區、磁碟區和快照集等資源定義 HTTP 作業。 本文可協助您開始使用 Azure NetApp Files REST API。

Azure NetApp Files REST API 規格

Azure NetApp Files 的 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 Resource Manager HTTP 429 回應碼

存取 Azure NetApp Files REST API

  1. 安裝 Azure CLI (如果您尚未安裝)。

  2. 在 Microsoft Entra ID 中建立服務主體:

    1. 確認您擁有足夠的權限

    2. 在 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" 
      } 
      

      保留命令輸出。 您需要 appIdpasswordtenant 值。

  3. 要求 OAuth 存取權杖:

    本文中使用 cURL 的範例。 您還可以使用各種 API 工具,例如 PostmanInsomniaPaw

    使用上面步驟 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 秒。 有效期之後,您需要要求新權杖。 將權杖儲存到文字編輯器中。 您在下一個步驟將會用到這些資料。

  4. 傳送測試呼叫,並包含權杖以驗證您對 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 Files 命名空間的根目錄。

https://management.azure.com/subscriptions/SUBIDGOESHERE/resourceGroups/RESOURCEGROUPGOESHERE/providers/Microsoft.NetApp/netAppAccounts?api-version=2022-05-01

您應該以您自己的值,取代下列範例中的 SUBIDGOESHERERESOURCEGROUPGOESHERE 值。

GET 要求範例

您可以使用 GET 要求來查詢訂用帳戶中 Azure NetApp Files 的物件,如下列範例所示:

#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 Files 中建立新的物件,如下列範例所示。 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 值。

下一步