Пример #1
0
        private async Task <(VirtualMachineScaleSet, VirtualMachineScaleSet)> CreateVMScaleSetAndGetOperationResponse(
            string rgName,
            string vmssName,
            StorageAccount storageAccount,
            ImageReference imageRef,
            VirtualMachineScaleSetExtensionProfile extensionProfile = null,
            Action <VirtualMachineScaleSet> vmScaleSetCustomizer    = null,
            bool createWithPublicIpAddress = false,
            bool createWithManagedDisks    = false,
            bool hasDiffDisks          = false,
            bool createWithHealthProbe = false,
            Subnet subnet              = null,
            IList <string> zones       = null,
            int?osDiskSizeInGB         = null,
            string ppgId               = null,
            string machineSizeType     = null,
            bool?enableUltraSSD        = false,
            string diskEncryptionSetId = null,
            AutomaticRepairsPolicy automaticRepairsPolicy = null)
        {
            // Create the resource Group, it might have been already created during StorageAccount creation.
            var resourceGroup = await ResourceGroupsOperations.CreateOrUpdateAsync(
                rgName,
                new ResourceGroup(m_location));

            var getPublicIpAddressResponse = createWithPublicIpAddress ? null : await CreatePublicIP(rgName);

            var subnetResponse = subnet ?? await CreateVNET(rgName);

            var nicResponse = await CreateNIC(
                rgName,
                subnetResponse,
                getPublicIpAddressResponse != null?getPublicIpAddressResponse.IpAddress : null);

            var loadBalancer = ((getPublicIpAddressResponse != null && createWithHealthProbe) ?
                                (await CreatePublicLoadBalancerWithProbe(rgName, getPublicIpAddressResponse)) : null);

            Assert.True(createWithManagedDisks || storageAccount != null);
            var inputVMScaleSet = CreateDefaultVMScaleSetInput(rgName, storageAccount?.Name, imageRef, subnetResponse.Id, hasManagedDisks: createWithManagedDisks,
                                                               healthProbeId: loadBalancer?.Probes?.FirstOrDefault()?.Id,
                                                               loadBalancerBackendPoolId: loadBalancer?.BackendAddressPools?.FirstOrDefault()?.Id, zones: zones, osDiskSizeInGB: osDiskSizeInGB,
                                                               machineSizeType: machineSizeType, enableUltraSSD: enableUltraSSD, diskEncryptionSetId: diskEncryptionSetId, automaticRepairsPolicy: automaticRepairsPolicy);

            if (vmScaleSetCustomizer != null)
            {
                vmScaleSetCustomizer(inputVMScaleSet);
            }

            if (hasDiffDisks)
            {
                VirtualMachineScaleSetOSDisk osDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionTypes.FromImage);
                osDisk.Caching          = CachingTypes.ReadOnly;
                osDisk.DiffDiskSettings = new DiffDiskSettings
                {
                    Option = "Local",
                    //TODO the value of "Placement" may not be given
                    //Placement = DiffDiskPlacement.CacheDisk
                };
                inputVMScaleSet.VirtualMachineProfile.StorageProfile.OsDisk = osDisk;
            }

            inputVMScaleSet.VirtualMachineProfile.ExtensionProfile = extensionProfile;

            if (ppgId != null)
            {
                inputVMScaleSet.ProximityPlacementGroup = new Azure.ResourceManager.Compute.Models.SubResource()
                {
                    Id = ppgId
                };
            }

            VirtualMachineScaleSet createOrUpdateResponse = null;

            try
            {
                createOrUpdateResponse = await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartCreateOrUpdateAsync(rgName, vmssName, inputVMScaleSet));

                Assert.True(createOrUpdateResponse.Name == vmssName);
                Assert.True(createOrUpdateResponse.Location.ToLower() == inputVMScaleSet.Location.ToLower().Replace(" ", ""));
            }
            catch (Exception e)
            {
                if (e.Message.Contains("the allotted time"))
                {
                    createOrUpdateResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName);
                }
                else
                {
                    throw;
                }
            }

            ValidateVMScaleSet(inputVMScaleSet, createOrUpdateResponse, createWithManagedDisks, ppgId: ppgId);

            return(createOrUpdateResponse, inputVMScaleSet);
        }
Пример #2
0
        //not use in track one
        //protected async Task<VirtualMachineScaleSet> CreateVMScaleSet(
        //    string rgName,
        //    string vmssName,
        //    StorageAccount storageAccount,
        //    ImageReference imageRef,
        //    VirtualMachineScaleSetExtensionProfile extensionProfile = null,
        //    Action<VirtualMachineScaleSet> vmScaleSetCustomizer = null,
        //    bool createWithPublicIpAddress = false,
        //    bool createWithManagedDisks = false)
        //{
        //    try
        //    {
        //        var createOrUpdateResponse = CreateVMScaleSetAndGetOperationResponse(
        //            rgName,
        //            vmssName,
        //            storageAccount,
        //            imageRef,
        //            extensionProfile,
        //            vmScaleSetCustomizer,
        //            createWithPublicIpAddress,
        //            createWithManagedDisks);

        //        var lroResponse = await VirtualMachineScaleSetsClient.StartCreateOrUpdateAsync(rgName, inputVMScaleSet.Name, inputVMScaleSet);

        //        var getResponse = await VirtualMachineScaleSetsClient.Get(rgName, inputVMScaleSet.Name);

        //        return getResponse;
        //    }
        //    catch
        //    {
        //        await ResourceGroupsClient.Delete(rgName);
        //        throw;
        //    }
        //}

        protected async Task UpdateVMScaleSet(string rgName, string vmssName, VirtualMachineScaleSet inputVMScaleSet)
        {
            var createOrUpdateResponse = await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartCreateOrUpdateAsync(rgName, vmssName, inputVMScaleSet));
        }