private string GetSubnetAddressPrefix(VirtualMachineScaleSetIPConfiguration ipConfiguration) { if (ipConfiguration?.Subnet == null) { throw new InvalidOperationException(ServiceFabricProperties.Resources.InvalidVmssIpConfiguration); } var subnetId = ipConfiguration.Subnet.Id; var segments = subnetId.Split('/'); if (!segments[segments.Length - 2].Equals("subnets", StringComparison.OrdinalIgnoreCase) || !segments[segments.Length - 4].Equals("virtualNetworks", StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException( string.Format( ServiceFabricProperties.Resources.InvalidNetworkNameInResourceId, subnetId)); } var subnetName = segments[segments.Length - 1]; var virtualNetworkName = segments[segments.Length - 3]; var subnet = NetworkManagementClient.Subnets.Get(this.ResourceGroupName, virtualNetworkName, subnetName); return(subnet.AddressPrefix); }
public void TestVMSSWithMultiCA() { using (MockContext context = MockContext.Start(this.GetType())) { EnsureClientsInitialized(context); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); // Create resource group string rgName = TestUtilities.GenerateName(TestPrefix) + 1; var vmssName = TestUtilities.GenerateName("vmss"); string storageAccountName = TestUtilities.GenerateName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; bool passed = false; try { var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); var vnetResponse = CreateVNETWithSubnets(rgName, 2); var vmssSubnet = vnetResponse.Subnets[1]; var secondaryCA = new VirtualMachineScaleSetIPConfiguration( name: TestUtilities.GenerateName("vmsstestnetconfig"), subnet: new ApiEntityReference() { Id = vmssSubnet.Id }); VirtualMachineScaleSet vmScaleSet = CreateVMScaleSet_NoAsyncTracking( rgName: rgName, vmssName: vmssName, storageAccount: storageAccountOutput, imageRef: imageRef, inputVMScaleSet: out inputVMScaleSet, vmScaleSetCustomizer: (virtualMachineScaleSet) => { virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].Primary = true; virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations.Add(secondaryCA); }, createWithPublicIpAddress: false, subnet: vmssSubnet); var vmss = m_CrpClient.VirtualMachineScaleSets.Get(rgName, vmssName); Assert.Equal(2, vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations.Count); Assert.True(vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations.Count(ip => ip.Primary == true) == 1); passed = true; } finally { m_ResourcesClient.ResourceGroups.DeleteIfExists(rgName); } Assert.True(passed); } }
public void TestVMScaleSetWithnIpv6() { using (MockContext context = MockContext.Start(this.GetType())) { EnsureClientsInitialized(context); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); // Create resource group string rgName = TestUtilities.GenerateName(TestPrefix) + 1; var vmssName = TestUtilities.GenerateName("vmss"); var dnsname = TestUtilities.GenerateName("dnsname"); string storageAccountName = TestUtilities.GenerateName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; bool passed = false; try { var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); var vnetResponse = CreateVNETWithSubnets(rgName, 2); var vmssSubnet = vnetResponse.Subnets[1]; var ipv6ipconfig = new VirtualMachineScaleSetIPConfiguration(); ipv6ipconfig.Name = "ipv6"; ipv6ipconfig.PrivateIPAddressVersion = Microsoft.Azure.Management.Compute.Models.IPVersion.IPv6; VirtualMachineScaleSet vmScaleSet = CreateVMScaleSet_NoAsyncTracking( rgName: rgName, vmssName: vmssName, storageAccount: storageAccountOutput, imageRef: imageRef, inputVMScaleSet: out inputVMScaleSet, vmScaleSetCustomizer: (virtualMachineScaleSet) => { virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile .NetworkInterfaceConfigurations[0].IpConfigurations[0].PrivateIPAddressVersion = Microsoft.Azure.Management.Compute.Models.IPVersion.IPv4; virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile .NetworkInterfaceConfigurations[0].IpConfigurations.Add(ipv6ipconfig); }, createWithPublicIpAddress: false, subnet: vmssSubnet); var vmss = m_CrpClient.VirtualMachineScaleSets.Get(rgName, vmssName); Assert.Equal(2, vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations.Count); passed = true; } finally { m_ResourcesClient.ResourceGroups.DeleteIfExists(rgName); } Assert.True(passed); } }
public async Task TestVMSSWithMultiCA() { EnsureClientsInitialized(LocationWestCentralUs); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group string rgName = Recording.GenerateAssetName(TestPrefix) + 1; var vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; bool passed = false; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); var vnetResponse = await CreateVNETWithSubnets(rgName, 2); var vmssSubnet = vnetResponse.Subnets[1]; var secondaryCA = new VirtualMachineScaleSetIPConfiguration(Recording.GenerateAssetName("vmsstestnetconfig")) { Subnet = new ApiEntityReference() { Id = vmssSubnet.Id } }; var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking( rgName : rgName, vmssName : vmssName, storageAccount : storageAccountOutput, imageRef : imageRef, vmScaleSetCustomizer : (virtualMachineScaleSet) => { virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].Primary = true; virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations.Add(secondaryCA); }, createWithPublicIpAddress : false, subnet : vmssSubnet); VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1; inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2; var vmss = (await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName)).Value; Assert.AreEqual(2, vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations.Count); Assert.True(vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations.Count(ip => ip.Primary == true) == 1); passed = true; Assert.True(passed); }
public async Task TestVMScaleSetWithnIpv6() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group string rgName = Recording.GenerateAssetName(TestPrefix) + 1; var vmssName = Recording.GenerateAssetName("vmss"); var dnsname = Recording.GenerateAssetName("dnsname"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; bool passed = false; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); var vnetResponse = await CreateVNETWithSubnets(rgName, 2); var vmssSubnet = vnetResponse.Subnets[1]; var ipv6ipconfig = new VirtualMachineScaleSetIPConfiguration("ipv6"); ipv6ipconfig.Name = "ipv6"; ipv6ipconfig.PrivateIPAddressVersion = Azure.ResourceManager.Compute.Models.IPVersion.IPv6; var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking( rgName : rgName, vmssName : vmssName, storageAccount : storageAccountOutput, imageRef : imageRef, vmScaleSetCustomizer : (virtualMachineScaleSet) => { virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile .NetworkInterfaceConfigurations[0].IpConfigurations[0].PrivateIPAddressVersion = Azure.ResourceManager.Compute.Models.IPVersion.IPv4; virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile .NetworkInterfaceConfigurations[0].IpConfigurations.Add(ipv6ipconfig); }, createWithPublicIpAddress : false, subnet : vmssSubnet); VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1; inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2; var vmss = (await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName)).Value; Assert.AreEqual(2, vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations.Count); passed = true; Assert.True(passed); }
protected void CompareIpConfigApplicationGatewayPools(VirtualMachineScaleSetIPConfiguration ipconfig, VirtualMachineScaleSetIPConfiguration outipconfig) { if (ipconfig.ApplicationGatewayBackendAddressPools != null && ipconfig.ApplicationGatewayBackendAddressPools.Count > 0) { Assert.NotNull(outipconfig.ApplicationGatewayBackendAddressPools); Assert.AreEqual(ipconfig.ApplicationGatewayBackendAddressPools.Count, outipconfig.ApplicationGatewayBackendAddressPools.Count); foreach (var pool in ipconfig.ApplicationGatewayBackendAddressPools) { var outPool = outipconfig.ApplicationGatewayBackendAddressPools.First( p => string.Equals(p.Id, pool.Id, StringComparison.OrdinalIgnoreCase)); Assert.NotNull(outPool); } } else { Assert.True((outipconfig.ApplicationGatewayBackendAddressPools == null) || (outipconfig.ApplicationGatewayBackendAddressPools.Count == 0)); } }
protected VirtualMachineScaleSet CreateDefaultVMScaleSetInput( string rgName, string storageAccountName, ImageReference imageRef, string subnetId, bool hasManagedDisks = false, string healthProbeId = null, string loadBalancerBackendPoolId = null, IList <string> zones = null, int?osDiskSizeInGB = null, string machineSizeType = null, bool?enableUltraSSD = false, string diskEncryptionSetId = null, AutomaticRepairsPolicy automaticRepairsPolicy = null) { // Generate Container name to hold disk VHds string containerName = Recording.GenerateAssetName(TestPrefix); var vhdContainer = "https://" + storageAccountName + ".blob.core.windows.net/" + containerName; var vmssName = Recording.GenerateAssetName("vmss"); bool createOSDisk = !hasManagedDisks || osDiskSizeInGB != null; string vmSize = zones == null?VirtualMachineSizeTypes.StandardA0.ToString() : VirtualMachineSizeTypes.StandardA1V2.ToString(); var test1 = Recording.GenerateAssetName("vmsstestnetconfig"); var test2 = Recording.GenerateAssetName("vmsstestnetconfig"); var virtualMachineScaleSetIpConfiguration = new VirtualMachineScaleSetIPConfiguration(test2) { Subnet = new Azure.ResourceManager.Compute.Models.ApiEntityReference() { Id = subnetId } }; virtualMachineScaleSetIpConfiguration.ApplicationGatewayBackendAddressPools.Clear(); if (loadBalancerBackendPoolId != null) { virtualMachineScaleSetIpConfiguration.LoadBalancerBackendAddressPools.Add(new Models.SubResource(loadBalancerBackendPoolId)); } var virtualMachineScaleSetOsDisk = !createOSDisk ? null : new VirtualMachineScaleSetOSDisk(DiskCreateOptionTypes.FromImage) { Caching = CachingTypes.None, Name = hasManagedDisks ? null : "test", DiskSizeGB = osDiskSizeInGB, ManagedDisk = diskEncryptionSetId == null ? null : new VirtualMachineScaleSetManagedDiskParameters() { StorageAccountType = StorageAccountTypes.StandardLRS, DiskEncryptionSet = new DiskEncryptionSetParameters() { Id = diskEncryptionSetId } } }; if (!hasManagedDisks) { virtualMachineScaleSetOsDisk?.VhdContainers.Add(vhdContainer); } var virtualMachineScaleSetStorageProfile = new VirtualMachineScaleSetStorageProfile() { ImageReference = imageRef, OsDisk = virtualMachineScaleSetOsDisk }; if (hasManagedDisks) { virtualMachineScaleSetStorageProfile.DataDisks.Add(new VirtualMachineScaleSetDataDisk(1, DiskCreateOptionTypes.Empty) { DiskSizeGB = 128, ManagedDisk = diskEncryptionSetId == null ? null : new VirtualMachineScaleSetManagedDiskParameters() { StorageAccountType = StorageAccountTypes.StandardLRS, DiskEncryptionSet = new DiskEncryptionSetParameters() { Id = diskEncryptionSetId } } }); } var vmScaleSet = new VirtualMachineScaleSet(m_location) { Location = m_location, Tags = { { "RG", "rg" }, { "testTag", "1" } }, Sku = new CM.Sku() { Capacity = 2, Name = machineSizeType == null ? vmSize : machineSizeType }, Overprovision = false, UpgradePolicy = new UpgradePolicy() { Mode = UpgradeMode.Automatic }, VirtualMachineProfile = new VirtualMachineScaleSetVMProfile() { StorageProfile = virtualMachineScaleSetStorageProfile, OsProfile = new VirtualMachineScaleSetOSProfile() { ComputerNamePrefix = "test", AdminUsername = "******", AdminPassword = PLACEHOLDER, CustomData = Convert.ToBase64String(Encoding.UTF8.GetBytes("Custom data")) }, NetworkProfile = new VirtualMachineScaleSetNetworkProfile() { HealthProbe = healthProbeId == null ? null : new ApiEntityReference { Id = healthProbeId }, NetworkInterfaceConfigurations = { new VirtualMachineScaleSetNetworkConfiguration(test1) { Primary = true, IpConfigurations = { virtualMachineScaleSetIpConfiguration } } } }, ExtensionProfile = new VirtualMachineScaleSetExtensionProfile(), }, AutomaticRepairsPolicy = automaticRepairsPolicy }; vmScaleSet.Zones.InitializeFrom(zones); if (enableUltraSSD == true) { vmScaleSet.AdditionalCapabilities = new AdditionalCapabilities { UltraSSDEnabled = true }; VirtualMachineScaleSetOSDisk osDisk = vmScaleSet.VirtualMachineProfile.StorageProfile.OsDisk; osDisk.ManagedDisk = osDisk.ManagedDisk ?? new VirtualMachineScaleSetManagedDiskParameters(); osDisk.ManagedDisk.StorageAccountType = StorageAccountTypes.PremiumLRS; foreach (VirtualMachineScaleSetDataDisk dataDisk in vmScaleSet.VirtualMachineProfile.StorageProfile.DataDisks) { dataDisk.ManagedDisk = dataDisk.ManagedDisk ?? new VirtualMachineScaleSetManagedDiskParameters(); dataDisk.ManagedDisk.StorageAccountType = StorageAccountTypes.UltraSSDLRS; } } return(vmScaleSet); }
public async Async.Task <OneFuzzResultVoid> CreateVmss( string location, Guid name, string vmSku, long vmCount, string image, string networkId, bool?spotInstance, bool ephemeralOsDisks, IList <VirtualMachineScaleSetExtensionData>?extensions, string password, string sshPublicKey, IDictionary <string, string> tags) { var vmss = await GetVmss(name); if (vmss is not null) { return(OneFuzzResultVoid.Ok); } _log.Info($"creating VM name: {name}, vm_sku: {vmSku}, vm_count: {vmCount}, image: {image}, subnet: {networkId}, spot_instance: {spotInstance}"); var getOsResult = await _imageOps.GetOs(location, image); if (!getOsResult.IsOk) { return(getOsResult.ErrorV); } var vmssData = new VirtualMachineScaleSetData(location) { DoNotRunExtensionsOnOverprovisionedVms = false, Sku = new ComputeSku() { Name = vmSku }, Overprovision = false, SinglePlacementGroup = false, UpgradePolicy = new UpgradePolicy() { Mode = UpgradeMode.Manual }, Identity = new ManagedServiceIdentity(managedServiceIdentityType: ManagedServiceIdentityType.UserAssigned), }; vmssData.Identity.UserAssignedIdentities.Add(_creds.GetScalesetIdentityResourcePath(), new UserAssignedIdentity()); vmssData.VirtualMachineProfile = new VirtualMachineScaleSetVmProfile() { Priority = VirtualMachinePriorityTypes.Regular }; var imageRef = new ImageReference(); if (image.StartsWith('/')) { imageRef.Id = image; } else { var info = IImageOperations.GetImageInfo(image); imageRef.Publisher = info.Publisher; imageRef.Offer = info.Offer; imageRef.Sku = info.Sku; imageRef.Version = info.Version; } vmssData.VirtualMachineProfile.StorageProfile = new VirtualMachineScaleSetStorageProfile() { ImageReference = imageRef }; vmssData.VirtualMachineProfile.OSProfile = new VirtualMachineScaleSetOSProfile() { ComputerNamePrefix = "node", AdminUsername = "******" }; var networkConfiguration = new VirtualMachineScaleSetNetworkConfiguration("onefuzz-nic") { Primary = true }; var ipConfig = new VirtualMachineScaleSetIPConfiguration("onefuzz-ip-config"); ipConfig.SubnetId = new ResourceIdentifier(networkId); networkConfiguration.IPConfigurations.Add(ipConfig); vmssData.VirtualMachineProfile.NetworkProfile = new VirtualMachineScaleSetNetworkProfile(); vmssData.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.Add(networkConfiguration); if (extensions is not null) { vmssData.VirtualMachineProfile.ExtensionProfile = new VirtualMachineScaleSetExtensionProfile(); foreach (var e in extensions) { vmssData.VirtualMachineProfile.ExtensionProfile.Extensions.Add(e); } } switch (getOsResult.OkV) { case Os.Windows: vmssData.VirtualMachineProfile.OSProfile.AdminPassword = password; break; case Os.Linux: vmssData.VirtualMachineProfile.OSProfile.LinuxConfiguration = new LinuxConfiguration(); vmssData.VirtualMachineProfile.OSProfile.LinuxConfiguration.DisablePasswordAuthentication = true; var i = new SshPublicKeyInfo() { KeyData = sshPublicKey, Path = "/home/onefuzz/.ssh/authorized_keys" }; vmssData.VirtualMachineProfile.OSProfile.LinuxConfiguration.SshPublicKeys.Add(i); break; default: return(OneFuzzResultVoid.Error(ErrorCode.INVALID_CONFIGURATION, $"unhandled OS: {getOsResult.OkV} in image: {image}")); } if (ephemeralOsDisks) { vmssData.VirtualMachineProfile.StorageProfile.OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionTypes.FromImage); vmssData.VirtualMachineProfile.StorageProfile.OSDisk.DiffDiskSettings = new DiffDiskSettings(); vmssData.VirtualMachineProfile.StorageProfile.OSDisk.DiffDiskSettings.Option = DiffDiskOptions.Local; vmssData.VirtualMachineProfile.StorageProfile.OSDisk.Caching = CachingTypes.ReadOnly; } if (spotInstance.HasValue && spotInstance.Value) { // Setting max price to -1 means it won't be evicted because of // price. // // https://docs.microsoft.com/en-us/azure/ // virtual-machine-scale-sets/use-spot#resource-manager-templates vmssData.VirtualMachineProfile.EvictionPolicy = VirtualMachineEvictionPolicyTypes.Deallocate; vmssData.VirtualMachineProfile.Priority = VirtualMachinePriorityTypes.Spot; vmssData.VirtualMachineProfile.BillingMaxPrice = 1.0; } foreach (var tag in tags) { vmssData.Tags.Add(tag); } if (_serviceConfig.OneFuzzOwner is not null) { vmssData.Tags.Add("OWNER", _serviceConfig.OneFuzzOwner); } try { var rg = _creds.GetResourceGroupResource(); var createUpdate = await rg.GetVirtualMachineScaleSets().CreateOrUpdateAsync(WaitUntil.Started, name.ToString(), vmssData); if (createUpdate.GetRawResponse().IsError) { var msg = $"Failed to create new scaleset due to {createUpdate.GetRawResponse().ReasonPhrase}"; _log.Error(msg); return(OneFuzzResultVoid.Error(ErrorCode.VM_CREATE_FAILED, new[] { msg })); } else { return(OneFuzzResultVoid.Ok); } } catch (Exception ex) { _log.Exception(ex); return(OneFuzzResultVoid.Error(ErrorCode.VM_CREATE_FAILED, new[] { ex.Message })); } }
private void Run() { var vIpConfigurations = new VirtualMachineScaleSetIPConfiguration(); vIpConfigurations.Name = this.IsParameterBound(c => c.Name) ? this.Name : null; vIpConfigurations.Primary = this.Primary.IsPresent; vIpConfigurations.PrivateIPAddressVersion = this.IsParameterBound(c => c.PrivateIPAddressVersion) ? this.PrivateIPAddressVersion : null; vIpConfigurations.Id = this.IsParameterBound(c => c.Id) ? this.Id : null; // SubnetId if (this.IsParameterBound(c => c.SubnetId)) { if (vIpConfigurations.Subnet == null) { vIpConfigurations.Subnet = new ApiEntityReference(); } vIpConfigurations.Subnet.Id = this.SubnetId; } // PublicIPAddressConfigurationName if (this.IsParameterBound(c => c.PublicIPAddressConfigurationName)) { if (vIpConfigurations.PublicIPAddressConfiguration == null) { vIpConfigurations.PublicIPAddressConfiguration = new VirtualMachineScaleSetPublicIPAddressConfiguration(); } vIpConfigurations.PublicIPAddressConfiguration.Name = this.PublicIPAddressConfigurationName; } // PublicIPAddressConfigurationIdleTimeoutInMinutes if (this.IsParameterBound(c => c.PublicIPAddressConfigurationIdleTimeoutInMinutes)) { if (vIpConfigurations.PublicIPAddressConfiguration == null) { vIpConfigurations.PublicIPAddressConfiguration = new VirtualMachineScaleSetPublicIPAddressConfiguration(); } vIpConfigurations.PublicIPAddressConfiguration.IdleTimeoutInMinutes = this.PublicIPAddressConfigurationIdleTimeoutInMinutes; } // DnsSetting if (this.IsParameterBound(c => c.DnsSetting)) { if (vIpConfigurations.PublicIPAddressConfiguration == null) { vIpConfigurations.PublicIPAddressConfiguration = new VirtualMachineScaleSetPublicIPAddressConfiguration(); } if (vIpConfigurations.PublicIPAddressConfiguration.DnsSettings == null) { vIpConfigurations.PublicIPAddressConfiguration.DnsSettings = new VirtualMachineScaleSetPublicIPAddressConfigurationDnsSettings(); } vIpConfigurations.PublicIPAddressConfiguration.DnsSettings.DomainNameLabel = this.DnsSetting; } // IpTag if (this.IpTag != null) { if (vIpConfigurations.PublicIPAddressConfiguration == null) { vIpConfigurations.PublicIPAddressConfiguration = new VirtualMachineScaleSetPublicIPAddressConfiguration(); } if (vIpConfigurations.PublicIPAddressConfiguration.IpTags == null) { vIpConfigurations.PublicIPAddressConfiguration.IpTags = new List <VirtualMachineScaleSetIpTag>(); } foreach (var element in this.IpTag) { vIpConfigurations.PublicIPAddressConfiguration.IpTags.Add(element); } } // PublicIPPrefix if (this.IsParameterBound(c => c.PublicIPPrefix)) { if (vIpConfigurations.PublicIPAddressConfiguration == null) { vIpConfigurations.PublicIPAddressConfiguration = new VirtualMachineScaleSetPublicIPAddressConfiguration(); } if (vIpConfigurations.PublicIPAddressConfiguration.PublicIPPrefix == null) { vIpConfigurations.PublicIPAddressConfiguration.PublicIPPrefix = new SubResource(); } vIpConfigurations.PublicIPAddressConfiguration.PublicIPPrefix.Id = this.PublicIPPrefix; } // ApplicationGatewayBackendAddressPoolsId if (this.ApplicationGatewayBackendAddressPoolsId != null) { if (vIpConfigurations.ApplicationGatewayBackendAddressPools == null) { vIpConfigurations.ApplicationGatewayBackendAddressPools = new List <SubResource>(); } foreach (var element in this.ApplicationGatewayBackendAddressPoolsId) { var vApplicationGatewayBackendAddressPools = new SubResource(); vApplicationGatewayBackendAddressPools.Id = element; vIpConfigurations.ApplicationGatewayBackendAddressPools.Add(vApplicationGatewayBackendAddressPools); } } // LoadBalancerBackendAddressPoolsId if (this.LoadBalancerBackendAddressPoolsId != null) { if (vIpConfigurations.LoadBalancerBackendAddressPools == null) { vIpConfigurations.LoadBalancerBackendAddressPools = new List <SubResource>(); } foreach (var element in this.LoadBalancerBackendAddressPoolsId) { var vLoadBalancerBackendAddressPools = new SubResource(); vLoadBalancerBackendAddressPools.Id = element; vIpConfigurations.LoadBalancerBackendAddressPools.Add(vLoadBalancerBackendAddressPools); } } // LoadBalancerInboundNatPoolsId if (this.LoadBalancerInboundNatPoolsId != null) { if (vIpConfigurations.LoadBalancerInboundNatPools == null) { vIpConfigurations.LoadBalancerInboundNatPools = new List <SubResource>(); } foreach (var element in this.LoadBalancerInboundNatPoolsId) { var vLoadBalancerInboundNatPools = new SubResource(); vLoadBalancerInboundNatPools.Id = element; vIpConfigurations.LoadBalancerInboundNatPools.Add(vLoadBalancerInboundNatPools); } } WriteObject(vIpConfigurations); }
internal static ResourceConfig <VirtualMachineScaleSet> CreateVirtualMachineScaleSetConfig( this ResourceConfig <ResourceGroup> resourceGroup, string name, NestedResourceConfig <Subnet, VirtualNetwork> subnet, IEnumerable <NestedResourceConfig <FrontendIPConfiguration, LoadBalancer> > frontendIpConfigurations, NestedResourceConfig <BackendAddressPool, LoadBalancer> backendAdressPool, bool isWindows, string adminUsername, string adminPassword, Image image, string vmSize, int instanceCount, UpgradeMode?upgradeMode) => Strategy.CreateResourceConfig( resourceGroup: resourceGroup, name: name, createModel: subscriptionId => { var vmss = new VirtualMachineScaleSet() { Zones = frontendIpConfigurations ?.Select(f => f.CreateModel(subscriptionId)) ?.Where(z => z?.Zones != null) .SelectMany(z => z.Zones) .Where(z => z != null) .ToList(), UpgradePolicy = upgradeMode.HasValue ? new UpgradePolicy { Mode = upgradeMode } : new UpgradePolicy { Mode = UpgradeMode.Manual }, Sku = new Microsoft.Azure.Management.Compute.Models.Sku() { Capacity = instanceCount, Name = vmSize, }, VirtualMachineProfile = new VirtualMachineScaleSetVMProfile() }; vmss.VirtualMachineProfile.OsProfile = new VirtualMachineScaleSetOSProfile { ComputerNamePrefix = name.Substring(0, Math.Min(name.Length, 9)), WindowsConfiguration = isWindows ? new WindowsConfiguration { } : null, LinuxConfiguration = isWindows ? null : new LinuxConfiguration(), AdminUsername = adminUsername, AdminPassword = adminPassword, }; vmss.VirtualMachineProfile.StorageProfile = new VirtualMachineScaleSetStorageProfile { ImageReference = new ImageReference { Publisher = image.publisher, Offer = image.offer, Sku = image.sku, Version = image.version } }; var ipConfig = new VirtualMachineScaleSetIPConfiguration { Name = name, LoadBalancerBackendAddressPools = new List <Microsoft.Azure.Management.Compute.Models.SubResource>( new[] { new Microsoft.Azure.Management.Compute.Models.SubResource( id: backendAdressPool.GetId(subscriptionId).IdToString()) }), Subnet = new ApiEntityReference { Id = subnet.GetId(subscriptionId).IdToString() } }; vmss.VirtualMachineProfile.NetworkProfile = new VirtualMachineScaleSetNetworkProfile { NetworkInterfaceConfigurations = new[] { new VirtualMachineScaleSetNetworkConfiguration { Name = name, IpConfigurations = new List <VirtualMachineScaleSetIPConfiguration>( new [] { ipConfig }), Primary = true } } }; return(vmss); }, dependencies: new IEntityConfig[] { subnet, backendAdressPool } .Concat(frontendIpConfigurations));