public static ResourceConfig <VirtualMachine> CreateVirtualMachineConfig(
            this ResourceConfig <ResourceGroup> resourceGroup,
            string name,
            ResourceConfig <NetworkInterface> networkInterface,
            ImageAndOsType imageAndOsType,
            string adminUsername,
            string adminPassword,
            string size,
            ResourceConfig <AvailabilitySet> availabilitySet,
            VirtualMachineIdentity identity,
            IEnumerable <int> dataDisks,
            IList <string> zones,
            bool ultraSSDEnabled,
            Func <IEngine, SubResource> proximityPlacementGroup,
            string hostId,
            string priority,
            string evictionPolicy,
            double?maxPrice)

        => Strategy.CreateResourceConfig(
            resourceGroup: resourceGroup,
            name: name,
            createModel: engine => new VirtualMachine
        {
            OsProfile = new OSProfile
            {
                ComputerName         = name,
                WindowsConfiguration = imageAndOsType.CreateWindowsConfiguration(),
                LinuxConfiguration   = imageAndOsType.CreateLinuxConfiguration(),
                AdminUsername        = adminUsername,
                AdminPassword        = adminPassword,
            },
            Identity       = identity,
            NetworkProfile = new NetworkProfile
            {
                NetworkInterfaces = new[]
                {
                    engine.GetReference(networkInterface)
                }
            },
            HardwareProfile = new HardwareProfile
            {
                VmSize = size
            },
            StorageProfile = new StorageProfile
            {
                ImageReference = imageAndOsType?.Image,
                DataDisks      = DataDiskStrategy.CreateDataDisks(
                    imageAndOsType?.DataDiskLuns, dataDisks)
            },
            AvailabilitySet         = engine.GetReference(availabilitySet),
            Zones                   = zones,
            AdditionalCapabilities  = ultraSSDEnabled ? new AdditionalCapabilities(true) : null,
            ProximityPlacementGroup = proximityPlacementGroup(engine),
            Host           = string.IsNullOrEmpty(hostId) ? null : new SubResource(hostId),
            Priority       = priority,
            EvictionPolicy = evictionPolicy,
            BillingProfile = (maxPrice == null) ? null : new BillingProfile(maxPrice)
        });
Example #2
0
 public static ResourceConfig <VirtualMachine> CreateVirtualMachineConfig(
     this ResourceConfig <ResourceGroup> resourceGroup,
     string name,
     ResourceConfig <NetworkInterface> networkInterface,
     ImageAndOsType imageAndOsType,
     string adminUsername,
     string adminPassword,
     string size,
     ResourceConfig <AvailabilitySet> availabilitySet,
     VirtualMachineIdentity identity,
     IEnumerable <int> dataDisks,
     IList <string> zones,
     bool ultraSSDEnabled)
 => Strategy.CreateResourceConfig(
     resourceGroup: resourceGroup,
     name: name,
     createModel: engine => new VirtualMachine
 {
     OsProfile = new OSProfile
     {
         ComputerName         = name,
         WindowsConfiguration = imageAndOsType.CreateWindowsConfiguration(),
         LinuxConfiguration   = imageAndOsType.CreateLinuxConfiguration(),
         AdminUsername        = adminUsername,
         AdminPassword        = adminPassword,
     },
     Identity       = identity,
     NetworkProfile = new NetworkProfile
     {
         NetworkInterfaces = new[]
         {
             engine.GetReference(networkInterface)
         }
     },
     HardwareProfile = new HardwareProfile
     {
         VmSize = size
     },
     StorageProfile = new StorageProfile
     {
         ImageReference = imageAndOsType?.Image,
         DataDisks      = DataDiskStrategy.CreateDataDisks(
             imageAndOsType?.DataDiskLuns, dataDisks)
     },
     AvailabilitySet        = engine.GetReference(availabilitySet),
     Zones                  = zones,
     AdditionalCapabilities = ultraSSDEnabled ? new AdditionalCapabilities(true) : null
 });
 internal static ResourceConfig <VirtualMachineScaleSet> CreateVirtualMachineScaleSetConfig(
     this ResourceConfig <ResourceGroup> resourceGroup,
     string name,
     NestedResourceConfig <Subnet, VirtualNetwork> subnet,
     NestedResourceConfig <BackendAddressPool, LoadBalancer> backendAdressPool,
     IEnumerable <NestedResourceConfig <InboundNatPool, LoadBalancer> > inboundNatPools,
     ResourceConfig <NetworkSecurityGroup> networkSecurityGroup,
     ImageAndOsType imageAndOsType,
     string adminUsername,
     string adminPassword,
     string vmSize,
     int instanceCount,
     VirtualMachineScaleSetIdentity identity,
     bool singlePlacementGroup,
     UpgradeMode?upgradeMode,
     IEnumerable <int> dataDisks,
     IList <string> zones,
     bool ultraSSDEnabled,
     Func <IEngine, SubResource> proximityPlacementGroup,
     string priority,
     string evictionPolicy,
     double?maxPrice,
     string[] scaleInPolicy,
     bool doNotRunExtensionsOnOverprovisionedVMs)
 => Strategy.CreateResourceConfig(
     resourceGroup: resourceGroup,
     name: name,
     createModel: engine => new VirtualMachineScaleSet()
 {
     Zones         = zones,
     UpgradePolicy = new UpgradePolicy
     {
         Mode = upgradeMode ?? UpgradeMode.Manual
     },
     Sku = new Azure.Management.Compute.Models.Sku()
     {
         Capacity = instanceCount,
         Name     = vmSize,
     },
     Identity               = identity,
     SinglePlacementGroup   = singlePlacementGroup,
     AdditionalCapabilities = ultraSSDEnabled ? new AdditionalCapabilities(true) : null,
     VirtualMachineProfile  = new VirtualMachineScaleSetVMProfile
     {
         OsProfile = new VirtualMachineScaleSetOSProfile
         {
             ComputerNamePrefix   = name.Substring(0, Math.Min(name.Length, 9)),
             WindowsConfiguration = imageAndOsType.CreateWindowsConfiguration(),
             LinuxConfiguration   = imageAndOsType.CreateLinuxConfiguration(),
             AdminUsername        = adminUsername,
             AdminPassword        = adminPassword,
         },
         StorageProfile = new VirtualMachineScaleSetStorageProfile
         {
             ImageReference = imageAndOsType?.Image,
             DataDisks      = DataDiskStrategy.CreateVmssDataDisks(
                 imageAndOsType?.DataDiskLuns, dataDisks)
         },
         NetworkProfile = new VirtualMachineScaleSetNetworkProfile
         {
             NetworkInterfaceConfigurations = new[]
             {
                 new VirtualMachineScaleSetNetworkConfiguration
                 {
                     Name             = name,
                     IpConfigurations = new []
                     {
                         new VirtualMachineScaleSetIPConfiguration
                         {
                             Name = name,
                             LoadBalancerBackendAddressPools = new []
                             {
                                 engine.GetReference(backendAdressPool)
                             },
                             Subnet = engine.GetReference(subnet),
                             LoadBalancerInboundNatPools = inboundNatPools
                                                           ?.Select(engine.GetReference)
                                                           .ToList()
                         }
                     },
                     Primary = true,
                     NetworkSecurityGroup = engine.GetReference(networkSecurityGroup)
                 }
             }
         },
         Priority       = priority,
         EvictionPolicy = evictionPolicy,
         BillingProfile = (maxPrice == null) ? null : new BillingProfile(maxPrice)
     },
     ProximityPlacementGroup = proximityPlacementGroup(engine),
     ScaleInPolicy           = (scaleInPolicy == null) ? null : new ScaleInPolicy
     {
         Rules = scaleInPolicy
     },
     DoNotRunExtensionsOnOverprovisionedVMs = doNotRunExtensionsOnOverprovisionedVMs ? true : (bool?)null
 });
 internal static ResourceConfig <VirtualMachineScaleSet> CreateVirtualMachineScaleSetConfigOrchestrationModeFlexible(
     this ResourceConfig <ResourceGroup> resourceGroup,
     string name,
     NestedResourceConfig <Subnet, VirtualNetwork> subnet,
     NestedResourceConfig <BackendAddressPool, LoadBalancer> backendAdressPool,
     ResourceConfig <NetworkSecurityGroup> networkSecurityGroup,
     ImageAndOsType imageAndOsType,
     string adminUsername,
     string adminPassword,
     string vmSize,
     int instanceCount,
     VirtualMachineScaleSetIdentity identity,
     bool singlePlacementGroup,
     IEnumerable <int> dataDisks,
     IList <string> zones,
     bool ultraSSDEnabled,
     Func <IEngine, CM.SubResource> proximityPlacementGroup,
     Func <IEngine, CM.SubResource> hostGroup,
     string priority,
     string evictionPolicy,
     double?maxPrice,
     string[] scaleInPolicy,
     bool doNotRunExtensionsOnOverprovisionedVMs,
     bool encryptionAtHost,
     int?platformFaultDomainCount,
     string edgeZone,
     string orchestrationMode,
     string capacityReservationId
     )
 => Strategy.CreateResourceConfig(
     resourceGroup: resourceGroup,
     name: name,
     createModel: engine => new VirtualMachineScaleSet()
 {
     Zones            = zones,
     ExtendedLocation = edgeZone == null ? null : new CM.ExtendedLocation(edgeZone, CM.ExtendedLocationTypes.EdgeZone),
     Sku = new Azure.Management.Compute.Models.Sku()
     {
         Capacity = instanceCount,
         Name     = vmSize,
     },
     Identity                 = identity,
     SinglePlacementGroup     = singlePlacementGroup,
     AdditionalCapabilities   = ultraSSDEnabled ? new AdditionalCapabilities(true) : null,
     PlatformFaultDomainCount = platformFaultDomainCount,
     VirtualMachineProfile    = new VirtualMachineScaleSetVMProfile
     {
         SecurityProfile = (encryptionAtHost == true) ? new SecurityProfile(encryptionAtHost: encryptionAtHost) : null,
         OsProfile       = new VirtualMachineScaleSetOSProfile
         {
             ComputerNamePrefix   = name.Substring(0, Math.Min(name.Length, 9)),
             WindowsConfiguration = imageAndOsType.CreateWindowsConfiguration(),
             LinuxConfiguration   = imageAndOsType.CreateLinuxConfiguration(),
             AdminUsername        = adminUsername,
             AdminPassword        = adminPassword,
         },
         StorageProfile = new VirtualMachineScaleSetStorageProfile
         {
             ImageReference = imageAndOsType?.Image,
             DataDisks      = DataDiskStrategy.CreateVmssDataDisks(
                 imageAndOsType?.DataDiskLuns, dataDisks)
         },
         NetworkProfile = new VirtualMachineScaleSetNetworkProfile
         {
             NetworkApiVersion = flexibleOModeNetworkAPIVersion,
             NetworkInterfaceConfigurations = new[]
             {
                 new VirtualMachineScaleSetNetworkConfiguration
                 {
                     Name             = name,
                     IpConfigurations = new []
                     {
                         new VirtualMachineScaleSetIPConfiguration
                         {
                             Name = name,
                             LoadBalancerBackendAddressPools = new []
                             {
                                 engine.GetReference(backendAdressPool)
                             },
                             Subnet = engine.GetReference(subnet)
                         }
                     },
                     Primary = true,
                     NetworkSecurityGroup = engine.GetReference(networkSecurityGroup)
                 }
             }
         },
         Priority            = priority,
         EvictionPolicy      = evictionPolicy,
         BillingProfile      = (maxPrice == null) ? null : new BillingProfile(maxPrice),
         CapacityReservation = (capacityReservationId == null) ? null : new CapacityReservationProfile
         {
             CapacityReservationGroup = new Microsoft.Azure.Management.Compute.Models.SubResource(capacityReservationId)
         }
     },
     ProximityPlacementGroup = proximityPlacementGroup(engine),
     HostGroup     = hostGroup(engine),
     ScaleInPolicy = (scaleInPolicy == null) ? null : new ScaleInPolicy
     {
         Rules = scaleInPolicy
     },
     DoNotRunExtensionsOnOverprovisionedVMs = doNotRunExtensionsOnOverprovisionedVMs ? true : (bool?)null,
     OrchestrationMode = orchestrationMode
 });
 internal static ResourceConfig <VirtualMachineScaleSet> CreateVirtualMachineScaleSetConfig(
     this ResourceConfig <ResourceGroup> resourceGroup,
     string name,
     NestedResourceConfig <Subnet, VirtualNetwork> subnet,
     NestedResourceConfig <BackendAddressPool, LoadBalancer> backendAdressPool,
     IEnumerable <NestedResourceConfig <InboundNatPool, LoadBalancer> > inboundNatPools,
     ResourceConfig <NetworkSecurityGroup> networkSecurityGroup,
     ImageAndOsType imageAndOsType,
     string adminUsername,
     string adminPassword,
     string vmSize,
     int instanceCount,
     VirtualMachineScaleSetIdentity identity,
     Boolean singlePlacementGroup,
     UpgradeMode?upgradeMode,
     IEnumerable <int> dataDisks,
     IList <string> zones)
 => Strategy.CreateResourceConfig(
     resourceGroup: resourceGroup,
     name: name,
     createModel: engine => new VirtualMachineScaleSet()
 {
     Zones         = zones,
     UpgradePolicy = new UpgradePolicy
     {
         Mode = upgradeMode ?? UpgradeMode.Manual
     },
     Sku = new Azure.Management.Compute.Models.Sku()
     {
         Capacity = instanceCount,
         Name     = vmSize,
     },
     Identity              = identity,
     SinglePlacementGroup  = singlePlacementGroup,
     VirtualMachineProfile = new VirtualMachineScaleSetVMProfile
     {
         OsProfile = new VirtualMachineScaleSetOSProfile
         {
             ComputerNamePrefix   = name.Substring(0, Math.Min(name.Length, 9)),
             WindowsConfiguration = imageAndOsType.CreateWindowsConfiguration(),
             LinuxConfiguration   = imageAndOsType.CreateLinuxConfiguration(),
             AdminUsername        = adminUsername,
             AdminPassword        = adminPassword,
         },
         StorageProfile = new VirtualMachineScaleSetStorageProfile
         {
             ImageReference = imageAndOsType?.Image,
             DataDisks      = DataDiskStrategy.CreateVmssDataDisks(
                 imageAndOsType?.DataDiskLuns, dataDisks)
         },
         NetworkProfile = new VirtualMachineScaleSetNetworkProfile
         {
             NetworkInterfaceConfigurations = new[]
             {
                 new VirtualMachineScaleSetNetworkConfiguration
                 {
                     Name             = name,
                     IpConfigurations = new []
                     {
                         new VirtualMachineScaleSetIPConfiguration
                         {
                             Name = name,
                             LoadBalancerBackendAddressPools = new []
                             {
                                 engine.GetReference(backendAdressPool)
                             },
                             Subnet = engine.GetReference(subnet),
                             LoadBalancerInboundNatPools = inboundNatPools
                                                           ?.Select(engine.GetReference)
                                                           .ToList()
                         }
                     },
                     Primary = true,
                     NetworkSecurityGroup = engine.GetReference(networkSecurityGroup)
                 }
             }
         }
     }
 });