Azure C# SDK
Photo by Brett Sayles from Pexels.com |
I took some time to look at Azure SDK for .Net because I am new to it. In this blog, I share my findings, observations, and sample code.
Azure has REST API to manage its services and resources, and here is the Git repo. We can definitely make HTTPS call to Azure API Server once we understand its specification. Alternatively, we can use the Azure SDK for .Net. (there are many examples and resources over here).
Last week, I have the opportunity to try them out, and my sample code are in a public git repo. Most of the code are in Common folder. For example, to create a resource group, we do
using CSharp_Azure_API.Common; using Microsoft.Azure.Management.ResourceManager.Fluent.Core; ... var subscriptionId = EnvironmentVals.GetSubscription(); var credentials = Authentication.GetCredential(); ResourceGroups oResourceGroups = new ResourceGroups(credentials, subscriptionId); oResourceGroups.Create(rgName, Region.USWest);
which in turn calls
public IResourceGroup Create (string name, Region region) { if (this.IsExist (name)) { return this.azure.ResourceGroups.GetByName (name); } return this.azure.ResourceGroups .Define (name) .WithRegion (region) .Create (); }
from
https://github.com/dennisseah/c-azure-resources/blob/master/Common/ResourceGroups.cs#L29
We also provided similar functions for Virtual Machine, PublicIPAddress, etc. The SDK may not be intuitive because it is generated from Azure REST API Specification (here) with autorest (which is a code generator). From autorest git repo, we see that it is capable of generating code for different languages.
Code generation from autorest |
Comments
Post a Comment