예제 #1
0
        public override void ExecuteCmdlet()
        {
            WriteWarning("New-AzureRmVmss: A property of the output of this cmdlet will change in an upcoming breaking change release. " +
                         "The StorageAccountType property for a DataDisk will return Standard_LRS and Premium_LRS");

            switch (ParameterSetName)
            {
            case SimpleParameterSet:
                this.StartAndWait(SimpleParameterSetExecuteCmdlet);
                break;

            default:
                ExecuteClientAction(() =>
                {
                    if (ShouldProcess(this.VMScaleSetName, VerbsCommon.New))
                    {
                        string resourceGroupName          = this.ResourceGroupName;
                        string vmScaleSetName             = this.VMScaleSetName;
                        VirtualMachineScaleSet parameters = new VirtualMachineScaleSet();
                        ComputeAutomationAutoMapperProfile.Mapper.Map <PSVirtualMachineScaleSet, VirtualMachineScaleSet>(this.VirtualMachineScaleSet, parameters);

                        var result   = VirtualMachineScaleSetsClient.CreateOrUpdate(resourceGroupName, vmScaleSetName, parameters);
                        var psObject = new PSVirtualMachineScaleSet();
                        ComputeAutomationAutoMapperProfile.Mapper.Map <VirtualMachineScaleSet, PSVirtualMachineScaleSet>(result, psObject);
                        WriteObject(psObject);
                    }
                });
                break;
            }
        }
예제 #2
0
        public override void ExecuteCmdlet()
        {
            switch (ParameterSetName)
            {
            case SimpleParameterSet:
                this.StartAndWait(SimpleParameterSetExecuteCmdlet);
                break;

            default:
                ExecuteClientAction(() =>
                {
                    if (ShouldProcess(this.VMScaleSetName, VerbsCommon.New))
                    {
                        string resourceGroupName          = this.ResourceGroupName;
                        string vmScaleSetName             = this.VMScaleSetName;
                        VirtualMachineScaleSet parameters = new VirtualMachineScaleSet();
                        ComputeAutomationAutoMapperProfile.Mapper.Map <PSVirtualMachineScaleSet, VirtualMachineScaleSet>(this.VirtualMachineScaleSet, parameters);

                        var result   = VirtualMachineScaleSetsClient.CreateOrUpdate(resourceGroupName, vmScaleSetName, parameters);
                        var psObject = new PSVirtualMachineScaleSet();
                        ComputeAutomationAutoMapperProfile.Mapper.Map <VirtualMachineScaleSet, PSVirtualMachineScaleSet>(result, psObject);
                        WriteObject(psObject);
                    }
                });
                break;
            }
        }
예제 #3
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            switch (ParameterSetName)
            {
            case SimpleParameterSet:
                this.StartAndWait(SimpleParameterSetExecuteCmdlet);
                break;

            default:
                ExecuteClientAction(() =>
                {
                    if (ShouldProcess(this.VMScaleSetName, VerbsCommon.New))
                    {
                        string resourceGroupName          = this.ResourceGroupName;
                        string vmScaleSetName             = this.VMScaleSetName;
                        VirtualMachineScaleSet parameters = new VirtualMachineScaleSet();
                        ComputeAutomationAutoMapperProfile.Mapper.Map <PSVirtualMachineScaleSet, VirtualMachineScaleSet>(this.VirtualMachineScaleSet, parameters);
                        if (parameters?.VirtualMachineProfile?.StorageProfile?.ImageReference?.Version?.ToLower() != "latest")
                        {
                            WriteWarning("You are deploying VMSS pinned to a specific image version from Azure Marketplace. \n" +
                                         "Consider using \"latest\" as the image version. This allows VMSS to auto upgrade when a newer version is available.");
                        }
                        var result   = VirtualMachineScaleSetsClient.CreateOrUpdate(resourceGroupName, vmScaleSetName, parameters);
                        var psObject = new PSVirtualMachineScaleSet();
                        ComputeAutomationAutoMapperProfile.Mapper.Map <VirtualMachineScaleSet, PSVirtualMachineScaleSet>(result, psObject);
                        WriteObject(psObject);
                    }
                });
                break;
            }
        }
예제 #4
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            switch (ParameterSetName)
            {
            case SimpleParameterSet:
                this.StartAndWait(SimpleParameterSetExecuteCmdlet);
                break;

            default:
                ExecuteClientAction(() =>
                {
                    if (ShouldProcess(this.VMScaleSetName, VerbsCommon.New))
                    {
                        string resourceGroupName          = this.ResourceGroupName;
                        string vmScaleSetName             = this.VMScaleSetName;
                        VirtualMachineScaleSet parameters = new VirtualMachineScaleSet();
                        ComputeAutomationAutoMapperProfile.Mapper.Map <PSVirtualMachineScaleSet, VirtualMachineScaleSet>(this.VirtualMachineScaleSet, parameters);
                        if (parameters?.VirtualMachineProfile?.StorageProfile?.ImageReference?.Version?.ToLower() != "latest")
                        {
                            WriteWarning("You are deploying VMSS pinned to a specific image version from Azure Marketplace. \n" +
                                         "Consider using \"latest\" as the image version. This allows VMSS to auto upgrade when a newer version is available.");
                        }

                        if (parameters?.OrchestrationMode == "Flexible")
                        {
                            if (parameters?.VirtualMachineProfile?.NetworkProfile?.NetworkInterfaceConfigurations != null)
                            {
                                foreach (var nicConfig in parameters.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations)
                                {
                                    if (nicConfig.IpConfigurations != null)
                                    {
                                        foreach (var ipConfig in nicConfig.IpConfigurations)
                                        {
                                            ipConfig.LoadBalancerInboundNatPools = null;
                                        }
                                    }
                                }
                            }

                            parameters.UpgradePolicy = null;

                            flexibleOrchestrationModeDefaultParameters(parameters);
                            checkFlexibleOrchestrationModeParamsDefaultParamSet(parameters);
                        }


                        var result   = VirtualMachineScaleSetsClient.CreateOrUpdate(resourceGroupName, vmScaleSetName, parameters);
                        var psObject = new PSVirtualMachineScaleSet();
                        ComputeAutomationAutoMapperProfile.Mapper.Map <VirtualMachineScaleSet, PSVirtualMachineScaleSet>(result, psObject);
                        WriteObject(psObject);
                    }
                });
                break;
            }
        }
        protected void ExecuteVirtualMachineScaleSetCreateOrUpdateMethod(object[] invokeMethodInputParameters)
        {
            string resourceGroupName = (string)ParseParameter(invokeMethodInputParameters[0]);
            string name = (string)ParseParameter(invokeMethodInputParameters[1]);
            VirtualMachineScaleSet parameters = (VirtualMachineScaleSet)ParseParameter(invokeMethodInputParameters[2]);

            var result = VirtualMachineScaleSetsClient.CreateOrUpdate(resourceGroupName, name, parameters);

            WriteObject(result);
        }
        protected override void ProcessRecord()
        {
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.ResourceGroupName, VerbsData.Update))
                {
                    string resourceGroupName          = this.ResourceGroupName;
                    string vmScaleSetName             = this.VMScaleSetName;
                    VirtualMachineScaleSet parameters = this.VirtualMachineScaleSet;

                    var result = VirtualMachineScaleSetsClient.CreateOrUpdate(resourceGroupName, vmScaleSetName, parameters);
                    WriteObject(result);
                }
            });
        }
        protected override void ProcessRecord()
        {
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.VMScaleSetName, VerbsCommon.New))
                {
                    string resourceGroupName          = this.ResourceGroupName;
                    string vmScaleSetName             = this.VMScaleSetName;
                    VirtualMachineScaleSet parameters = new VirtualMachineScaleSet();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <PSVirtualMachineScaleSet, VirtualMachineScaleSet>(this.VirtualMachineScaleSet, parameters);

                    var result   = VirtualMachineScaleSetsClient.CreateOrUpdate(resourceGroupName, vmScaleSetName, parameters);
                    var psObject = new PSVirtualMachineScaleSet();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <VirtualMachineScaleSet, PSVirtualMachineScaleSet>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
예제 #8
0
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.UserData))
            {
                if (!ValidateBase64EncodedString.ValidateStringIsBase64Encoded(this.UserData))
                {
                    this.UserData = ValidateBase64EncodedString.EncodeStringToBase64(this.UserData);
                    this.WriteInformation(ValidateBase64EncodedString.UserDataEncodeNotification, new string[] { "PSHOST" });
                }
            }

            base.ExecuteCmdlet();
            switch (ParameterSetName)
            {
            case SimpleParameterSet:
                this.StartAndWait(SimpleParameterSetExecuteCmdlet);
                break;

            default:
                ExecuteClientAction(() =>
                {
                    if (ShouldProcess(this.VMScaleSetName, VerbsCommon.New))
                    {
                        string resourceGroupName          = this.ResourceGroupName;
                        string vmScaleSetName             = this.VMScaleSetName;
                        VirtualMachineScaleSet parameters = new VirtualMachineScaleSet();
                        ComputeAutomationAutoMapperProfile.Mapper.Map <PSVirtualMachineScaleSet, VirtualMachineScaleSet>(this.VirtualMachineScaleSet, parameters);
                        if (parameters?.VirtualMachineProfile?.StorageProfile?.ImageReference?.Version?.ToLower() != "latest")
                        {
                            WriteWarning("You are deploying VMSS pinned to a specific image version from Azure Marketplace. \n" +
                                         "Consider using \"latest\" as the image version. This allows VMSS to auto upgrade when a newer version is available.");
                        }

                        if (parameters?.OrchestrationMode == "Flexible")
                        {
                            if (parameters?.VirtualMachineProfile?.NetworkProfile?.NetworkInterfaceConfigurations != null)
                            {
                                foreach (var nicConfig in parameters.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations)
                                {
                                    if (nicConfig.IpConfigurations != null)
                                    {
                                        foreach (var ipConfig in nicConfig.IpConfigurations)
                                        {
                                            ipConfig.LoadBalancerInboundNatPools = null;
                                        }
                                    }
                                }
                            }

                            parameters.UpgradePolicy = null;

                            flexibleOrchestrationModeDefaultParameters(parameters);
                            checkFlexibleOrchestrationModeParamsDefaultParamSet(parameters);
                        }

                        // For Cross-tenant RBAC sharing
                        Dictionary <string, List <string> > auxAuthHeader = null;
                        if (!string.IsNullOrEmpty(parameters.VirtualMachineProfile?.StorageProfile?.ImageReference?.Id))
                        {
                            var resourceId = ResourceId.TryParse(parameters.VirtualMachineProfile?.StorageProfile.ImageReference.Id);

                            if (string.Equals(ComputeStrategy.Namespace, resourceId?.ResourceType?.Namespace, StringComparison.OrdinalIgnoreCase) &&
                                string.Equals("galleries", resourceId?.ResourceType?.Provider, StringComparison.OrdinalIgnoreCase) &&
                                !string.Equals(this.ComputeClient?.ComputeManagementClient?.SubscriptionId, resourceId?.SubscriptionId, StringComparison.OrdinalIgnoreCase))
                            {
                                List <string> resourceIds = new List <string>();
                                resourceIds.Add(parameters.VirtualMachineProfile?.StorageProfile.ImageReference.Id);
                                var auxHeaderDictionary = GetAuxilaryAuthHeaderFromResourceIds(resourceIds);
                                if (auxHeaderDictionary != null && auxHeaderDictionary.Count > 0)
                                {
                                    auxAuthHeader = new Dictionary <string, List <string> >(auxHeaderDictionary);
                                }
                            }
                        }
                        // END: For Cross-tenant RBAC sharing

                        VirtualMachineScaleSet result;
                        if (auxAuthHeader != null)
                        {
                            var res = VirtualMachineScaleSetsClient.CreateOrUpdateWithHttpMessagesAsync(
                                resourceGroupName,
                                vmScaleSetName,
                                parameters,
                                auxAuthHeader).GetAwaiter().GetResult();

                            result = res.Body;
                        }
                        else
                        {
                            result = VirtualMachineScaleSetsClient.CreateOrUpdate(resourceGroupName, vmScaleSetName, parameters);
                        }
                        var psObject = new PSVirtualMachineScaleSet();
                        ComputeAutomationAutoMapperProfile.Mapper.Map <VirtualMachineScaleSet, PSVirtualMachineScaleSet>(result, psObject);
                        WriteObject(psObject);
                    }
                });
                break;
            }
        }