Skip to content

Commit

Permalink
PrivateDNS: generate package-2018-09 (#913)
Browse files Browse the repository at this point in the history
* PrivateDNS: generate package-2018-09

* PrivateDNS: add in solutions

* PrivateDNS: add interfaces of private zone

* PrivateDNS: add interfaces of private dns record set

* PrivateDNS: add interfaces of records

* PrivateDNS: add implementations of records

* PrivateDNS: add implementations of private zone

* PrivateDNS: add implementations of private dns record set

* PrivateDNS: add private dns manager

* PrivateDNS: add interfaces and implementations for virtual network link

* PrivateDNS: add tests and sample with record sessions

* PrivateDNS: update in test script

* PrivateDNS: fix alignment

* PrivateDNS: update by review comments

* PrivateDNS: update by review comments

* PrivateDNS: fix typo in Azure.cs
  • Loading branch information
xseeseesee committed Dec 10, 2019
1 parent b7c00c1 commit 12e061c
Show file tree
Hide file tree
Showing 110 changed files with 45,783 additions and 33 deletions.
6 changes: 6 additions & 0 deletions Fluent.SDK.sln
Expand Up @@ -21,6 +21,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.KeyVault.Fluent", "src\ResourceManagement\KeyVault\Microsoft.Azure.Management.KeyVault.Fluent.csproj", "{1911A39E-FA13-48F6-A7DD-98B0A7EE973B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.PrivateDns.Fluent", "src\ResourceManagement\PrivateDns\Microsoft.Azure.Management.PrivateDns.Fluent.csproj", "{CEC27EF8-F20B-421D-A429-0EC438E57630}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.Redis.Fluent", "src\ResourceManagement\RedisCache\Microsoft.Azure.Management.Redis.Fluent.csproj", "{399E50C9-629E-4FD3-9F19-B7DFA64C9E40}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.ResourceManager.Fluent", "src\ResourceManagement\ResourceManager\Microsoft.Azure.Management.ResourceManager.Fluent.csproj", "{E5C3B599-F17E-4BE2-9E67-97246EB14162}"
Expand Down Expand Up @@ -81,6 +83,10 @@ Global
{48CCF7A7-1F38-4681-9311-E8FCB1A0EB18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48CCF7A7-1F38-4681-9311-E8FCB1A0EB18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48CCF7A7-1F38-4681-9311-E8FCB1A0EB18}.Release|Any CPU.Build.0 = Release|Any CPU
{CEC27EF8-F20B-421D-A429-0EC438E57630}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CEC27EF8-F20B-421D-A429-0EC438E57630}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CEC27EF8-F20B-421D-A429-0EC438E57630}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CEC27EF8-F20B-421D-A429-0EC438E57630}.Release|Any CPU.Build.0 = Release|Any CPU
{1D87885A-C7DB-4DB8-8572-F0DFC53318AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D87885A-C7DB-4DB8-8572-F0DFC53318AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D87885A-C7DB-4DB8-8572-F0DFC53318AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
7 changes: 7 additions & 0 deletions Fluent.Samples.sln
Expand Up @@ -27,6 +27,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.Network.Fluent", "src\ResourceManagement\Network\Microsoft.Azure.Management.Network.Fluent.csproj", "{83752382-9E71-45FA-813A-15B5F8A6FCB0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.PrivateDns.Fluent", "src\ResourceManagement\PrivateDns\Microsoft.Azure.Management.PrivateDns.Fluent.csproj", "{7ACB3B27-BA2C-4BE9-8D8E-E3C7B265060E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.Redis.Fluent", "src\ResourceManagement\RedisCache\Microsoft.Azure.Management.Redis.Fluent.csproj", "{15B618D3-6FC3-4ECA-A4F8-57F51F3C137D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.ResourceManager.Fluent", "src\ResourceManagement\ResourceManager\Microsoft.Azure.Management.ResourceManager.Fluent.csproj", "{F6070835-D98E-4750-B747-BEBC7D470E8A}"
Expand Down Expand Up @@ -105,6 +107,10 @@ Global
{83752382-9E71-45FA-813A-15B5F8A6FCB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83752382-9E71-45FA-813A-15B5F8A6FCB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83752382-9E71-45FA-813A-15B5F8A6FCB0}.Release|Any CPU.Build.0 = Release|Any CPU
{7ACB3B27-BA2C-4BE9-8D8E-E3C7B265060E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7ACB3B27-BA2C-4BE9-8D8E-E3C7B265060E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7ACB3B27-BA2C-4BE9-8D8E-E3C7B265060E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7ACB3B27-BA2C-4BE9-8D8E-E3C7B265060E}.Release|Any CPU.Build.0 = Release|Any CPU
{15B618D3-6FC3-4ECA-A4F8-57F51F3C137D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{15B618D3-6FC3-4ECA-A4F8-57F51F3C137D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15B618D3-6FC3-4ECA-A4F8-57F51F3C137D}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -176,6 +182,7 @@ Global
{173AD141-C258-4EE6-B85E-90C87DE6A171} = {6FB01238-DA67-4BC0-98B7-01F07947419F}
{4479E694-BCAD-4CD4-9B73-3F1C4629DE5A} = {6FB01238-DA67-4BC0-98B7-01F07947419F}
{83752382-9E71-45FA-813A-15B5F8A6FCB0} = {6FB01238-DA67-4BC0-98B7-01F07947419F}
{7ACB3B27-BA2C-4BE9-8D8E-E3C7B265060E} = {6FB01238-DA67-4BC0-98B7-01F07947419F}
{15B618D3-6FC3-4ECA-A4F8-57F51F3C137D} = {6FB01238-DA67-4BC0-98B7-01F07947419F}
{F6070835-D98E-4750-B747-BEBC7D470E8A} = {6FB01238-DA67-4BC0-98B7-01F07947419F}
{BBBCE191-2051-4610-A3D2-8418646854F1} = {6FB01238-DA67-4BC0-98B7-01F07947419F}
Expand Down
7 changes: 7 additions & 0 deletions Fluent.Tests.sln
Expand Up @@ -38,6 +38,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.Network.Fluent", "src\ResourceManagement\Network\Microsoft.Azure.Management.Network.Fluent.csproj", "{9CAE8EAC-324D-4498-942E-4F8AFA9A4FE0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.PrivateDns.Fluent", "src\ResourceManagement\PrivateDns\Microsoft.Azure.Management.PrivateDns.Fluent.csproj", "{502FAC64-38A0-4035-B512-309E12AB82C8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.Redis.Fluent", "src\ResourceManagement\RedisCache\Microsoft.Azure.Management.Redis.Fluent.csproj", "{D1CF9FCF-097B-4CB5-A1BD-A3432E036DC7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.ResourceManager.Fluent", "src\ResourceManagement\ResourceManager\Microsoft.Azure.Management.ResourceManager.Fluent.csproj", "{07F97082-7478-42B2-9F8C-3D2D167D5A0B}"
Expand Down Expand Up @@ -124,6 +126,10 @@ Global
{9CAE8EAC-324D-4498-942E-4F8AFA9A4FE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9CAE8EAC-324D-4498-942E-4F8AFA9A4FE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9CAE8EAC-324D-4498-942E-4F8AFA9A4FE0}.Release|Any CPU.Build.0 = Release|Any CPU
{502FAC64-38A0-4035-B512-309E12AB82C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{502FAC64-38A0-4035-B512-309E12AB82C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{502FAC64-38A0-4035-B512-309E12AB82C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{502FAC64-38A0-4035-B512-309E12AB82C8}.Release|Any CPU.Build.0 = Release|Any CPU
{D1CF9FCF-097B-4CB5-A1BD-A3432E036DC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1CF9FCF-097B-4CB5-A1BD-A3432E036DC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1CF9FCF-097B-4CB5-A1BD-A3432E036DC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -196,6 +202,7 @@ Global
{05790214-3D01-449E-BFBB-C7F280C53022} = {6861600A-FFF3-49C3-8A91-7174F754EAED}
{B747657A-4CFE-4B3C-A387-B21FAD5AF4C2} = {6861600A-FFF3-49C3-8A91-7174F754EAED}
{9CAE8EAC-324D-4498-942E-4F8AFA9A4FE0} = {6861600A-FFF3-49C3-8A91-7174F754EAED}
{502FAC64-38A0-4035-B512-309E12AB82C8} = {6861600A-FFF3-49C3-8A91-7174F754EAED}
{D1CF9FCF-097B-4CB5-A1BD-A3432E036DC7} = {6861600A-FFF3-49C3-8A91-7174F754EAED}
{07F97082-7478-42B2-9F8C-3D2D167D5A0B} = {6861600A-FFF3-49C3-8A91-7174F754EAED}
{16775A2E-CE93-4A6B-B6C0-EF7AF23238BC} = {6861600A-FFF3-49C3-8A91-7174F754EAED}
Expand Down
187 changes: 187 additions & 0 deletions Samples/PrivateDns/ManagePrivateDns.cs
@@ -0,0 +1,187 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Azure.Management.Compute.Fluent;
using Microsoft.Azure.Management.Compute.Fluent.Models;
using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.Network.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using Microsoft.Azure.Management.Samples.Common;
using System;
using System.Collections.Generic;

namespace ManagePrivateDns
{
public class Program
{
private const string CustomDomainName = "private.contoso.com";

/**
* Azure private DNS sample for managing DNS zones.
* - Creates a private DNS zone (private.contoso.com)
* - Creates a virtual network
* - Link a virtual network
* - Creates test virtual machines
* - Creates an additional DNS record
* - Test the private DNS zone
*/
public static void RunSample(IAzure azure)
{
string rgName = SdkContext.RandomResourceName("rgNEMV_", 24);
string vnName = SdkContext.RandomResourceName("vnetwork1-", 24);
string subnetName = SdkContext.RandomResourceName("subnet1-", 24);
string linkName = SdkContext.RandomResourceName("vnlink1-", 24);
string vm1Name = SdkContext.RandomResourceName("vm1-", 24);
string vm2Name = SdkContext.RandomResourceName("vm2-", 24);
string rsName = SdkContext.RandomResourceName("recordset1-", 24);

try
{
var resourceGroup = azure.ResourceGroups.Define(rgName)
.WithRegion(Region.AsiaSouthEast)
.Create();

//============================================================
// Creates a private DNS zone

Utilities.Log("Creating private DNS zone " + CustomDomainName + "...");
var privateDnsZone = azure.PrivateDnsZones.Define(CustomDomainName)
.WithExistingResourceGroup(resourceGroup)
.Create();

Utilities.Log("Created private DNS zone " + privateDnsZone.Name);
Utilities.Print(privateDnsZone);

//============================================================
// Creates a virtual network

Utilities.Log("Creating virtual network " + vnName + "...");
INetwork virtualNetwork = azure.Networks.Define(vnName)
.WithRegion(Region.AsiaSouthEast)
.WithExistingResourceGroup(resourceGroup)
.WithAddressSpace("10.2.0.0/16")
.WithSubnet(subnetName, "10.2.0.0/24")
.Create();
Utilities.Log("Created virtual network " + virtualNetwork.Name);

//============================================================
// Link a virtual network

Utilities.Log("Creating virtual network link " + linkName + " within private zone " + privateDnsZone.Name + " ...");
privateDnsZone.Update()
.DefineVirtualNetworkLink(linkName)
.EnableAutoRegistration()
.WithReferencedVirtualNetworkId(virtualNetwork.Id)
.WithETagCheck()
.Attach()
.Apply();
Utilities.Log("Linked a virtual network " + virtualNetwork.Id);
Utilities.Print(privateDnsZone);

//============================================================
// Creates test virtual machines

Utilities.Log("Creating first virtual machine " + vm1Name + "...");
var virtualMachine1 = azure.VirtualMachines.Define(vm1Name)
.WithRegion(Region.AsiaSouthEast)
.WithExistingResourceGroup(resourceGroup)
.WithExistingPrimaryNetwork(virtualNetwork)
.WithSubnet(subnetName)
.WithPrimaryPrivateIPAddressDynamic()
.WithoutPrimaryPublicIPAddress()
.WithPopularWindowsImage(KnownWindowsVirtualMachineImage.WindowsServer2012Datacenter)
.WithAdminUsername("azureadmin")
.WithAdminPassword("Azure12345678")
.Create();
Utilities.Log("Created first virtual machine " + virtualMachine1.Name);
Utilities.Log("Starting first virtual machine " + virtualMachine1.Name + "...");
virtualMachine1.Start();
Utilities.Log("Started first virtual machine " + virtualMachine1.Name);

Utilities.Log("Creating second virtual machine " + vm2Name + "...");
var virtualMachine2 = azure.VirtualMachines.Define(vm2Name)
.WithRegion(Region.AsiaSouthEast)
.WithExistingResourceGroup(resourceGroup)
.WithExistingPrimaryNetwork(virtualNetwork)
.WithSubnet(subnetName)
.WithPrimaryPrivateIPAddressDynamic()
.WithoutPrimaryPublicIPAddress()
.WithPopularWindowsImage(KnownWindowsVirtualMachineImage.WindowsServer2012Datacenter)
.WithAdminUsername("Foo12")
.WithAdminPassword("BaR@12!Foo")
.Create();
Utilities.Log("Created second virtual machine " + virtualMachine2.Name);
Utilities.Log("Starting second virtual machine " + virtualMachine2.Name + "...");
virtualMachine2.Start();
Utilities.Log("Started second virtual machine " + virtualMachine2.Name);

//============================================================
// Creates an additional DNS record
Utilities.Log("Creating additional record set " + rsName + "...");
privateDnsZone.Update()
.DefineARecordSet(rsName)
.WithIPv4Address(virtualMachine1.GetPrimaryNetworkInterface().PrimaryPrivateIP)
.Attach()
.Apply();
Utilities.Log("Created additional record set " + rsName);
Utilities.Print(privateDnsZone);

//============================================================
// Test the private DNS zone

string script1 = "New-NetFirewallRule -DisplayName \"Allow ICMPv4-In\" -Protocol ICMPv4";
Utilities.Log("Preparing first command: " + script1);
string script2 = "ping " + virtualMachine1.ComputerName + "." + CustomDomainName;
Utilities.Log("Preparing second command: " + script2);
string script3 = "ping " + rsName + "." + CustomDomainName;
Utilities.Log("Preparing third command: " + script1);

Utilities.Log("Starting to run command...");
var result = virtualMachine2.RunPowerShellScript(new List<string> { script1, script2, script3 }, new List<RunCommandInputParameter>());
foreach (var info in result.Value)
{
Utilities.Log(info.Message);
}
}
finally
{
try
{
Utilities.Log("Deleting Resource Group: " + rgName);
azure.ResourceGroups.DeleteByName(rgName);
Utilities.Log("Deleted Resource Group: " + rgName);
}
catch (Exception)
{
Utilities.Log("Did not create any resources in Azure. No clean up is necessary");
}
}
}

public static void Main(string[] args)
{
try
{
//=================================================================
// Authenticate
var credentials = SdkContext.AzureCredentialsFactory.FromFile(Environment.GetEnvironmentVariable("AZURE_AUTH_LOCATION"));

var azure = Azure
.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(credentials)
.WithDefaultSubscription();

// Print selected subscription
Utilities.Log("Selected subscription: " + azure.SubscriptionId);

RunSample(azure);
}
catch (Exception e)
{
Utilities.Log(e);
}
}
}
}
1 change: 1 addition & 0 deletions Samples/Samples.csproj
Expand Up @@ -118,6 +118,7 @@
<ProjectReference Include="..\src\ResourceManagement\Monitor\Microsoft.Azure.Management.Monitor.Fluent.csproj" />
<ProjectReference Include="..\src\ResourceManagement\Msi\Microsoft.Azure.Management.Msi.Fluent.csproj" />
<ProjectReference Include="..\src\ResourceManagement\Network\Microsoft.Azure.Management.Network.Fluent.csproj" />
<ProjectReference Include="..\src\ResourceManagement\PrivateDns\Microsoft.Azure.Management.PrivateDns.Fluent.csproj" />
<ProjectReference Include="..\src\ResourceManagement\RedisCache\Microsoft.Azure.Management.Redis.Fluent.csproj" />
<ProjectReference Include="..\src\ResourceManagement\ResourceManager\Microsoft.Azure.Management.ResourceManager.Fluent.csproj" />
<ProjectReference Include="..\src\ResourceManagement\Search\Microsoft.Azure.Management.Search.Fluent.csproj" />
Expand Down

0 comments on commit 12e061c

Please sign in to comment.