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, 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,
     string userData
     )
 => Strategy.CreateResourceConfig(
     resourceGroup: resourceGroup,
     name: name,
     createModel: engine => new VirtualMachineScaleSet()
 {
     Zones            = zones,
     ExtendedLocation = edgeZone == null ? null : new CM.ExtendedLocation(edgeZone, CM.ExtendedLocationTypes.EdgeZone),
     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,
     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
         {
             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),
         CapacityReservation = (capacityReservationId == null) ? null : new CapacityReservationProfile
         {
             CapacityReservationGroup = new Microsoft.Azure.Management.Compute.Models.SubResource(capacityReservationId)
         },
         UserData = userData
     },
     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,
     bool singlePlacementGroup,
     UpgradeMode?upgradeMode,
     IEnumerable <int> dataDisks,
     IList <string> zones,
     bool ultraSSDEnabled,
     Func <IEngine, SubResource> proximityPlacementGroup,
     string priority,
     string evictionPolicy,
     double?maxPrice)
 => 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),
 });
 public static LinuxConfiguration CreateLinuxConfiguration(this ImageAndOsType imageAndOsType)
 => imageAndOsType?.OsType == OperatingSystemTypes.Linux
         ? new LinuxConfiguration()
         : null;
Ejemplo n.º 4
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,
            Func <IEngine, SubResource> proximityPlacementGroup,
            string hostId,
            string hostGroupId,
            string VmssId,
            string priority,
            string evictionPolicy,
            double?maxPrice,
            bool encryptionAtHostPresent,
            string networkInterfaceDeleteOption = null,
            string osDiskDeleteOption           = null,
            string dataDiskDeleteOption         = null)

        => 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 Azure.Management.Compute.Models.NetworkProfile
            {
                NetworkInterfaces = new[]
                {
                    engine.GetReference(networkInterface, networkInterfaceDeleteOption)
                }
            },
            HardwareProfile = new HardwareProfile
            {
                VmSize = size
            },
            StorageProfile = new StorageProfile
            {
                ImageReference = imageAndOsType?.Image,
                DataDisks      = DataDiskStrategy.CreateDataDisks(
                    imageAndOsType?.DataDiskLuns, dataDisks, dataDiskDeleteOption)
            },
            AvailabilitySet         = engine.GetReference(availabilitySet),
            Zones                   = zones,
            AdditionalCapabilities  = ultraSSDEnabled ? new AdditionalCapabilities(true) : null,
            ProximityPlacementGroup = proximityPlacementGroup(engine),
            Host = string.IsNullOrEmpty(hostId) ? null : new SubResource(hostId),
            VirtualMachineScaleSet = string.IsNullOrEmpty(VmssId) ? null : new SubResource(VmssId),
            HostGroup       = string.IsNullOrEmpty(hostGroupId) ? null : new SubResource(hostGroupId),
            Priority        = priority,
            EvictionPolicy  = evictionPolicy,
            BillingProfile  = (maxPrice == null) ? null : new BillingProfile(maxPrice),
            SecurityProfile = (encryptionAtHostPresent == true) ? new SecurityProfile(encryptionAtHost: encryptionAtHostPresent) : null
        });
Ejemplo n.º 5
0
        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,
            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,
            },
            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)
                        }
                    }
                }
            }
        });
Ejemplo n.º 6
0
        public static async Task <ImageAndOsType> UpdateImageAndOsTypeAsync(
            this IClient client,
            ImageAndOsType imageAndOsType,
            string resourceGroupName,
            string imageName,
            string location)
        {
            if (imageAndOsType != null)
            {
                return(imageAndOsType);
            }

            var compute = client.GetClient <ComputeManagementClient>();

            if (imageName.Contains(':'))
            {
                if (location == null)
                {
                    return(null);
                }

                var imageArray = imageName.Split(':');
                if (imageArray.Length != 4)
                {
                    throw new InvalidOperationException(
                              string.Format(Resources.InvalidImageName, imageName));
                }
                var image = new ImageReference
                {
                    Publisher = imageArray[0],
                    Offer     = imageArray[1],
                    Sku       = imageArray[2],
                    Version   = imageArray[3],
                };

                if (image.Version.ToLower() == "latest")
                {
                    var images = await compute.VirtualMachineImages.ListAsync(
                        location, image.Publisher, image.Offer, image.Sku);

                    // According to Compute API:
                    // "The allowed formats are Major.Minor.Build or 'latest'.
                    //  Major, Minor, and Build are decimal numbers."
                    image.Version = images
                                    .Select(i => ImageVersion.Parse(i.Name))
                                    .Aggregate((a, b) => a.CompareTo(b) < 0 ? b : a)
                                    .ToString();
                }
                var imageModel = await compute.VirtualMachineImages.GetAsync(
                    location, image.Publisher, image.Offer, image.Sku, image.Version);

                return(new ImageAndOsType(
                           imageModel.OsDiskImage.OperatingSystem,
                           image,
                           imageModel.DataDiskImages.GetLuns()));
            }
            else if (imageName.Contains("/"))
            {
                var resourceId = ResourceId.TryParse(imageName);
                if (resourceId == null ||
                    resourceId.ResourceType.Namespace != ComputeStrategy.Namespace ||
                    (resourceId.ResourceType.Provider != "images") &&
                    resourceId.ResourceType.Provider != "galleries")
                {
                    throw new ArgumentException(string.Format(Resources.ComputeInvalidImageName, imageName));
                }

                if (compute.SubscriptionId != resourceId.SubscriptionId)
                {
                    throw new ArgumentException(Resources.ComputeMismatchSubscription);
                }

                if (resourceId.ResourceType.Provider == "galleries")
                {
                    return(await compute.GetGalleryImageAndOsTypeAsync(resourceId.ResourceGroupName, imageName));
                }
                else
                {
                    return(await compute.GetImageAndOsTypeAsync(resourceId.ResourceGroupName, resourceId.Name));
                }
            }
            else
            {
                try
                {
                    return(await compute.GetImageAndOsTypeAsync(resourceGroupName, imageName));
                }
                catch
                {
                }

                // get generic image
                var result = Images
                             .Instance
                             .SelectMany(osAndMap => osAndMap
                                         .Value
                                         .Where(nameAndImage => nameAndImage.Key.ToLower() == imageName.ToLower())
                                         .Select(nameAndImage => new ImageAndOsType(
                                                     osAndMap.Key == "Windows"
                                ? OperatingSystemTypes.Windows
                                : OperatingSystemTypes.Linux,
                                                     nameAndImage.Value,
                                                     null)))
                             .FirstOrDefault();

                if (result == null)
                {
                    throw new ArgumentException(string.Format(Resources.ComputeNoImageFound, imageName));
                }

                return(result);
            }
        }
Ejemplo n.º 7
0
 public static int[] UpdatePorts(this ImageAndOsType imageAndOsType, int[] ports)
 => ports ?? imageAndOsType?.OsType.CreatePorts();
 public static WindowsConfiguration CreateWindowsConfiguration(
     this ImageAndOsType imageAndOsType)
     => imageAndOsType?.OsType == OperatingSystemTypes.Windows
         ? new WindowsConfiguration()
         : null;
Ejemplo n.º 9
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,
            Func <IEngine, SubResource> proximityPlacementGroup,
            string hostId,
            string hostGroupId,
            string capacityReservationGroupId,
            string VmssId,
            string priority,
            string evictionPolicy,
            double?maxPrice,
            bool encryptionAtHostPresent,
            List <SshPublicKey> sshPublicKeys,
            int?platformFaultDomain             = null,
            string networkInterfaceDeleteOption = null,
            string osDiskDeleteOption           = null,
            string dataDiskDeleteOption         = null,
            string userData = null,
            AdditionalCapabilities additionalCapabilities = null,
            int?vCPUsAvailable = null,
            int?vCPUsPerCore   = null
            )

        => Strategy.CreateResourceConfig(
            resourceGroup: resourceGroup,
            name: name,
            createModel: engine => new VirtualMachine
        {
            OsProfile = new OSProfile
            {
                ComputerName         = name,
                WindowsConfiguration = imageAndOsType?.CreateWindowsConfiguration(),
                LinuxConfiguration   = (imageAndOsType?.OsType != OperatingSystemTypes.Linux) ? null : new LinuxConfiguration
                {
                    Ssh = new SshConfiguration(sshPublicKeys)
                },
                AdminUsername = adminUsername,
                AdminPassword = adminPassword,
            },
            Identity       = identity,
            NetworkProfile = new Azure.Management.Compute.Models.NetworkProfile
            {
                NetworkInterfaces = new[]
                {
                    engine.GetReference(networkInterface, networkInterfaceDeleteOption)
                }
            },
            HardwareProfile = new HardwareProfile
            {
                VmSize           = size,
                VmSizeProperties = (vCPUsPerCore == null && vCPUsAvailable == null) ? null : new VMSizeProperties
                {
                    VCPUsPerCore   = vCPUsPerCore,
                    VCPUsAvailable = vCPUsAvailable
                }
            },
            StorageProfile = new StorageProfile
            {
                ImageReference = imageAndOsType?.Image,
                DataDisks      = DataDiskStrategy.CreateDataDisks(
                    imageAndOsType?.DataDiskLuns, dataDisks, dataDiskDeleteOption)
            },
            AvailabilitySet         = engine.GetReference(availabilitySet),
            Zones                   = zones,
            AdditionalCapabilities  = additionalCapabilities,
            ProximityPlacementGroup = proximityPlacementGroup(engine),
            Host = string.IsNullOrEmpty(hostId) ? null : new SubResource(hostId),
            VirtualMachineScaleSet = string.IsNullOrEmpty(VmssId) ? null : new SubResource(VmssId),
            HostGroup           = string.IsNullOrEmpty(hostGroupId) ? null : new SubResource(hostGroupId),
            Priority            = priority,
            EvictionPolicy      = evictionPolicy,
            BillingProfile      = (maxPrice == null) ? null : new BillingProfile(maxPrice),
            SecurityProfile     = (encryptionAtHostPresent == true) ? new SecurityProfile(encryptionAtHost: encryptionAtHostPresent) : null,
            CapacityReservation = string.IsNullOrEmpty(capacityReservationGroupId) ? null : new CapacityReservationProfile
            {
                CapacityReservationGroup = new SubResource(capacityReservationGroupId)
            },
            UserData            = userData,
            PlatformFaultDomain = platformFaultDomain
        });