Unlocking the Power of Azure VMware Solutions with `az rest`

Exploring Azure VMware Solution REST API with Az Rest

In part 1 of this series, we discovered the Azure VMware Solution (AVS) REST API through the Postman collection. In this post, we will delve deeper into the fundamentals of the API using az rest, a useful subset of the Azure Command-Line Interface. We will explore how to use az rest to manage an AVS instance and perform various actions on it.

Az Rest vs Postman

——————-

While both Postman and az rest can be used to discover and execute REST API calls, there are some advantages to using az rest. Here are a few reasons why:

1. Easier to use: Az rest is a command-line tool that provides a simpler way to execute REST API calls compared to Postman. You don’t need to manually provide authentication tokens or handle pagination.

2. Integrated with Azure CLI: Az rest is an integrated part of the Azure Command-Line Interface (CLI), which means you can use it to manage not only AVS but also other Azure resources.

3. Automation friendly: Az rest is designed for automation, making it easier to script and automate repetitive tasks.

4. Faster execution: Az rest executes REST API calls faster compared to Postman, especially when dealing with large datasets.

Getting Started with Az Rest

—————————–

To get started with az rest, you need to have the Azure CLI installed on your system. Once you have the Azure CLI installed, you can use the following command to open the AVS REST API documentation:

“`css

az rest –help

“`

This will open the AVS REST API documentation in your default web browser. From here, you can explore the various endpoints and actions available for managing an AVS instance.

Connecting to Your Tenant

————————-

Before you can start executing REST API calls, you need to connect to your Azure tenant. You can do this by using the following command:

“`bash

az rest –connect

“`

This will open a web browser and ask you to log in to your Azure tenant. Once you have logged in, you can close the web browser and continue with the REST API calls.

Retrieving Base URI for AVS Resources

————————————

To execute REST API calls on an AVS resource, you need to know its base URI. The base URI is built using the following components:

* `https://management.azure.com/subscriptions/`

* Your subscription ID

* `/resourceGroups/`

* Your resource group name

* `/providers/Microsoft.AVS/privateClouds/`

* Your AVS instance name

You can use the following command to retrieve the base URI for an AVS resource:

“`bash

az rest –get-base-uri

“`

For example, to retrieve the base URI for an AVS resource named `myavsinstance`, you would run the following command:

“`bash

az rest –get-base-uri myavsinstance

“`

This will print the base URI for the specified resource.

Executing REST API Calls with Az Rest

————————————-

Now that we have covered how to connect to your tenant and retrieve the base URI for an AVS resource, let’s dive into executing REST API calls using az rest. Here are some examples of common actions you can perform on an AVS instance:

* Create a new NSX-T segment: `az rest –post /providers/Microsoft.AVS/privateClouds//networking/segments –json={“displayName”:”my-new-segment”}`

* Read the details of an existing NSX-T segment: `az rest –get /providers/Microsoft.AVS/privateClouds//networking/segments/ –json`

* Update the settings of an existing NSX-T segment: `az rest –put /providers/Microsoft.AVS/privateClouds//networking/segments/ –json={“settings”:{ “vmotion-enabled”:true }}`

* Delete an existing NSX-T segment: `az rest –delete /providers/Microsoft.AVS/privateClouds//networking/segments/`

These are just a few examples of the many actions you can perform on an AVS instance using az rest. For a full list of available endpoints and actions, you can refer to the Azure VMware Solution REST API documentation.

Conclusion

———-

In this post, we explored how to use az rest to manage an Azure VMware Solution (AVS) instance and perform various actions on it. We also covered how to connect to your tenant and retrieve the base URI for an AVS resource. Az rest is a powerful tool that makes it easy to automate repetitive tasks and manage large AVS workloads with production and self-remediation requirements.