Azure.ResourceManager.Compute 1.0.0-beta.4

Prefix Reserved
This is a prerelease version of Azure.ResourceManager.Compute.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Azure.ResourceManager.Compute --version 1.0.0-beta.4                
NuGet\Install-Package Azure.ResourceManager.Compute -Version 1.0.0-beta.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Azure.ResourceManager.Compute" Version="1.0.0-beta.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Azure.ResourceManager.Compute --version 1.0.0-beta.4                
#r "nuget: Azure.ResourceManager.Compute, 1.0.0-beta.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Azure.ResourceManager.Compute as a Cake Addin
#addin nuget:?package=Azure.ResourceManager.Compute&version=1.0.0-beta.4&prerelease

// Install Azure.ResourceManager.Compute as a Cake Tool
#tool nuget:?package=Azure.ResourceManager.Compute&version=1.0.0-beta.4&prerelease                

Azure Compute Management client library for .NET

This package follows the new Azure SDK guidelines,which provide core capabilities that are shared amongst all Azure SDKs, including:

  • The intuitive Azure Identity library.
  • An HTTP pipeline with custom policies.
  • Error handling.
  • Distributed tracing.

Getting started

Install the package

Install the Azure Compute management library for .NET with NuGet:

Install-Package Azure.ResourceManager.Compute -Version 1.0.0-beta.4

Prerequisites

Set up a way to authenticate to Azure with Azure Identity.

Some options are:

More information and different authentication approaches using Azure Identity can be found in this document.

Authenticate the Client

The default option to create an authenticated client is to use DefaultAzureCredential. Since all management APIs go through the same endpoint, in order to interact with resources, only one top-level ArmClient has to be created.

To authenticate to Azure and create an ArmClient, do the following:

using Azure.Identity;
using Azure.ResourceManager;

// Code omitted for brevity

ArmClient armClient = new ArmClient(new DefaultAzureCredential());

Additional documentation for the Azure.Identity.DefaultAzureCredential class can be found in this document.

Key concepts

Key concepts of the Azure .NET SDK can be found here

Examples

Create an availability set

Before creating an availability set, we need to have a resource group.

ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupCollection rgCollection = subscription.GetResourceGroups();
// With the collection, we can create a new resource group with an specific name
string rgName = "myRgName";
Location location = Location.WestUS2;
ResourceGroupCreateOrUpdateOperation lro = await rgCollection.CreateOrUpdateAsync(rgName, new ResourceGroupData(location));
ResourceGroup resourceGroup = lro.Value;
AvailabilitySetCollection availabilitySetCollection = resourceGroup.GetAvailabilitySets();
string availabilitySetName = "myAvailabilitySet";
AvailabilitySetData input = new AvailabilitySetData(location);
AvailabilitySetCreateOrUpdateOperation lro = await availabilitySetCollection.CreateOrUpdateAsync(availabilitySetName, input);
AvailabilitySet availabilitySet = lro.Value;

Get all availability set in a resource group

// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup collection for that subscription
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupCollection rgCollection = subscription.GetResourceGroups();

string rgName = "myRgName";
ResourceGroup resourceGroup = await rgCollection.GetAsync(rgName);
// First, we get the availability set collection from the resource group
AvailabilitySetCollection availabilitySetCollection = resourceGroup.GetAvailabilitySets();
// With GetAllAsync(), we can get a list of the availability sets in the collection
AsyncPageable<AvailabilitySet> response = availabilitySetCollection.GetAllAsync();
await foreach (AvailabilitySet availabilitySet in response)
{
    Console.WriteLine(availabilitySet.Data.Name);
}

Update an availability set

// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup collection for that subscription
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupCollection rgCollection = subscription.GetResourceGroups();

// With the collection, we can create a new resource group with an specific name
string rgName = "myRgName";
ResourceGroup resourceGroup = await rgCollection.GetAsync(rgName);
AvailabilitySetCollection availabilitySetCollection = resourceGroup.GetAvailabilitySets();
string availabilitySetName = "myAvailabilitySet";
AvailabilitySet availabilitySet = await availabilitySetCollection.GetAsync(availabilitySetName);
// availabilitySet is an AvailabilitySet instance created above
AvailabilitySetUpdate update = new AvailabilitySetUpdate()
{
    PlatformFaultDomainCount = 3
};
AvailabilitySet updatedAvailabilitySet = await availabilitySet.UpdateAsync(update);

Delete an availability set

// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup collection for that subscription
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupCollection rgCollection = subscription.GetResourceGroups();

// With the collection, we can create a new resource group with an specific name
string rgName = "myRgName";
ResourceGroup resourceGroup = await rgCollection.GetAsync(rgName);
AvailabilitySetCollection availabilitySetCollection = resourceGroup.GetAvailabilitySets();
string availabilitySetName = "myAvailabilitySet";
AvailabilitySet availabilitySet = await availabilitySetCollection.GetAsync(availabilitySetName);
// delete the availability set
await availabilitySet.DeleteAsync();

Check if availability set exists

If you just want to verify if the availability set exists, you can use the function CheckIfExists.

ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupCollection rgCollection = subscription.GetResourceGroups();

string rgName = "myRgName";
ResourceGroup resourceGroup = await rgCollection.GetAsync(rgName);
string availabilitySetName = "myAvailabilitySet";
bool exists = await resourceGroup.GetAvailabilitySets().CheckIfExistsAsync(availabilitySetName);

if (exists)
{
    Console.WriteLine($"Availability Set {availabilitySetName} exists.");
}
else
{
    Console.WriteLine($"Availability Set {availabilitySetName} does not exist.");
}

If you want to first check if the availability set exists, and if it does, you want to do something else on it, you should use the function GetIfExists():

// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup collection for that subscription
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupCollection rgCollection = subscription.GetResourceGroups();

string rgName = "myRgName";
ResourceGroup resourceGroup = await rgCollection.GetAsync(rgName);
AvailabilitySetCollection availabilitySetCollection = resourceGroup.GetAvailabilitySets();
string availabilitySetName = "myAvailabilitySet";
AvailabilitySet availabilitySet = await availabilitySetCollection.GetIfExistsAsync(availabilitySetName);

if (availabilitySet == null)
{
    Console.WriteLine($"Availability Set {availabilitySetName} does not exist.");
    return;
}

// At this point, we are sure that availabilitySet is a not null Availability Set, so we can use this object to perform any operations we want.

Add a tag to an availability set

// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup collection for that subscription
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupCollection rgCollection = subscription.GetResourceGroups();

string rgName = "myRgName";
ResourceGroup resourceGroup = await rgCollection.GetAsync(rgName);
AvailabilitySetCollection availabilitySetCollection = resourceGroup.GetAvailabilitySets();
string availabilitySetName = "myAvailabilitySet";
AvailabilitySet availabilitySet = await availabilitySetCollection.GetAsync(availabilitySetName);
// add a tag on this availabilitySet
AvailabilitySet updatedAvailabilitySet = await availabilitySet.AddTagAsync("key", "value");

For more detailed examples, take a look at samples we have available.

Troubleshooting

Next steps

More sample code

Additional Documentation

For more information on Azure SDK, please refer to this website.

Contributing

For details on contributing to this repository, see the contributing guide.

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repositories using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on Azure.ResourceManager.Compute:

Package Downloads
Neon.Kube.Azure

INTERNAL USE ONLY: neonKUBE hosting manager for Azure

ModularPipelines.Azure

Helpers for interacting with Azure.

Ngs.Agent.AzureResources

Package Description

Cloudlib

Package Description

Ngs.Server.Utilities

Package Description

GitHub repositories (6)

Showing the top 5 popular GitHub repositories that depend on Azure.ResourceManager.Compute:

Repository Stars
Azure/azure-sdk-for-net
This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
microsoft/onefuzz
A self-hosted Fuzzing-As-A-Service platform
thomhurst/ModularPipelines
Write your pipelines in C# !
Stratus-Security/Subdominator
The Internets #1 Subdomain Takeover Tool
TheCloudTheory/arm-estimator
ACE (Azure Cost Estimator) - automated cost estimations for ARM Templates, Bicep and Terraform
Version Downloads Last updated
1.7.0-beta.1 2,656 10/15/2024
1.6.0 167,258 8/27/2024
1.5.0 213,750 5/10/2024
1.5.0-beta.1 406 4/26/2024
1.4.0 141,396 2/23/2024
1.4.0-beta.1 272 1/26/2024
1.3.0 85,292 1/2/2024
1.2.1 68,296 11/24/2023
1.2.0 217,032 9/15/2023
1.2.0-beta.3 1,731 8/14/2023
1.2.0-beta.2 980 7/28/2023
1.2.0-beta.1 3,516 6/1/2023
1.1.0 390,247 2/15/2023
1.0.1 136,011 11/29/2022
1.0.0 297,657 7/11/2022
1.0.0-beta.9 36,454 6/14/2022
1.0.0-beta.8 25,845 4/8/2022
1.0.0-beta.7 1,402 3/31/2022
1.0.0-beta.6 13,806 1/29/2022
1.0.0-beta.5 28,663 12/28/2021
1.0.0-beta.4 10,917 12/2/2021
1.0.0-beta.3 12,172 10/29/2021
1.0.0-beta.2 4,854 9/14/2021
1.0.0-beta.1 6,096 8/31/2021