Compute Management Rest Client
If you are not familiar with our REST client, please spend 5 minutes to take a look at our REST client docs to use this library, the REST client provides a light-weighted & developer friendly way to call azure rest api
Key links:
- You must have an Azure subscription to use this package.
Install the Azure ComputeManagement client REST client library for JavaScript with npm
:
npm install @azure-rest/arm-compute
To use an Azure Active Directory (AAD) token credential, provide an instance of the desired credential type obtained from the @azure/identity library.
To authenticate with AAD, you must first npm
install @azure/identity
After setup, you can choose which type of credential from @azure/identity
to use.
As an example, DefaultAzureCredential
can be used to authenticate the client.
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
Use the returned token credential to authenticate the client:
import ComputeManagementClient from "@azure-rest/arm-compute";
import { DefaultAzureCredential } from "@azure/identity";
const credential = new DefaultAzureCredential();
const client = ComputeManagementClient(credential);
The following section shows you how to initialize and authenticate your client, then list all of your Virtual Machines within a resource group.
import createComputeManagementClient, {
VirtualMachinesListParameters,
paginate,
} from "@azure-rest/arm-compute";
import { DefaultAzureCredential } from "@azure/identity";
async function virtualMachinesListMaximumSetGen() {
const credential = new DefaultAzureCredential();
const client = createComputeManagementClient(credential);
const subscriptionId = "";
const resourceGroupName = "rgcompute";
const options: VirtualMachinesListParameters = {
queryParameters: {
$filter: "aaaaaaaaaaaaaaaaaaaaaaa",
"api-version": "2022-08-01",
},
};
const initialResponse = await client
.path(
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines",
subscriptionId,
resourceGroupName
)
.get(options);
const pageData = paginate(client, initialResponse);
const result = [];
for await (const item of pageData) {
result.push(item);
}
console.log(result);
}
virtualMachinesListMaximumSetGen().catch(console.error);
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL
environment variable to info
. Alternatively, logging can be enabled at runtime by calling setLogLevel
in the @azure/logger
:
import { setLogLevel } from "@azure/logger";
setLogLevel("info");
For more detailed instructions on how to enable logs, you can look at the @azure/logger package docs.