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 にアクセスする
まだインストールしていない場合は、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" }コマンドの出力を保持します。
appId、password、tenantの値が必要です。
OAuth アクセス トークンを要求します。
この記事の例では cURL を使用します。 Postman、不眠症、Paw などのさまざまな API ツールを使用することもできます。
次の例の変数を、上記の手順 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 Files 名前空間のルートを指します。
https://management.azure.com/subscriptions/SUBIDGOESHERE/resourceGroups/RESOURCEGROUPGOESHERE/providers/Microsoft.NetApp/netAppAccounts?api-version=2022-05-01
次の例の SUBIDGOESHERE と RESOURCEGROUPGOESHERE の値は、独自の値に置き換える必要があります。
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 の例をファイルに保存し、curl コマンドに -d @<filename> を追加します。
#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 値を取得できます。