Skip to content

Commit

Permalink
Prepare for release stable version for Azure.ResourceManager and Azur…
Browse files Browse the repository at this point in the history
…e.ResourceManager.Resources. (Azure#28028)

* Prepare for release stable version for Azure.ResourceManager and Azure.ResourceManager.Resources.

* Update csproj files

* minor fix

* Fix samples

* Minor updates

* Minor fixes

* Update the contributing part

* Update sample code

* Update release date

* update release date

* rename ResourcesMoveInfo to ResourcesMoveContent

* regen after merge and update api

* rename ArmDeploymentInput to ArmDeploymentContent and ArmDeploymentWhatIf to ArmDeploymentWhatIfContent

Co-authored-by: m-nash <prognash@gmail.com>
  • Loading branch information
ArthurMa1978 and m-nash authored Apr 7, 2022
1 parent 92819af commit dc751ff
Show file tree
Hide file tree
Showing 30 changed files with 635 additions and 560 deletions.
344 changes: 344 additions & 0 deletions doc/dev/mgmt_quickstart.md

Large diffs are not rendered by default.

276 changes: 1 addition & 275 deletions doc/mgmt_preview_quickstart.md
Original file line number Diff line number Diff line change
@@ -1,276 +1,2 @@

# Quickstart Tutorial - Resource Management (Preview Libraries)

We are excited to announce that a new set of management libraries are
now in Public Preview. Those packages share a number of new features
such as Azure Identity support, HTTP pipeline, error-handling.,etc, and
they also follow the new Azure SDK guidelines which create easy-to-use
APIs that are idiomatic, compatible, and dependable.

You can find the details of those new libraries
[here](https://azure.github.io/azure-sdk/releases/latest/#dotnet)

In this basic quickstart guide, we will walk you through how to
authenticate to Azure using the preview libraries and start interacting
with Azure resources. There are several possible approaches to
authentication. This document illustrates the most common scenario.

## Getting started

### Install the package

Install the Azure Compute management library for .NET with [NuGet](https://www.nuget.org/):

```PowerShell
Install-Package Azure.ResourceManager.Compute -Version 1.0.0-beta.1
```

### Prerequisites

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

Some options are:

- Through the [Azure CLI Login](https://docs.microsoft.com/cli/azure/authenticate-azure-cli).
- Via [Visual Studio](https://docs.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#authenticating-via-visual-studio).
- Setting [Environment Variables](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/resourcemanager/Azure.ResourceManager/docs/AuthUsingEnvironmentVariables.md).

More information and different authentication approaches using Azure Identity can be found in [this document](https://docs.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet).

### 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:

```C# Snippet:Readme_AuthClient
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](https://docs.microsoft.com/dotnet/api/azure.identity.defaultazurecredential).

### Understanding Azure Resource Hierarchy

In new management libraries, we no longer provide various clients like `ResourceManagementClient` or `ComputeMangementClient`. Instead, we adopt a hierarchical resource model. **Before you continue, make sure you go through the concepts of the Azure .NET SDK [here](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/resourcemanager/Azure.ResourceManager/README.md#key-concepts).**

----

## Interacting with Azure Resources

Now that we are authenticated, we can use our `ArmClient` to make API calls. Let's demonstrate the hierarchical APIs by concrete examples.

For the examples below, you need the following namespaces:

```csharp
using System;
using System.Threading.Tasks;
using Azure.Identity;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
```

### Example: Managing Resource Groups

We can use the `ResourceGroupContainer` to perform operations on Resource Group. In the following code snippets, we will demonstrate how to manage Resource Groups.

#### Create a resource group

```csharp
// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup container for that subscription
Subscription subscription = armClient.DefaultSubscription;
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();

// With the container, we can create a new resource group with an specific name
string rgName = "myRgName";
Location location = Location.WestUS2;
ResourceGroupData rgData = new ResourceGroupData(location);
ResourceGroup resourceGroup = await rgContainer.CreateOrUpdateAsync(rgName, rgData);
```

#### Update a resource group

```csharp
// Note: Resource group named 'myRgName' should exist for this example to work.
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
resourceGroup = await resourceGroup.AddTagAsync("key", "value");
```

#### List all resource groups

```csharp
// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
// Now we get a ResourceGroup container for that subscription
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();
// With GetAllAsync(), we can get a list of the resources in the container
await foreach (ResourceGroup rg in rgContainer.GetAllAsync())
{
Console.WriteLine(rg.Data.Name);
}
```

#### Delete a resource group

```csharp
// Note: Resource group named 'myRgName' should exist for this example to work.
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
await resourceGroup.DeleteAsync();
```

### Example: Managing Virtual Machines

We can use `VirtualMachineContainer` to perform operations on Virtual Machine. In the following code snippets, we will demonstrate how to manage Virtual Machine.

#### Create a virtual machine

```csharp
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
// Now we get the virtual machine container from the resource group
VirtualMachineContainer vmContainer = resourceGroup.GetVirtualMachines();
// Use the same location as the resource group
string vmName = "myVM";
VirtualMachineData input = new VirtualMachineData(resourceGroup.Data.Location)
{
HardwareProfile = new HardwareProfile()
{
VmSize = VirtualMachineSizeTypes.StandardF2
},
OsProfile = new OSProfile()
{
AdminUsername = "adminUser",
ComputerName = "myVM",
LinuxConfiguration = new LinuxConfiguration()
{
DisablePasswordAuthentication = true,
Ssh = new SshConfiguration()
{
PublicKeys = {
new SshPublicKeyInfo()
{
Path = $"/home/adminUser/.ssh/authorized_keys",
KeyData = "<value of the public ssh key>",
}
}
}
}
},
NetworkProfile = new NetworkProfile()
{
NetworkInterfaces =
{
new NetworkInterfaceReference()
{
Id = "/subscriptions/<subscriptionId>/resourceGroups/<rgName>/providers/Microsoft.Network/networkInterfaces/<nicName>",
Primary = true,
}
}
},
StorageProfile = new StorageProfile()
{
OsDisk = new OSDisk(DiskCreateOptionTypes.FromImage)
{
OsType = OperatingSystemTypes.Linux,
Caching = CachingTypes.ReadWrite,
ManagedDisk = new ManagedDiskParameters()
{
StorageAccountType = StorageAccountTypes.StandardLRS
}
},
ImageReference = new ImageReference()
{
Publisher = "Canonical",
Offer = "UbuntuServer",
Sku = "16.04-LTS",
Version = "latest",
}
}
};
VirtualMachineCreateOrUpdateOperation lro = await vmContainer.CreateOrUpdateAsync(vmName, input);
VirtualMachine vm = lro.Value;
```

#### List all virtual machines

```csharp
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
// Now we get the virtual machine container from the resource group
VirtualMachineContainer vmContainer = resourceGroup.GetVirtualMachines();
// With ListAsync(), we can get a list of the virtual machines in the container
AsyncPageable<VirtualMachine> response = vmContainer.GetAllAsync();
await foreach (VirtualMachine vm in response)
{
Console.WriteLine(vm.Data.Name);
}
```

#### Delete a virtual machine

```csharp
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
// Now we get the virtual machine container from the resource group
VirtualMachineContainer vmContainer = resourceGroup.GetVirtualMachines();
string vmName = "myVM";
VirtualMachine vm = await vmContainer.GetAsync(vmName);
await vm.DeleteAsync();
```

## Code Samples

More code samples for using the management library for .NET can be found in the following locations

- [.NET Management Library Code Samples](https://docs.microsoft.com/samples/browse/?branch=master&languages=csharp&term=managing%20using%20Azure%20.NET%20SDK&terms=managing%20using%20Azure%20.NET%20SDK)

## Need help?

- File an issue via [Github
Issues](https://github.com/Azure/azure-sdk-for-net/issues) and
make sure you add the "Preview" label to the issue
- Check [previous
questions](https://stackoverflow.com/questions/tagged/azure+.net)
or ask new ones on StackOverflow using azure and .NET tags.

## 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.
This article has been deprcated since we have released stable version of the new managment libraries, and here is the new [Getting started](https://github.com/Azure/azure-sdk-for-net/blob/main/doc/dev/mgmt_quickstart.md).
13 changes: 7 additions & 6 deletions sdk/resourcemanager/Azure.ResourceManager/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Release History

## 1.0.0-beta.10 (Unreleased)

### Features Added
## 1.0.0 (2022-04-07)
This is the first stable release of the Azure Resources management core library.

### Breaking Changes

### Bugs Fixed

### Other Changes
Minor changes since the public beta release:
- All `Tag` methods have been removed from `SubscriptionResource` as the service doesn't support these operations.
- Simplify `type` property names.
- Normalized the body parameter type names for PUT / POST / PATCH operations if it is only used as input.
- Tweaked some properties to right type.

## 1.0.0-beta.9 (2022-03-31)

Expand Down
12 changes: 6 additions & 6 deletions sdk/resourcemanager/Azure.ResourceManager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ This package follows the [new Azure SDK guidelines](https://azure.github.io/azur

### Install the package

Install the Azure Resources management library for .NET with [NuGet](https://www.nuget.org/):
Install the Azure Resources management core library for .NET with [NuGet](https://www.nuget.org/):

```PowerShell
Install-Package Azure.ResourceManager -Version 1.0.0-beta.9
Install-Package Azure.ResourceManager -Version 1.0.0
```

### Prerequisites
Expand Down Expand Up @@ -56,7 +56,7 @@ To reduce both the number of clients needed to perform common tasks and the amou

To accomplish this, we're introducing 3 standard types for all resources in Azure:

### **[Resource].cs**
### **[Resource]Resource.cs**

This represents a full resource client object which contains a **Data** property exposing the details as a **[Resource]Data** type.
It also has access to all of the operations on that resource without needing to pass in scope parameters such as subscription ID or resource name. This makes it very convenient to directly execute operations on the result of list calls
Expand Down Expand Up @@ -139,7 +139,7 @@ Console.WriteLine($"Subnet: {id.Name}");
## Managing Existing Resources By Id
Performing operations on resources that already exist is a common use case when using the management client libraries. In this scenario you usually have the identifier of the resource you want to work on as a string. Although the new object hierarchy is great for provisioning and working within the scope of a given parent, it is not the most efficient when it comes to this specific scenario.

Here is an example how you to access an `AvailabilitySet` object and manage it directly with its id:
Here is an example how you can access an `AvailabilitySet` object and manage it directly with its id:
```C# Snippet:Readme_ManageAvailabilitySetOld
ResourceIdentifier id = new ResourceIdentifier("/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/workshop2021-rg/providers/Microsoft.Compute/availabilitySets/ws2021availSet");
// We construct a new client to work with
Expand Down Expand Up @@ -319,7 +319,7 @@ To run test with code coverage and auto generate an html report with just a sing

## Troubleshooting

- If you find a bug or have a suggestion, file an issue via [GitHub issues](https://github.com/Azure/azure-sdk-for-net/issues) and make sure you add the "Preview" label to the issue.
- If you find a bug or have a suggestion, file an issue via [GitHub issues](https://github.com/Azure/azure-sdk-for-net/issues) and make sure you add the "Mgmt" label to the issue.
- If you need help, check [previous
questions](https://stackoverflow.com/questions/tagged/azure+.net)
or ask new ones on StackOverflow using azure and .NET tags.
Expand All @@ -333,7 +333,7 @@ To run test with code coverage and auto generate an html report with just a sing
- [.NET Management Library Code Samples](https://docs.microsoft.com/samples/browse/?branch=master&languages=csharp&term=managing%20using%20Azure%20.NET%20SDK)

### Additional Documentation
If you are migrating from the old SDK to this preview, check out this [Migration guide](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/resourcemanager/Azure.ResourceManager/docs/MigrationGuide.md).
If you are migrating from the old SDK, check out this [Migration guide](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/resourcemanager/Azure.ResourceManager/docs/MigrationGuide.md).

For more information on Azure SDK, please refer to [this website](https://azure.github.io/azure-sdk/).

Expand Down
Loading

0 comments on commit dc751ff

Please sign in to comment.