public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            switch (ParameterSetName)
            {
            case ParameterSet1Name:
                AppServicePlan              = new PSAppServicePlan(WebsitesClient.GetAppServicePlan(ResourceGroupName, Name));
                AppServicePlan.Sku.Tier     = string.IsNullOrWhiteSpace(Tier) ? AppServicePlan.Sku.Tier : Tier;
                AppServicePlan.Sku.Capacity = NumberofWorkers > 0 ? NumberofWorkers : AppServicePlan.Sku.Capacity;
                int workerSizeAsNumber = 0;
                int.TryParse(Regex.Match(AppServicePlan.Sku.Name, @"\d+").Value, out workerSizeAsNumber);
                AppServicePlan.Sku.Name       = string.IsNullOrWhiteSpace(WorkerSize) ? CmdletHelpers.GetSkuName(AppServicePlan.Sku.Tier, workerSizeAsNumber) : CmdletHelpers.GetSkuName(AppServicePlan.Sku.Tier, WorkerSize);
                AppServicePlan.PerSiteScaling = PerSiteScaling;
                if (Tag != null && AppServicePlan.Tags != null)
                {
                    CmdletHelpers.ConvertToStringDictionary(Tag).ForEach(item => AppServicePlan.Tags?.Add(item));
                }
                else
                {
                    AppServicePlan.Tags = (IDictionary <string, string>)CmdletHelpers.ConvertToStringDictionary(Tag);
                }
                break;
            }

            // Fix Server Farm SKU description
            AppServicePlan.Sku.Size   = AppServicePlan.Sku.Name;
            AppServicePlan.Sku.Family = AppServicePlan.Sku.Name.Substring(0, 1);

            WriteObject(new PSAppServicePlan(WebsitesClient.CreateOrUpdateAppServicePlan(ResourceGroupName, Name, AppServicePlan)), true);
        }
예제 #2
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            string deletedSiteId = string.IsNullOrEmpty(DeletedId) ? GetDeletedSiteResourceId() : DeletedId;

            ResolveTargetParameters();

            DeletedAppRestoreRequest restoreReq = new DeletedAppRestoreRequest()
            {
                DeletedSiteId        = deletedSiteId,
                RecoverConfiguration = !this.RestoreContentOnly,
                UseDRSecondary       = UseDisasterRecovery
            };

            Action restoreAction = () => WebsitesClient.RestoreDeletedWebApp(TargetResourceGroupName, TargetName, TargetSlot, restoreReq);

            if (WebsitesClient.WebAppExists(TargetResourceGroupName, TargetName, TargetSlot))
            {
                ConfirmAction(this.Force.IsPresent, "Target web app contents will be overwritten with the contents of the deleted app.",
                              "The deleted app has been restored.", TargetName, restoreAction);
            }
            else
            {
                if (string.IsNullOrEmpty(TargetAppServicePlanName))
                {
                    throw new Exception("Target app " + TargetName + " does not exist. Specify TargetAppServicePlanName for it to be created automatically.");
                }
                AppServicePlan plan = WebsitesClient.GetAppServicePlan(TargetResourceGroupName, TargetAppServicePlanName);
                if (plan == null)
                {
                    throw new Exception("Target App Service Plan " + TargetAppServicePlanName + " not found in target Resource Group " + TargetResourceGroupName);
                }
                try
                {
                    Action createRestoreAction = () =>
                    {
                        WebsitesClient.CreateWebApp(TargetResourceGroupName, TargetName, TargetSlot, plan.Location, TargetAppServicePlanName,
                                                    null, string.Empty, string.Empty);
                        restoreAction();
                    };
                    string confirmMsg = string.Format("This web app will be created. App Name: {0}, Resource Group: {1}", TargetName, TargetResourceGroupName);
                    if (!string.IsNullOrEmpty(TargetSlot))
                    {
                        confirmMsg += ", Slot: " + TargetSlot;
                    }
                    ConfirmAction(this.Force.IsPresent, confirmMsg, "The deleted app has been restored.", TargetName, createRestoreAction);
                }
                catch (Exception e)
                {
                    WebsitesClient.RemoveWebApp(TargetResourceGroupName, TargetName, TargetSlot, true, true, false);
                    throw e;
                }
            }

            PSSite restoredApp = new PSSite(WebsitesClient.GetWebApp(TargetResourceGroupName, TargetName, TargetSlot));

            WriteObject(restoredApp);
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            switch (ParameterSetName)
            {
            case ParameterSet1Name:
                AppServicePlan              = WebsitesClient.GetAppServicePlan(ResourceGroupName, Name);
                AppServicePlan.Sku.Tier     = string.IsNullOrWhiteSpace(Tier) ? AppServicePlan.Sku.Tier : Tier;
                AppServicePlan.Sku.Capacity = NumberofWorkers > 0 ? NumberofWorkers : AppServicePlan.Sku.Capacity;
                var workerSizeAsNumber = int.Parse(AppServicePlan.Sku.Name.Substring(1, AppServicePlan.Sku.Name.Length - 1));
                AppServicePlan.Sku.Name = string.IsNullOrWhiteSpace(WorkerSize) ? CmdletHelpers.GetSkuName(AppServicePlan.Sku.Tier, workerSizeAsNumber) : CmdletHelpers.GetSkuName(AppServicePlan.Sku.Tier, WorkerSize);
                break;
            }

            // Fix Server Farm SKU description
            AppServicePlan.Sku.Size   = AppServicePlan.Sku.Name;
            AppServicePlan.Sku.Family = AppServicePlan.Sku.Name.Substring(0, 1);

            WriteObject(WebsitesClient.CreateAppServicePlan(ResourceGroupName, Name, AppServicePlan.Location, AdminSiteName, AppServicePlan.Sku), true);
        }
예제 #4
0
            public async Task <ResourceConfig <Site> > CreateConfigAsync()
            {
                _cmdlet.ResourceGroupName = _cmdlet.ResourceGroupName ?? _cmdlet.Name;
                _cmdlet.AppServicePlan    = _cmdlet.AppServicePlan ?? _cmdlet.Name;

                var planResourceGroup = _cmdlet.ResourceGroupName;
                var planName          = _cmdlet.AppServicePlan;

                var rgStrategy = ResourceGroupStrategy.CreateResourceGroupConfig(_cmdlet.ResourceGroupName);
                var planRG     = rgStrategy;

                if (_cmdlet.MyInvocation.BoundParameters.ContainsKey(nameof(AppServicePlan)))
                {
                    if (!_cmdlet.TryGetServerFarmFromResourceId(_cmdlet.AppServicePlan, out planResourceGroup, out planName))
                    {
                        planResourceGroup = _cmdlet.ResourceGroupName;
                        planName          = _cmdlet.AppServicePlan;
                    }

                    planRG = ResourceGroupStrategy.CreateResourceGroupConfig(planResourceGroup);
                }
                else
                {
                    var farm = await _cmdlet.GetDefaultServerFarm(Location);

                    if (farm != null)
                    {
                        planResourceGroup = farm.ResourceGroup;
                        planName          = farm.Name;
                        planRG            = ResourceGroupStrategy.CreateResourceGroupConfig(planResourceGroup);
                    }
                }
                AppServicePlan appServiceplan = _websitesClient.GetAppServicePlan(planResourceGroup, planName);

                // If ContainerImageName is specified and appservice plan doesn’t exist (appServiceplan == null) we will try to create plan with windows container
                var farmStrategy = planRG.CreateServerFarmConfig(planResourceGroup, planName, appServiceplan == null && _cmdlet.ContainerImageName != null);

                return(rgStrategy.CreateSiteConfig(farmStrategy, _cmdlet.Name, this.GetNewConfig(appServiceplan)));
            }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            switch (ParameterSetName)
            {
            case ParameterSet1Name:
                AppServicePlan              = WebsitesClient.GetAppServicePlan(ResourceGroupName, Name);
                AppServicePlan.Sku.Tier     = string.IsNullOrWhiteSpace(Tier) ? AppServicePlan.Sku.Tier : Tier;
                AppServicePlan.Sku.Capacity = NumberofWorkers > 0 ? NumberofWorkers : AppServicePlan.Sku.Capacity;
                int workerSizeAsNumber = 0;
                int.TryParse(Regex.Match(AppServicePlan.Sku.Name, @"\d+").Value, out workerSizeAsNumber);
                AppServicePlan.Sku.Name       = string.IsNullOrWhiteSpace(WorkerSize) ? CmdletHelpers.GetSkuName(AppServicePlan.Sku.Tier, workerSizeAsNumber) : CmdletHelpers.GetSkuName(AppServicePlan.Sku.Tier, WorkerSize);
                AppServicePlan.PerSiteScaling = PerSiteScaling;
                break;
            }

            // Fix Server Farm SKU description
            AppServicePlan.Sku.Size   = AppServicePlan.Sku.Name;
            AppServicePlan.Sku.Family = AppServicePlan.Sku.Name.Substring(0, 1);

            WriteObject(WebsitesClient.CreateAppServicePlan(ResourceGroupName, Name, AppServicePlan.Location, AdminSiteName, AppServicePlan.Sku, null, null, AppServicePlan.PerSiteScaling), true);
        }
        private void GetByAppServicePlanName()
        {
            const string progressDescriptionFormat = "Progress: {0}/{1} app service plans processed.";
            var          progressRecord            = new ProgressRecord(1, string.Format("Get app service plans with name '{0}'", Name), "Progress:");

            WriteProgress(progressRecord);

            var serverFarmResources = this.ResourcesClient.ResourceManagementClient.FilterResources(new FilterResourcesOptions()
            {
                ResourceType = "Microsoft.Web/ServerFarms"
            }).Where(sf => string.Equals(sf.Name, Name, StringComparison.OrdinalIgnoreCase)).ToArray();

            var list = new List <PSAppServicePlan>();

            for (var i = 0; i < serverFarmResources.Length; i++)
            {
                var sf = serverFarmResources[i];
                try
                {
                    var result = WebsitesClient.GetAppServicePlan(sf.ResourceGroupName, sf.Name);
                    if (result != null)
                    {
                        list.Add(new PSAppServicePlan(result));
                    }
                }
                catch (Exception e)
                {
                    WriteExceptionError(e);
                }

                progressRecord.StatusDescription = string.Format(progressDescriptionFormat, i + 1, serverFarmResources.Length);
                progressRecord.PercentComplete   = (100 * (i + 1)) / serverFarmResources.Length;
                WriteProgress(progressRecord);
            }

            WriteObject(list, true);
        }
예제 #7
0
 private void GetByWebHostingPlan()
 {
     WriteObject(WebsitesClient.GetAppServicePlan(ResourceGroupName, Name));
 }
        /// <summary>
        /// Execute the create new workflow command
        /// </summary>
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var workflow = LogicAppClient.GetWorkflow(this.ResourceGroupName, this.Name);

            if (this.Definition == null)
            {
                workflow.Definition = null;
            }
            else if (this.Definition.ToString() != string.Empty)
            {
                workflow.Definition = JToken.Parse(this.Definition.ToString());
            }

            if (!string.IsNullOrEmpty(this.DefinitionFilePath))
            {
                workflow.Definition = CmdletHelper.GetDefinitionFromFile(this.TryResolvePath(this.DefinitionFilePath));
            }

            if (!string.IsNullOrEmpty(this.IntegrationAccountId))
            {
                workflow.IntegrationAccount = new ResourceReference(this.IntegrationAccountId);
            }

            if (this.Parameters == null)
            {
                workflow.Parameters = null;
            }
            else if (this.Parameters.ToString() != string.Empty)
            {
                workflow.Parameters = CmdletHelper.ConvertToWorkflowParameterDictionary(this.Parameters);
            }

            if (!string.IsNullOrEmpty(this.ParameterFilePath))
            {
                workflow.Parameters = CmdletHelper.GetParametersFromFile(this.TryResolvePath(this.ParameterFilePath));
            }

            if (!string.IsNullOrEmpty(this.State))
            {
                workflow.State = this.State;
            }

            if (UseConsumptionModel.IsPresent)
            {
                workflow.Sku = null;
            }
            else if (!string.IsNullOrEmpty(this.AppServicePlan))
            {
                var servicePlan = WebsitesClient.GetAppServicePlan(this.ResourceGroupName, this.AppServicePlan);
                workflow.Sku = new Sku
                {
                    Name = servicePlan.Sku.Tier,
                    Plan = new ResourceReference(id: servicePlan.Id)
                };
            }

            if (workflow.Definition == null)
            {
                throw new PSArgumentException(Properties.Resource.DefinitionMissingWarning);
            }

            ConfirmAction(Force.IsPresent,
                          string.Format(CultureInfo.InvariantCulture, Properties.Resource.UpdateResourceWarning,
                                        "Microsoft.Logic/workflows", this.Name),
                          string.Format(CultureInfo.InvariantCulture, Properties.Resource.UpdateResourceMessage,
                                        "Microsoft.Logic/workflows", this.Name),
                          Name,
                          () =>
            {
                this.WriteObject(LogicAppClient.UpdateWorkflow(this.ResourceGroupName, this.Name, workflow), true);
            },
                          null);
        }
 private void GetAppServicePlan()
 {
     WriteObject(WebsitesClient.GetAppServicePlan(ResourceGroupName, Name), true);
 }
        /// <summary>
        /// Execute the create new workflow command
        /// </summary>
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if (this.Definition != null)
            {
                this.Definition = JToken.Parse(this.Definition.ToString());
            }

            if (!string.IsNullOrEmpty(this.DefinitionFilePath))
            {
                this.Definition = CmdletHelper.GetDefinitionFromFile(this.TryResolvePath(this.DefinitionFilePath));
            }

            if (this.Parameters != null)
            {
                this.Parameters = CmdletHelper.ConvertToWorkflowParameterDictionary(this.Parameters);
            }

            if (!string.IsNullOrEmpty(this.ParameterFilePath))
            {
                this.Parameters = CmdletHelper.GetParametersFromFile(this.TryResolvePath(this.ParameterFilePath));
            }

            var servicePlan = WebsitesClient.GetAppServicePlan(this.ResourceGroupName, this.AppServicePlan);

            if (string.IsNullOrEmpty(this.Location))
            {
                this.Location = servicePlan.GeoRegion;
            }

            this.WriteObject(LogicAppClient.CreateWorkflow(this.ResourceGroupName, this.Name, new Workflow
            {
                Location       = this.Location,
                Definition     = this.Definition,
                Parameters     = this.Parameters as Dictionary <string, WorkflowParameter>,
                DefinitionLink = string.IsNullOrEmpty(this.DefinitionLinkUri)
                    ? null
                    : new ContentLink
                {
                    Uri            = this.DefinitionLinkUri,
                    ContentVersion = this.DefinitionLinkContentVersion
                },
                ParametersLink = string.IsNullOrEmpty(this.ParameterLinkUri)
                    ? null
                    : new ContentLink
                {
                    Uri            = this.ParameterLinkUri,
                    ContentVersion = this.ParameterLinkContentVersion
                },
                State = (WorkflowState)Enum.Parse(typeof(WorkflowState), this.State),
                Sku   = new Sku
                {
                    Name = (SkuName)Enum.Parse(typeof(SkuName), servicePlan.Sku.Tier),
                    Plan = new ResourceReference
                    {
                        Id = servicePlan.Id
                    }
                }
            }), true);
        }
예제 #11
0
        /// <summary>
        /// Execute the create new workflow command
        /// </summary>
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var workflow = LogicAppClient.GetWorkflow(this.ResourceGroupName, this.Name);

            if (this.Definition == null)
            {
                workflow.Definition = null;
            }
            else if (this.Definition.ToString() != string.Empty)
            {
                workflow.Definition = JToken.Parse(this.Definition.ToString());
            }

            if (!string.IsNullOrEmpty(this.DefinitionFilePath))
            {
                workflow.Definition = CmdletHelper.GetDefinitionFromFile(this.TryResolvePath(this.DefinitionFilePath));
            }

            if (this.Parameters == null)
            {
                workflow.Parameters = null;
            }
            else if (this.Parameters.ToString() != string.Empty)
            {
                workflow.Parameters = CmdletHelper.ConvertToWorkflowParameterDictionary(this.Parameters);
            }

            if (!string.IsNullOrEmpty(this.ParameterFilePath))
            {
                workflow.Parameters = CmdletHelper.GetParametersFromFile(this.TryResolvePath(this.ParameterFilePath));
            }

            if (this.DefinitionLinkUri == null)
            {
                workflow.DefinitionLink = null;
            }
            else if (this.DefinitionLinkUri != string.Empty)
            {
                workflow.DefinitionLink = new ContentLink
                {
                    Uri            = this.DefinitionLinkUri,
                    ContentVersion = this.DefinitionLinkContentVersion
                };
            }

            if (this.ParameterLinkUri == null)
            {
                workflow.ParametersLink = null;
            }
            else if (this.ParameterLinkUri != string.Empty)
            {
                workflow.ParametersLink = new ContentLink
                {
                    Uri            = this.ParameterLinkUri,
                    ContentVersion = this.ParameterLinkContentVersion
                };
            }

            if (!string.IsNullOrEmpty(this.State))
            {
                workflow.State = (WorkflowState)Enum.Parse(typeof(WorkflowState), this.State);
            }

            if (!string.IsNullOrEmpty(this.AppServicePlan))
            {
                var servicePlan = WebsitesClient.GetAppServicePlan(this.ResourceGroupName, this.AppServicePlan);
                workflow.Sku = new Sku
                {
                    Name = (SkuName)Enum.Parse(typeof(SkuName), servicePlan.Sku.Tier),
                    Plan = new ResourceReference
                    {
                        Id = servicePlan.Id
                    }
                };
            }

            if (workflow.DefinitionLink == null && workflow.Definition == null)
            {
                throw new PSArgumentException(Properties.Resource.DefinitionMissingWarning);
            }

            this.WriteObject(LogicAppClient.UpdateWorkflow(this.ResourceGroupName, this.Name, workflow), true);
        }