protected async Task <GenericResource> deployWindowsNetworkAgent(string virtualMachineName, string location, ResourceGroup resourceGroup) { var extensionId = new ResourceIdentifier($"{resourceGroup.Id}/providers/Microsoft.Compute/virtualMachines/{virtualMachineName}/extensions/NetworkWatcherAgent"); return((await ArmClient.GetGenericResources().CreateOrUpdateAsync(true, extensionId, new GenericResourceData(location) { Properties = new Dictionary <string, object> { { "publisher", "Microsoft.Azure.NetworkWatcher" }, { "typeHandlerVersion", "1.4" }, { "type", "NetworkWatcherAgentWindows" }, } })).Value); //VirtualMachineExtensionData parameters = new VirtualMachineExtensionData(location) //{ // Publisher = "Microsoft.Azure.NetworkWatcher", // TypeHandlerVersion = "1.4", // TypePropertiesType = "NetworkWatcherAgentWindows" //}; //VirtualMachineExtensionCreateOrUpdateOperation createOrUpdateOperation = await vm.GetVirtualMachineExtensionVirtualMachines().CreateOrUpdateAsync("NetworkWatcherAgent", parameters); //await createOrUpdateOperation.WaitForCompletionAsync();; }
public async Task <GenericResource> CreateLinuxVM(string vmName, string networkInterfaceName, string location, ResourceGroup resourceGroup) { Subscription subscription = await ArmClient.GetDefaultSubscriptionAsync(); var vnet = await CreateVirtualNetwork(Recording.GenerateAssetName("vnet_"), Recording.GenerateAssetName("subnet_"), location, resourceGroup.GetVirtualNetworks()); var networkInterface = await CreateNetworkInterface(networkInterfaceName, null, vnet.Data.Subnets[0].Id, location, Recording.GenerateAssetName("ipconfig_"), resourceGroup.GetNetworkInterfaces()); var adminUsername = Recording.GenerateAssetName("admin"); var vmId = new ResourceIdentifier($"{resourceGroup.Id}/providers/Microsoft.Compute/virtualMachines/{vmName}"); var genericResouces = subscription.GetGenericResources(); var data = new GenericResourceData(location) { Properties = new Dictionary <string, object> { { "hardwareProfile", new Dictionary <string, object> { { "vmSize", "Standard_F2" } } }, { "storageProfile", new Dictionary <string, object> { { "imageReference", new Dictionary <string, object> { { "sku", "16.04-LTS" }, { "publisher", "Canonical" }, { "version", "latest" }, { "offer", "UbuntuServer" } } }, { "osDisk", new Dictionary <string, object> { { "name", $"{vmName}_os_disk" }, { "osType", "Linux" }, { "caching", "ReadWrite" }, { "createOption", "FromImage" }, { "managedDisk", new Dictionary <string, object> { { "storageAccountType", "Standard_LRS" } } } } } } }, { "osProfile", new Dictionary <string, object> { { "adminUsername", adminUsername }, { "computerName", vmName }, { "linuxConfiguration", new Dictionary <string, object> { { "ssh", new Dictionary <string, object> { { "publicKeys", new List <object> { new Dictionary <string, object> { { "path", $"/home/{adminUsername}/.ssh/authorized_keys" }, { "keyData", dummySSHKey } } } } } }, { "disablePasswordAuthentication", true }, } }, } }, { "networkProfile", new Dictionary <string, object> { { "networkInterfaces", new List <object> { new Dictionary <string, object> { { "id", networkInterface.Id.ToString() }, { "properties", new Dictionary <string, object> { { "primary", true } } } } } } } } } }; var operation = InstrumentOperation(await ArmClient.GetGenericResources().CreateOrUpdateAsync(true, vmId, data)); operation.WaitForCompletion(); return(operation.Value); }
public async Task <GenericResource> CreateWindowsVM(string vmName, string networkInterfaceName, string location, ResourceGroup resourceGroup) { var vnet = await CreateVirtualNetwork(Recording.GenerateAssetName("vnet_"), Recording.GenerateAssetName("subnet_"), location, resourceGroup.GetVirtualNetworks()); var networkInterface = await CreateNetworkInterface(networkInterfaceName, null, vnet.Data.Subnets[0].Id, location, Recording.GenerateAssetName("ipconfig_"), resourceGroup.GetNetworkInterfaces()); var vmId = new ResourceIdentifier($"{resourceGroup.Id}/providers/Microsoft.Compute/virtualMachines/{vmName}"); Subscription subscription = await ArmClient.GetDefaultSubscriptionAsync(); var genericResouces = subscription.GetGenericResources(); GenericResourceData data = new GenericResourceData(location) { Properties = new Dictionary <string, object> { { "hardwareProfile", new Dictionary <string, object> { { "vmSize", "Standard_D1_v2" } } }, { "storageProfile", new Dictionary <string, object> { { "imageReference", new Dictionary <string, object> { { "sku", "2016-Datacenter" }, { "publisher", "MicrosoftWindowsServer" }, { "version", "latest" }, { "offer", "WindowsServer" } } }, { "osDisk", new Dictionary <string, object> { { "name", $"{vmName}_os_disk" }, { "osType", "Windows" }, { "caching", "ReadWrite" }, { "createOption", "FromImage" }, { "managedDisk", new Dictionary <string, object> { { "storageAccountType", "Standard_LRS" } } } } } } }, { "osProfile", new Dictionary <string, object> { { "adminUsername", Recording.GenerateAssetName("admin") }, { "adminPassword", Recording.GenerateAlphaNumericId("adminPass") }, { "computerName", vmName } } }, { "networkProfile", new Dictionary <string, object> { { "networkInterfaces", new List <object> { new Dictionary <string, object> { { "id", networkInterface.Id.ToString() }, { "properties", new Dictionary <string, object> { { "primary", true } } } } } } } } } }; var operation = InstrumentOperation(await ArmClient.GetGenericResources().CreateOrUpdateAsync(true, vmId, data)); operation.WaitForCompletion(); return(operation.Value); }
public async Task PrivateDnsZoneGroupTest() { virtualNetwork = (await createVirtualNetwork()).Value; storageAccount = await createStorageAccount(); // create var privateEndpointCollection = resourceGroup.GetPrivateEndpoints(); var name = Recording.GenerateAssetName("pe"); System.Console.WriteLine($"Subnet ID: {virtualNetwork.Data.Subnets[0].Id}"); var privateEndpointData = new PrivateEndpointData { Location = TestEnvironment.Location, Subnet = virtualNetwork.Data.Subnets[0], PrivateLinkServiceConnections = { new PrivateLinkServiceConnection { Name = Recording.GenerateAssetName("pec"), // TODO: externalize or create the service on-demand, like virtual network //PrivateLinkServiceId = "/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c/resourceGroups/sdktest7669/providers/Microsoft.KeyVault/vaults/TierRuanKeyVaultJustTest", PrivateLinkServiceId = storageAccount.Id, RequestMessage = "SDK test", GroupIds = { "storage" } } }, }; var privateEndpoint = (await privateEndpointCollection.CreateOrUpdateAsync(WaitUntil.Completed, name, privateEndpointData)).Value; var privateDnsZoneName = Recording.GenerateAssetName("private_dns_zone"); var privateDnsZoneResourceId = new ResourceIdentifier($"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{resourceGroup.Data.Name}/Microsoft.Network/privateDnsZones/{privateDnsZoneName}"); privateDnsZone = ArmClient.GetGenericResources().CreateOrUpdate(WaitUntil.Completed, privateDnsZoneResourceId, new GenericResourceData(TestEnvironment.Location)).Value; var privateDnsZoneGroupName = Recording.GenerateAssetName("private_dns_zone_group"); var privateDnsZoneGroupCollection = privateEndpoint.GetPrivateDnsZoneGroups(); var privateDnsZoneGroup = (await privateDnsZoneGroupCollection.CreateOrUpdateAsync(WaitUntil.Completed, privateDnsZoneGroupName, new PrivateDnsZoneGroupData { PrivateDnsZoneConfigs = { new PrivateDnsZoneConfig { Name = privateDnsZoneName, PrivateDnsZoneId = privateDnsZone.Id, } } })).Value; Assert.IsNotEmpty(privateDnsZoneGroup.Data.PrivateDnsZoneConfigs); Assert.That(privateDnsZoneGroup.Data.PrivateDnsZoneConfigs, Has.Count.EqualTo(1)); Assert.AreEqual(privateDnsZoneName, privateDnsZoneGroup.Data.PrivateDnsZoneConfigs[0].Name); Assert.AreEqual(privateDnsZone.Id, privateDnsZoneGroup.Data.PrivateDnsZoneConfigs[0].PrivateDnsZoneId); // list var groups = (await privateDnsZoneGroupCollection.GetAllAsync().ToEnumerableAsync()); Assert.That(groups, Has.Count.EqualTo(1)); privateDnsZoneGroup = groups[0]; Assert.IsNotEmpty(privateDnsZoneGroup.Data.PrivateDnsZoneConfigs); Assert.That(privateDnsZoneGroup.Data.PrivateDnsZoneConfigs, Has.Count.EqualTo(1)); Assert.AreEqual(privateDnsZoneName, privateDnsZoneGroup.Data.PrivateDnsZoneConfigs[0].Name); Assert.AreEqual(privateDnsZone.Id, privateDnsZoneGroup.Data.PrivateDnsZoneConfigs[0].PrivateDnsZoneId); // get privateDnsZoneGroup = (await privateDnsZoneGroupCollection.GetAsync(privateDnsZoneGroupName)).Value; Assert.IsNotEmpty(privateDnsZoneGroup.Data.PrivateDnsZoneConfigs); Assert.That(privateDnsZoneGroup.Data.PrivateDnsZoneConfigs, Has.Count.EqualTo(1)); Assert.AreEqual(privateDnsZoneName, privateDnsZoneGroup.Data.PrivateDnsZoneConfigs[0].Name); Assert.AreEqual(privateDnsZone.Id, privateDnsZoneGroup.Data.PrivateDnsZoneConfigs[0].PrivateDnsZoneId); // update privateDnsZoneGroup = (await privateDnsZoneGroupCollection.CreateOrUpdateAsync(WaitUntil.Completed, privateDnsZoneGroupName, new PrivateDnsZoneGroupData { })).Value; Assert.IsEmpty(privateDnsZoneGroup.Data.PrivateDnsZoneConfigs); // delete await privateDnsZoneGroup.DeleteAsync(WaitUntil.Completed); // list again groups = (await privateDnsZoneGroupCollection.GetAllAsync().ToEnumerableAsync()); Assert.IsEmpty(groups); await privateEndpoint.DeleteAsync(WaitUntil.Completed); }