メイン コンテンツにスキップ

 Subscribe

We released 1.1 of the Azure Management Libraries for .NET. This release adds support for:

Cosmos DB Azure Container Service and Registry Active Directory Graph

https://github.com/azure/azure-sdk-for-net/tree/Fluent

Getting started

You can download 1.1 from:

Microsoft_Azure_Management_Fluent

Create a Cosmos DB with DocumentDB API

You can create a Cosmos DB account by using a define() … create() method chain.

var documentDBAccount = azure.DocumentDBAccounts.Define(docDBName)
    .WithRegion(Region.USEast)
    .WithNewResourceGroup(rgName)
    .WithKind(DatabaseAccountKind.GlobalDocumentDB)
    .WithSessionConsistency()
    .WithWriteReplication(Region.USWest)
    .WithReadReplication(Region.USCentral)
    .Create();

In addition, you can:

Create an Azure Container Registry

You can create an Azure Container Registry by using a define() … create() method chain.

var azureRegistry = azure.ContainerRegistries.Define("acrdemo")
       .WithRegion(Region.USEast)
       .WithNewResourceGroup(rgName)
       .WithNewStorageAccount(saName)
       .WithRegistryNameAsAdminUser()
       .Create();

You can get Azure Container Registry credentials by using ListCredentials().

RegistryListCredentials acrCredentials = azureRegistry.ListCredentials();

Create an Azure Container Service with Kubernetes Orchestration

You can create an Azure Container Service by using a define() … create() method chain.

var azureContainerService = azure.ContainerServices.Define(acsName)
      .WithRegion(Region.USEast)
      .WithNewResourceGroup(rgName)
      .WithKubernetesOrchestration()
      .WithServicePrincipal(servicePrincipalClientId, servicePrincipalSecret)
      .WithLinux()
      .WithRootUsername(rootUserName)
      .WithSshKey(sshPublicKey)
      .WithMasterNodeCount(ContainerServiceMasterProfileCount.MIN)
      .WithMasterLeafDomainLabel("dns-myK8S")
      .DefineAgentPool("agentpool")
            .WithVMCount(1)
            .WithVMSize(ContainerServiceVMSizeTypes.StandardD1V2)
            .WithLeafDomainLabel("dns-ap-myK8S")
            .Attach()
      .Create();

Create Service Principal with Subscription Access

You can create a service principal and assign it to a subscription with contributor role by using a define() … create() method chain.

var servicePrincipal = authenticated.ServicePrincipals.Define("spName")
      .WithExistingApplication(activeDirectoryApplication)
      // define credentials
      .DefinePasswordCredential("ServicePrincipalAzureSample")
            .WithPasswordValue("StrongPass!12")
            .Attach()
      // define certificate credentials
      .DefineCertificateCredential("spcert")
            .WithAsymmetricX509Certificate()
            .WithPublicKey(File.ReadAllBytes(certificate.CerPath))
            .WithDuration(TimeSpan.FromDays(7))
            // export credentials to a file
            .WithAuthFileToExport(new StreamWriter
                                     (new FileStream(authFilePath, FileMode.OpenOrCreate)))
            .WithPrivateKeyFile(certificate.PfxPath)
            .WithPrivateKeyPassword(certPassword)
            .Attach()
      .WithNewRoleInSubscription(role, subscriptionId)
      .Create();

Similarly, you can:

Try it

You can get more samples from GitHub. Give it a try and let us know what do you think by emailing us or commenting below.

  • Explore

     

    Let us know what you think of Azure and what you would like to see in the future.

     

    Provide feedback

  • Build your cloud computing and Azure skills with free courses by Microsoft Learn.

     

    Explore Azure learning


Join the conversation