@GauravMantriの説明をお寄せいただきありがとうございます。
リソースマネージャを使用して作成されたJava APIを使用してVM(非古典的)のリストを取得する方法はありますか。
Virtual Machine RESTためAzureのリファレンスによると、あなたはcommon parameters and headersにauthenticate Azure Resource Manager requestsに必要なthe REST APIを使用して、リソース・グループ内のすべての仮想マシンのリストを取得することができます。
以下は、Java APIを使用したサンプルコードです。
// The parameters include clientId, clientSecret, tenantId, subscriptionId and resourceGroupName.
private static final String clientId = "<client-id>";
private static final String clientSecret = "<key>";
private static final String tenantId = "<tenant-id>";
private static final String subscriptionId = "<subscription-id>";
private static final String resouceGroupName = "<resource-group-name>";
// The function for getting the access token via Class AuthenticationResult
private static AuthenticationResult getAccessTokenFromServicePrincipalCredentials()
throws ServiceUnavailableException, MalformedURLException, ExecutionException, InterruptedException {
AuthenticationContext context;
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
// TODO: add your tenant id
context = new AuthenticationContext("https://login.windows.net/" + tenantId, false, service);
// TODO: add your client id and client secret
ClientCredential cred = new ClientCredential(clientId, clientSecret);
Future<AuthenticationResult> future = context.acquireToken("https://management.azure.com/", cred, null);
result = future.get();
} finally {
service.shutdown();
}
if (result == null) {
throw new ServiceUnavailableException("authentication result was null");
}
return result;
}
// The process for getting the list of VMs in a resource group
Configuration config = ManagementConfiguration.configure(null, new URI("https://management.core.windows.net"),
subscriptionId,
getAccessTokenFromServicePrincipalCredentials().getAccessToken());
ComputeManagementClient client = ComputeManagementService.create(config);
VirtualMachineListResponse listResponse = client.getVirtualMachinesOperations().list(resourceGroupName);
ArrayList<VirtualMachine> list = listResponse.getVirtualMachines();
お返事ありがとうございました。「この目的でAzure ADを使用するには、Azure ADにアプリケーションを作成し、そのアプリケーションにAzure Service Management APIを実行する権限を与える必要があります。この同じアプリケーションは、(Resource Managerを使用して作成された)すべてのVMをフェッチするために使用されますか?そしてそれはその単一のサブスクリプションの下のどのアカウントによっても作成されますか? – Prit
'この同じアプリケーションは、(Resource Managerを使って作成された)すべてのVMをフェッチするために使用されますか? ' - >はい。 「それは単一のサブスクリプションの下でアカウントによって作成されますが? - >私はこれを理解しているかどうかわかりません。あなたは説明してもらえますか? –
ありがとうGaurav!つまり、ADの下にユーザーを作成することができます。これらのユーザーがリソースマネージャーを使用してVMを作成できる場合、ADの下に作成されたこの1つのアプリケーションは、すべてのユーザーによって作成されたVMをフェッチできますか? – Prit