예제 #1
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            CloningInfo cloningInfo = null;

            if (SourceWebApp != null)
            {
                cloningInfo = new CloningInfo
                {
                    SourceWebAppId         = SourceWebApp.Id,
                    SourceWebAppLocation   = SourceWebApp.Location,
                    CloneCustomHostNames   = !IgnoreCustomHostNames.IsPresent,
                    CloneSourceControl     = !IgnoreSourceControl.IsPresent,
                    ConfigureLoadBalancing = false,
                    AppSettingsOverrides   = AppSettingsOverrides == null ? null : AppSettingsOverrides.Cast <DictionaryEntry>().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString(), StringComparer.Ordinal)
                };
                cloningInfo = new PSCloningInfo(cloningInfo);
            }

            var webApp = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, Name, null));
            var site   = new PSSite(WebsitesClient.CreateWebApp(ResourceGroupName, Name, Slot, webApp.Location, AppServicePlan == null?webApp.ServerFarmId : AppServicePlan, cloningInfo, AseName, AseResourceGroupName));

            UpdateConfigIfNeeded(site);
        }
예제 #2
0
        public override void ExecuteCmdlet()
        {
            CloningInfo cloningInfo = null;

            if (SourceWebApp != null)
            {
                cloningInfo = new CloningInfo
                {
                    SourceWebAppId            = SourceWebApp.Id,
                    CloneCustomHostNames      = !IgnoreCustomHostNames.IsPresent,
                    CloneSourceControl        = !IgnoreSourceControl.IsPresent,
                    TrafficManagerProfileId   = TrafficManagerProfileId,
                    TrafficManagerProfileName = TrafficManagerProfileName,
                    ConfigureLoadBalancing    = !string.IsNullOrEmpty(TrafficManagerProfileId) || !string.IsNullOrEmpty(TrafficManagerProfileName),
                    AppSettingsOverrides      = AppSettingsOverrides == null ? null: AppSettingsOverrides.Cast <DictionaryEntry>().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString(), StringComparer.Ordinal)
                };
            }

            var cloneWebAppSlots = false;

            string[] slotNames            = null;
            string   srcResourceGroupName = null;
            string   srcwebAppName        = null;
            string   srcSlotName          = null;

            if (IncludeSourceWebAppSlots.IsPresent)
            {
                CmdletHelpers.TryParseWebAppMetadataFromResourceId(SourceWebApp.Id, out srcResourceGroupName,
                                                                   out srcwebAppName, out srcSlotName);
                var slots = WebsitesClient.ListWebApps(srcResourceGroupName, srcwebAppName);
                if (slots != null && slots.Any())
                {
                    slotNames        = slots.Select(s => s.Name.Replace(srcwebAppName + "/", string.Empty)).ToArray();
                    cloneWebAppSlots = true;
                }
            }

            if (cloneWebAppSlots)
            {
                WriteVerboseWithTimestamp("Cloning source web app '{0}' to destination web app {1}", srcwebAppName, Name);
            }

            WriteObject(WebsitesClient.CreateWebApp(ResourceGroupName, Name, null, Location, AppServicePlan, cloningInfo, AseName, AseResourceGroupName));

            if (cloneWebAppSlots)
            {
                WriteVerboseWithTimestamp("Cloning all deployment slots of source web app '{0}' to destination web app {1}", srcwebAppName, Name);
                CloneSlots(slotNames);
            }
        }
예제 #3
0
        public void CreateWithClonedWebApp()
        {
            string      trafficManagerProfielId   = IsResource(TrafficManagerProfile) ? TrafficManagerProfile : null;
            string      trafficManagerProfileName = IsResource(TrafficManagerProfile) ? null : TrafficManagerProfile;
            CloningInfo cloningInfo = null;

            if (SourceWebApp != null)
            {
                cloningInfo = new CloningInfo
                {
                    SourceWebAppId            = SourceWebApp.Id,
                    CloneCustomHostNames      = !IgnoreCustomHostNames.IsPresent,
                    SourceWebAppLocation      = SourceWebApp.Location,
                    CloneSourceControl        = !IgnoreSourceControl.IsPresent,
                    TrafficManagerProfileId   = trafficManagerProfielId,
                    TrafficManagerProfileName = trafficManagerProfileName,
                    ConfigureLoadBalancing    = !string.IsNullOrEmpty(TrafficManagerProfile),
                    AppSettingsOverrides      = AppSettingsOverrides == null ? null : AppSettingsOverrides.Cast <DictionaryEntry>().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString(), StringComparer.Ordinal)
                };
                cloningInfo = new PSCloningInfo(cloningInfo);
            }

            var cloneWebAppSlots = false;

            string[] slotNames            = null;
            string   srcResourceGroupName = null;
            string   srcwebAppName        = null;
            string   srcSlotName          = null;

            if (IncludeSourceWebAppSlots.IsPresent)
            {
                CmdletHelpers.TryParseWebAppMetadataFromResourceId(SourceWebApp.Id, out srcResourceGroupName,
                                                                   out srcwebAppName, out srcSlotName);
                var slots = WebsitesClient.ListWebApps(srcResourceGroupName, srcwebAppName);
                if (slots != null && slots.Any())
                {
                    slotNames        = slots.Select(s => s.Name.Replace(srcwebAppName + "/", string.Empty)).ToArray();
                    cloneWebAppSlots = true;
                }
            }

            if (cloneWebAppSlots)
            {
                WriteVerboseWithTimestamp("Cloning source web app '{0}' to destination web app {1}", srcwebAppName, Name);
            }

            try
            {
                WriteObject(new PSSite(WebsitesClient.CreateWebApp(ResourceGroupName, Name, null, Location, AppServicePlan, cloningInfo, AseName, AseResourceGroupName)));
            }
            catch (Exception e)
            {
                if (e.Message.Contains("Operation returned an invalid status code \'BadRequest\'"))
                {
                    var message = e.Message + "\nIf AppServicePlan is present in other resourceGroup, please provide AppServicePlan in following format : \" /subscriptions/{subscriptionId}/resourcegroups/{resourcegroupName}/providers/Microsoft.Web/serverfarms/{serverFarmName}\"";
                    WriteObject(message);
                    throw new Exception(message, e);
                }
                throw e;
            }

            if (cloneWebAppSlots)
            {
                WriteVerboseWithTimestamp("Cloning all deployment slots of source web app '{0}' to destination web app {1}", srcwebAppName, Name);
                CloneSlots(slotNames);
            }
        }