/// <summary>
        /// Executes the cmdlet.
        /// </summary>
        protected override void OnProcessRecord()
        {
            var deploymentOperations = ResourceManagerSdkClient.ListDeploymentOperationsAtResourceGroup(
                ResourceGroupName, DeploymentName);

            WriteObject(deploymentOperations, true);
        }
        protected PSWhatIfOperationResult ExecuteWhatIf()
        {
            const string statusMessage = "Getting the latest status of all resources...";
            var          clearMessage  = new string(' ', statusMessage.Length);
            var          information   = new HostInformationMessage {
                Message = statusMessage, NoNewLine = true
            };
            var clearInformation = new HostInformationMessage {
                Message = $"\r{clearMessage}\r", NoNewLine = true
            };
            var tags = new[] { "PSHOST" };

            try
            {
                // Write status message.
                this.WriteInformation(information, tags);

                PSWhatIfOperationResult whatIfResult = ResourceManagerSdkClient.ExecuteDeploymentWhatIf(this.WhatIfParameters);

                // Clear status before returning result.
                this.WriteInformation(clearInformation, tags);

                return(whatIfResult);
            }
            catch (Exception)
            {
                // Clear status before on exception.
                this.WriteInformation(clearInformation, tags);
                throw;
            }
        }
Exemplo n.º 3
0
        protected override void OnProcessRecord()
        {
            string whatIfMessage  = this.ShouldExecuteWhatIf() ? this.ExecuteWhatIf() : null;
            string warningMessage = $"{Environment.NewLine}{ProjectResources.ConfirmDeploymentMessage}";
            string captionMessage = $"{(char)27}[1A{Color.Reset}{whatIfMessage}"; // {(char)27}[1A for cursor up.

            if (ShouldProcess(whatIfMessage, warningMessage, captionMessage))
            {
                var parameters = new PSDeploymentCmdletParameters()
                {
                    ScopeType               = DeploymentScopeType.Subscription,
                    Location                = Location,
                    DeploymentName          = Name,
                    DeploymentMode          = DeploymentMode.Incremental,
                    TemplateFile            = TemplateUri ?? this.TryResolvePath(TemplateFile),
                    TemplateObject          = TemplateObject,
                    TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
                    ParameterUri            = TemplateParameterUri,
                    DeploymentDebugLogLevel = GetDeploymentDebugLogLevel(DeploymentDebugLogLevel),
                    Tags = TagsHelper.ConvertToTagsDictionary(Tag)
                };

                if (!string.IsNullOrEmpty(parameters.DeploymentDebugLogLevel))
                {
                    WriteWarning(ProjectResources.WarnOnDeploymentDebugSetting);
                }
                WriteObject(ResourceManagerSdkClient.ExecuteDeployment(parameters));
            }
        }
Exemplo n.º 4
0
        public override void ExecuteCmdlet()
        {
            this.ConfirmAction(
                this.Force,
                string.Format(ProjectResources.ConfirmOnCompleteDeploymentMode, this.ResourceGroupName),
                ProjectResources.CreateDeployment,
                ResourceGroupName,
                () =>
            {
                PSCreateResourceGroupDeploymentParameters parameters = new PSCreateResourceGroupDeploymentParameters()
                {
                    ResourceGroupName       = ResourceGroupName,
                    DeploymentName          = Name,
                    DeploymentMode          = Mode,
                    TemplateFile            = TemplateUri ?? this.TryResolvePath(TemplateFile),
                    TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
                    ParameterUri            = TemplateParameterUri,
                    DeploymentDebugLogLevel = GetDeploymentDebugLogLevel(DeploymentDebugLogLevel)
                };

                if (!string.IsNullOrEmpty(parameters.DeploymentDebugLogLevel))
                {
                    WriteWarning(ProjectResources.WarnOnDeploymentDebugSetting);
                }
                WriteObject(ResourceManagerSdkClient.ExecuteDeployment(parameters));
            },
                () => this.Mode == DeploymentMode.Complete);
        }
Exemplo n.º 5
0
        private void ExecuteDeployment()
        {
            if (RollbackToLastDeployment && !string.IsNullOrEmpty(RollBackDeploymentName))
            {
                WriteExceptionError(new ArgumentException(ProjectResources.InvalidRollbackParameters));
            }

            var parameters = new PSDeploymentCmdletParameters()
            {
                ScopeType               = DeploymentScopeType.ResourceGroup,
                ResourceGroupName       = ResourceGroupName,
                DeploymentName          = Name,
                DeploymentMode          = Mode,
                TemplateFile            = TemplateUri ?? this.TryResolvePath(TemplateFile),
                TemplateObject          = TemplateObject,
                TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
                ParameterUri            = TemplateParameterUri,
                DeploymentDebugLogLevel = GetDeploymentDebugLogLevel(DeploymentDebugLogLevel),
                Tags = TagsHelper.ConvertToTagsDictionary(Tag),
                OnErrorDeployment = RollbackToLastDeployment || !string.IsNullOrEmpty(RollBackDeploymentName)
                    ? new OnErrorDeployment
                {
                    Type           = RollbackToLastDeployment ? OnErrorDeploymentType.LastSuccessful : OnErrorDeploymentType.SpecificDeployment,
                    DeploymentName = RollbackToLastDeployment ? null : RollBackDeploymentName
                }
                    : null
            };

            if (!string.IsNullOrEmpty(parameters.DeploymentDebugLogLevel))
            {
                WriteWarning(ProjectResources.WarnOnDeploymentDebugSetting);
            }
            WriteObject(ResourceManagerSdkClient.ExecuteResourceGroupDeployment(parameters));
        }
        /// <summary>
        /// Get the default resource group for stoarge admin.
        /// This is consturcted as "System." + Location
        /// </summary>
        protected void GetDefaultResourceGroup()
        {
            WriteVerbose("Fetching default Resource Group");
            ResourceManagerSdkClient resourcesSdkClient = new ResourceManagerSdkClient(DefaultContext)
            {
                VerboseLogger = WriteVerboseWithTimestamp,
                ErrorLogger   = WriteErrorWithTimestamp,
                WarningLogger = WriteWarningWithTimestamp
            };

            PSResourceProvider[] providers = resourcesSdkClient.ListResourceProviders(providerName: AzureStackStorageAdminNameSpace)
                                             .Select(provider => provider.ToPSResourceProvider()).ToArray();

            if (null == providers || null == providers.FirstOrDefault() ||
                null == providers.FirstOrDefault().Locations || String.IsNullOrEmpty(providers.FirstOrDefault().Locations.FirstOrDefault()))
            {
                WriteErrorWithTimestamp(String.Format("Failed to get Resource Provider {0}", AzureStackStorageAdminNameSpace));
                WriteErrorWithTimestamp("Failed to Obtain Default location");
                throw new InvalidOperationException("Failed to Obtain Default location");
            }
            else
            {
                this.ResourceGroupName = AzureStackStorageAdminDefaultResourceGroupPrefix + providers.First().Locations.First();
                WriteVerbose(String.Format("Obtained Default Resource Group {0}", this.ResourceGroupName));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Collects subscription ids from the pipeline.
        /// </summary>
        protected override void OnProcessRecord()
        {
            base.OnProcessRecord();
            this.DefaultApiVersion = string.IsNullOrWhiteSpace(this.ApiVersion) ? Constants.ResourcesApiVersion : this.ApiVersion;
            var resourceId = string.Empty;

            if (ShouldConstructResourceId(out resourceId))
            {
                ResourceId = resourceId;
            }

            if (!string.IsNullOrEmpty(ResourceId) && IsValidResourceId(ResourceId))
            {
                var resource = ResourceManagerSdkClient.GetById(ResourceId, DefaultApiVersion);
                WriteObject(resource);
            }
            else if (this.IsParameterBound(c => c.ApiVersion) || this.IsParameterBound(c => c.ExpandProperties) || !string.IsNullOrEmpty(ResourceId))
            {
                this.RunCmdlet();
            }
            else
            {
                this.RunSimpleCmdlet();
            }
        }
        /// <summary>
        /// Executes the cmdlet.
        /// </summary>
        protected override void OnProcessRecord()
        {
            base.OnProcessRecord();

            var deploymentName = !string.IsNullOrEmpty(this.DeploymentName) ? this.DeploymentName : this.DeploymentObject.DeploymentName;

            if (ShouldProcess(deploymentName, VerbsData.Save))
            {
                var template = ResourceManagerSdkClient.GetDeploymentTemplate(deploymentName);

                string path = FileUtility.SaveTemplateFile(
                    templateName: deploymentName,
                    contents: template,
                    outputPath:
                    string.IsNullOrEmpty(this.Path)
                            ? System.IO.Path.Combine(CurrentPath(), deploymentName)
                            : this.TryResolvePath(this.Path),
                    overwrite: this.Force,
                    shouldContinue: ShouldContinue);

                WriteObject(new PSTemplatePath()
                {
                    Path = path
                });
            }
        }
Exemplo n.º 9
0
        public override void ExecuteCmdlet()
        {
            if (RollbackToLastDeployment && !string.IsNullOrEmpty(RollBackDeploymentName))
            {
                WriteExceptionError(new ArgumentException(ProjectResources.InvalidRollbackParameters));
            }

            PSDeploymentCmdletParameters parameters = new PSDeploymentCmdletParameters()
            {
                DeploymentName          = DeploymentName ?? Guid.NewGuid().ToString(),
                ResourceGroupName       = ResourceGroupName,
                TemplateFile            = TemplateUri ?? this.ResolvePath(TemplateFile),
                TemplateObject          = TemplateObject,
                TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
                ParameterUri            = TemplateParameterUri,
                OnErrorDeployment       = RollbackToLastDeployment || !string.IsNullOrEmpty(RollBackDeploymentName)
                    ? new OnErrorDeployment
                {
                    Type           = RollbackToLastDeployment ? OnErrorDeploymentType.LastSuccessful : OnErrorDeploymentType.SpecificDeployment,
                    DeploymentName = RollbackToLastDeployment ? null : RollBackDeploymentName
                }
                    : null
            };

            WriteObject(ResourceManagerSdkClient.ValidateDeployment(parameters, Mode));
        }
        /// <summary>
        /// Executes the cmdlet.
        /// </summary>
        protected override void OnProcessRecord()
        {
            base.OnProcessRecord();

            var options = new FilterDeploymentOptions(DeploymentScopeType.ManagementGroup)
            {
                ManagementGroupId = !string.IsNullOrEmpty(this.ManagementGroupId) ? this.ManagementGroupId : this.DeploymentObject.ManagementGroupId,
                DeploymentName    = !string.IsNullOrEmpty(this.DeploymentName) ? this.DeploymentName : this.DeploymentObject.DeploymentName
            };

            if (ShouldProcess(options.DeploymentName, VerbsData.Save))
            {
                var template = ResourceManagerSdkClient.GetDeploymentTemplateAtManagementGroup(options.ManagementGroupId, options.DeploymentName);

                string path = FileUtility.SaveTemplateFile(
                    templateName: options.DeploymentName,
                    contents: template,
                    outputPath:
                    string.IsNullOrEmpty(this.Path)
                            ? System.IO.Path.Combine(CurrentPath(), options.DeploymentName)
                            : this.TryResolvePath(this.Path),
                    overwrite: this.Force,
                    shouldContinue: ShouldContinue);

                WriteObject(new PSTemplatePath()
                {
                    Path = path
                });
            }
        }
Exemplo n.º 11
0
        public override void ExecuteCmdlet()
        {
            Name = Name ?? ResourceIdentifier.FromResourceGroupIdentifier(this.Id).ResourceGroupName;

            this.WriteObject(
                ResourceManagerSdkClient.FilterResourceGroups(name: this.Name, tag: this.Tag, detailed: false, location: this.Location),
                true);
        }
Exemplo n.º 12
0
        public override void ExecuteCmdlet()
        {
            FilterDeploymentOptions options = new FilterDeploymentOptions(DeploymentScopeType.Tenant)
            {
                DeploymentName = this.Name ?? (string.IsNullOrEmpty(this.Id) ? null : ResourceIdUtility.GetDeploymentName(this.Id))
            };

            WriteObject(ResourceManagerSdkClient.FilterDeployments(options), true);
        }
        protected override void OnProcessRecord()
        {
            FilterDeploymentOptions options = new FilterDeploymentOptions(DeploymentScopeType.Subscription)
            {
                DeploymentName = this.Name ?? (string.IsNullOrEmpty(this.Id) ? null : ResourceIdUtility.GetResourceName(this.Id))
            };

            WriteObject(ResourceManagerSdkClient.FilterDeployments(options), true);
        }
Exemplo n.º 14
0
        public override void ExecuteCmdlet()
        {
            FilterDeploymentOptions options = new FilterDeploymentOptions()
            {
                DeploymentName = Name ?? (string.IsNullOrEmpty(Id) ? null : ResourceIdUtility.GetResourceName(Id))
            };

            WriteObject(ResourceManagerSdkClient.FilterDeploymentsAtSubscriptionScope(options), true);
        }
Exemplo n.º 15
0
        public override void ExecuteCmdlet()
        {
            FilterDeploymentOptions options = new FilterDeploymentOptions(DeploymentScopeType.ResourceGroup)
            {
                ResourceGroupName = ResourceGroupName ?? ResourceIdUtility.GetResourceGroupName(Id),
                DeploymentName    = Name ?? (string.IsNullOrEmpty(Id) ? null : ResourceIdUtility.GetResourceName(Id))
            };

            WriteObject(ResourceManagerSdkClient.FilterResourceGroupDeployments(options), true);
        }
        public override void ExecuteCmdlet()
        {
            WriteWarning(ProjectResources.WarnOnTags);
            PSUpdateResourceGroupParameters parameters = new PSUpdateResourceGroupParameters
            {
                ResourceGroupName = Name ?? ResourceIdentifier.FromResourceGroupIdentifier(this.Id).ResourceGroupName,
                Tag = Tag,
            };

            WriteObject(ResourceManagerSdkClient.UpdatePSResourceGroup(parameters));
        }
        public override void ExecuteCmdlet()
        {
            var options = new FilterDeploymentOptions(DeploymentScopeType.Tenant)
            {
                DeploymentName = !string.IsNullOrEmpty(this.DeploymentName) ? this.DeploymentName : this.DeploymentObject.DeploymentName
            };

            var deploymentOperations = ResourceManagerSdkClient.ListDeploymentOperationsAtTenantScope(
                options.DeploymentName, this.OperationId);

            WriteObject(deploymentOperations, true);
        }
        public override void ExecuteCmdlet()
        {
            PSDeploymentCmdletParameters parameters = new PSDeploymentCmdletParameters()
            {
                ResourceGroupName       = ResourceGroupName,
                TemplateFile            = TemplateUri ?? this.TryResolvePath(TemplateFile),
                TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
                ParameterUri            = TemplateParameterUri
            };

            WriteObject(ResourceManagerSdkClient.ValidateDeployment(parameters, Mode));
        }
Exemplo n.º 19
0
        public override void ExecuteCmdlet()
        {
            var parameters = new PSDeploymentCmdletParameters()
            {
                Location                = Location,
                TemplateFile            = TemplateUri ?? this.TryResolvePath(TemplateFile),
                TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
                ParameterUri            = TemplateParameterUri
            };

            WriteObject(ResourceManagerSdkClient.ValidateDeployment(parameters, DeploymentMode.Incremental));
        }
Exemplo n.º 20
0
        protected override void OnProcessRecord()
        {
            var options = new FilterDeploymentOptions(DeploymentScopeType.ManagementGroup)
            {
                ManagementGroupId = !string.IsNullOrEmpty(this.ManagementGroupId) ? this.ManagementGroupId : this.DeploymentObject.ManagementGroupId,
                DeploymentName    = !string.IsNullOrEmpty(this.DeploymentName) ? this.DeploymentName : this.DeploymentObject.DeploymentName
            };

            var deploymentOperations = ResourceManagerSdkClient.ListDeploymentOperationsAtManagementGroup(
                options.ManagementGroupId, options.DeploymentName, this.OperationId);

            WriteObject(deploymentOperations, true);
        }
Exemplo n.º 21
0
        protected override void OnProcessRecord()
        {
            PSCreateResourceGroupParameters parameters = new PSCreateResourceGroupParameters
            {
                ResourceGroupName = Name,
                Location          = Location,
                Force             = Force.IsPresent,
                Tag           = Tag,
                ConfirmAction = ConfirmAction
            };

            WriteObject(ResourceManagerSdkClient.CreatePSResourceGroup(parameters));
        }
        protected override void OnProcessRecord()
        {
            Name = Name ?? ResourceIdentifier.FromResourceGroupIdentifier(this.Id).ResourceGroupName;

            ConfirmAction(
                Force.IsPresent,
                string.Format(ProjectResources.RemovingResourceGroup, Name),
                ProjectResources.RemoveResourceGroupMessage,
                Name,
                () => ResourceManagerSdkClient.DeleteResourceGroup(Name));

            WriteObject(true);
        }
Exemplo n.º 23
0
        public override void ExecuteCmdlet()
        {
            PSCreateResourceGroupParameters parameters = new PSCreateResourceGroupParameters
            {
                ResourceGroupName = Name,
                Location          = Location,
                Force             = Force.IsPresent,
                Tag           = Tag,
                ConfirmAction = ConfirmAction
            };

            WriteObject(ResourceManagerSdkClient.CreatePSResourceGroup(parameters));
        }
Exemplo n.º 24
0
        public override void ExecuteCmdlet()
        {
            if (string.IsNullOrEmpty(ResourceGroupName) && string.IsNullOrEmpty(Name))
            {
                ResourceGroupName = ResourceIdUtility.GetResourceGroupName(Id);
                Name = ResourceIdUtility.GetResourceName(Id);
            }
            ConfirmAction(
                ProjectResources.CancelResourceGroupDeploymentMessage,
                ResourceGroupName,
                () => ResourceManagerSdkClient.CancelDeployment(ResourceGroupName, Name));

            WriteObject(true);
        }
Exemplo n.º 25
0
        public override void ExecuteCmdlet()
        {
            ConfirmAction(
                ProjectResources.DeleteDeploymentMessage,
                ResourceGroupName,
                () =>
            {
                var resourceGroupName = !string.IsNullOrEmpty(this.ResourceGroupName) ? this.ResourceGroupName : ResourceIdUtility.GetResourceGroupName(Id);
                var deploymentName    = !string.IsNullOrEmpty(this.Name) ? this.Name : ResourceIdUtility.GetResourceName(Id);

                ResourceManagerSdkClient.DeleteDeploymentAtResourceGroup(resourceGroupName, deploymentName);
                WriteObject(true);
            });
        }
Exemplo n.º 26
0
        public override void ExecuteCmdlet()
        {
            var parameters = new PSDeploymentCmdletParameters()
            {
                ScopeType               = DeploymentScopeType.Tenant,
                Location                = this.Location,
                TemplateFile            = this.TemplateUri ?? this.TryResolvePath(this.TemplateFile),
                TemplateObject          = this.TemplateObject,
                TemplateParameterObject = this.GetTemplateParameterObject(this.TemplateParameterObject),
                ParameterUri            = this.TemplateParameterUri
            };

            WriteObject(ResourceManagerSdkClient.ValidateDeployment(parameters));
        }
        public override void ExecuteCmdlet()
        {
            PSUpdateResourceGroupParameters parameters = new PSUpdateResourceGroupParameters
            {
                ResourceGroupName = Name ?? ResourceIdentifier.FromResourceGroupIdentifier(this.Id).ResourceGroupName,
                Tag = Tag,
            };

            var resourceGroup = ResourceManagerSdkClient.UpdatePSResourceGroup(parameters);
            if (resourceGroup != null)
            {
                WriteObject(resourceGroup);
            }
        }
Exemplo n.º 28
0
        protected override void OnProcessRecord()
        {
            var parameters = new PSDeploymentCmdletParameters()
            {
                ScopeType               = DeploymentScopeType.Subscription,
                Location                = Location,
                TemplateFile            = TemplateUri ?? this.TryResolvePath(TemplateFile),
                TemplateObject          = TemplateObject,
                TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
                ParameterUri            = TemplateParameterUri
            };

            WriteObject(ResourceManagerSdkClient.ValidateDeployment(parameters));
        }
        protected override void OnProcessRecord()
        {
            var parameters = new PSDeploymentCmdletParameters()
            {
                ScopeType               = DeploymentScopeType.ManagementGroup,
                ManagementGroupId       = this.ManagementGroupId,
                Location                = this.Location,
                TemplateFile            = this.TemplateUri ?? this.TryResolvePath(this.TemplateFile),
                TemplateObject          = this.TemplateObject,
                TemplateParameterObject = this.GetTemplateParameterObject(this.TemplateParameterObject),
                ParameterUri            = this.TemplateParameterUri
            };

            WriteObject(ResourceManagerSdkClient.ValidateDeployment(parameters));
        }
Exemplo n.º 30
0
        public override void ExecuteCmdlet()
        {
            var options = new FilterDeploymentOptions(DeploymentScopeType.ResourceGroup)
            {
                ResourceGroupName = !string.IsNullOrEmpty(this.ResourceGroupName) ? this.ResourceGroupName : ResourceIdUtility.GetResourceGroupName(Id),
                DeploymentName    = !string.IsNullOrEmpty(this.Name) ? this.Name : ResourceIdUtility.GetResourceName(Id)
            };

            ConfirmAction(
                ProjectResources.CancelDeploymentMessage,
                ResourceGroupName,
                () => ResourceManagerSdkClient.CancelDeployment(options));

            WriteObject(true);
        }