/// <summary>
        /// Resets the administrator password for an existing server in the
        /// current subscription.
        /// </summary>
        /// <param name="serverName">
        /// The name of the server for which to reset the password.
        /// </param>
        /// <param name="newPassword">
        /// The new password for the server.
        /// </param>
        /// <returns>The context to this operation.</returns>
        internal SqlDatabaseServerOperationContext ResetAzureSqlDatabaseServerAdminPasswordProcess(string serverName, string newPassword)
        {
            // Do nothing if force is not specified and user cancelled the operation
            if (!Force.IsPresent &&
                !ShouldProcess(
                    string.Format(CultureInfo.InvariantCulture, Resources.SetAzureSqlDatabaseServerAdminPasswordDescription, serverName),
                    string.Format(CultureInfo.InvariantCulture, Resources.SetAzureSqlDatabaseServerAdminPasswordWarning, serverName),
                    Resources.ShouldProcessCaption))
            {
                return(null);
            }

            // Get the SQL management client for the current subscription
            SqlManagementClient sqlManagementClient = SqlDatabaseCmdletBase.GetCurrentSqlClient();

            // Issue the change admin password request
            OperationResponse response = sqlManagementClient.Servers.ChangeAdministratorPassword(
                serverName,
                new ServerChangeAdministratorPasswordParameters()
            {
                NewPassword = newPassword
            });

            SqlDatabaseServerOperationContext operationContext = new SqlDatabaseServerOperationContext()
            {
                OperationStatus      = Services.Constants.OperationSuccess,
                OperationDescription = CommandRuntime.ToString(),
                OperationId          = response.RequestId,
                ServerName           = serverName,
            };

            return(operationContext);
        }
        /// <summary>
        /// Removes an existing server in the current subscription.
        /// </summary>
        /// <param name="serverName">The name of the server to remove.</param>
        /// <returns>The context to this operation.</returns>
        internal SqlDatabaseServerOperationContext RemoveAzureSqlDatabaseServerProcess(string serverName)
        {
            // Do nothing if force is not specified and user cancelled the operation
            if (!Force.IsPresent &&
                !ShouldProcess(
                    string.Format(CultureInfo.InvariantCulture, Resources.RemoveAzureSqlDatabaseServerDescription, serverName),
                    string.Format(CultureInfo.InvariantCulture, Resources.RemoveAzureSqlDatabaseServerWarning, serverName),
                    Resources.ShouldProcessCaption))
            {
                return(null);
            }

            // Get the SQL management client for the current subscription
            SqlManagementClient sqlManagementClient = GetCurrentSqlClient();

            // Issue the delete server request
            OperationResponse response = sqlManagementClient.Servers.Delete(serverName);
            SqlDatabaseServerOperationContext operationContext = new SqlDatabaseServerOperationContext()
            {
                OperationStatus      = Services.Constants.OperationSuccess,
                OperationDescription = CommandRuntime.ToString(),
                OperationId          = response.RequestId,
                ServerName           = serverName,
            };

            return(operationContext);
        }
Beispiel #3
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            try
            {
                base.ProcessRecord();
                SqlDatabaseServerOperationContext context = this.SetAzureSqlDatabaseServerFirewallRuleProcess(this.ServerName, this.RuleName, this.StartIpAddress, this.EndIpAddress);

                if (context != null)
                {
                    WriteObject(context, true);
                }
            }
            catch (Exception ex)
            {
                WriteWindowsAzureError(new ErrorRecord(ex, string.Empty, ErrorCategory.WriteError, null));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Removes an existing server in the current subscription.
        /// </summary>
        /// <param name="serverName">
        /// The name of the server to remove.
        /// </param>
        /// <returns>The context to this operation.</returns>
        internal SqlDatabaseServerOperationContext RemoveAzureSqlDatabaseServerProcess(string serverName)
        {
            // Do nothing if force is not specified and user cancelled the operation
            if (!Force.IsPresent &&
                !ShouldProcess(
                    string.Format(CultureInfo.InvariantCulture, Resources.RemoveAzureSqlDatabaseServerDescription, serverName),
                    string.Format(CultureInfo.InvariantCulture, Resources.RemoveAzureSqlDatabaseServerWarning, serverName),
                    Resources.ShouldProcessCaption))
            {
                return(null);
            }

            SqlDatabaseServerOperationContext operationContext = null;

            try
            {
                InvokeInOperationContext(() =>
                {
                    RetryCall(subscription =>
                              Channel.RemoveServer(subscription, serverName));
                    WAPPSCmdlet.Operation operation = WaitForSqlDatabaseOperation();

                    operationContext = new SqlDatabaseServerOperationContext()
                    {
                        ServerName           = serverName,
                        OperationStatus      = operation.Status,
                        OperationDescription = CommandRuntime.ToString(),
                        OperationId          = operation.OperationTrackingId
                    };
                });
            }
            catch (CommunicationException ex)
            {
                this.WriteErrorDetails(ex);
            }

            return(operationContext);
        }
        /// <summary>
        /// Removes a new firewall rule on the specified server.
        /// </summary>
        /// <param name="serverName">
        /// The name of the server containing the firewall rule.
        /// </param>
        /// <param name="ruleName">
        /// The name of the firewall rule to remove.
        /// </param>
        /// <returns>The context to this operation.</returns>
        internal SqlDatabaseServerOperationContext RemoveAzureSqlDatabaseServerFirewallRuleProcess(string serverName, string ruleName)
        {
            // Do nothing if force is not specified and user cancelled the operation
            if (!Force.IsPresent &&
                !ShouldProcess(
                    string.Format(CultureInfo.InvariantCulture, Resources.RemoveAzureSqlDatabaseServerFirewallRuleDescription, ruleName, serverName),
                    string.Format(CultureInfo.InvariantCulture, Resources.RemoveAzureSqlDatabaseServerFirewallRuleWarning, ruleName, serverName),
                    Resources.ShouldProcessCaption))
            {
                return null;
            }

            SqlDatabaseServerOperationContext operationContext = null;
            try
            {
                InvokeInOperationContext(() =>
                {
                    RetryCall(subscription =>
                        Channel.RemoveServerFirewallRule(subscription, serverName, ruleName));
                    Operation operation = WaitForSqlDatabaseOperation();

                    operationContext = new SqlDatabaseServerOperationContext()
                    {
                        OperationDescription = CommandRuntime.ToString(),
                        OperationId = operation.OperationTrackingId,
                        OperationStatus = operation.Status,
                        ServerName = serverName
                    };
                });
            }
            catch (CommunicationException ex)
            {
                this.WriteErrorDetails(ex);
            }

            return operationContext;
        }
        /// <summary>
        /// Resets the administrator password for an existing server in the
        /// current subscription.
        /// </summary>
        /// <param name="serverName">
        /// The name of the server for which to reset the password.
        /// </param>
        /// <param name="newPassword">
        /// The new password for the server.
        /// </param>
        /// <returns>The context to this operation.</returns>
        internal SqlDatabaseServerOperationContext ResetAzureSqlDatabaseServerAdminPasswordProcess(string serverName, string newPassword)
        {
            // Do nothing if force is not specified and user cancelled the operation
            if (!Force.IsPresent &&
                !ShouldProcess(
                    string.Format(CultureInfo.InvariantCulture, Resources.SetAzureSqlDatabaseServerAdminPasswordDescription, serverName),
                    string.Format(CultureInfo.InvariantCulture, Resources.SetAzureSqlDatabaseServerAdminPasswordWarning, serverName),
                    Resources.ShouldProcessCaption))
            {
                return null;
            }

            // Get the SQL management client for the current subscription
            SqlManagementClient sqlManagementClient = SqlDatabaseCmdletBase.GetCurrentSqlClient();

            // Issue the change admin password request
            OperationResponse response = sqlManagementClient.Servers.ChangeAdministratorPassword(
                serverName, 
                new ServerChangeAdministratorPasswordParameters()
                {
                    NewPassword = newPassword
                });

            SqlDatabaseServerOperationContext operationContext = new SqlDatabaseServerOperationContext()
            {
                OperationStatus = Services.Constants.OperationSuccess,
                OperationDescription = CommandRuntime.ToString(),
                OperationId = response.RequestId,
                ServerName = serverName,
            };

            return operationContext;
        }
Beispiel #7
0
        /// <summary>
        /// Process the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            // Do nothing if force is not specified and user cancelled the operation
            string verboseDescription = string.Format(
                CultureInfo.InvariantCulture,
                Resources.NewAzureSqlDatabaseServerFirewallRuleDescription,
                this.RuleName,
                this.ServerName);

            string verboseWarning = string.Format(
                CultureInfo.InvariantCulture,
                Resources.NewAzureSqlDatabaseServerFirewallRuleWarning,
                this.RuleName,
                this.ServerName);

            if (!this.Force.IsPresent &&
                !this.ShouldProcess(verboseDescription, verboseWarning, Resources.ShouldProcessCaption))
            {
                return;
            }

            try
            {
                base.ProcessRecord();
                SqlDatabaseServerOperationContext context = null;

                switch (this.ParameterSetName)
                {
                case IpRangeParameterSet:
                    context = this.NewAzureSqlDatabaseServerFirewallRuleProcess(
                        this.ParameterSetName,
                        this.ServerName,
                        this.RuleName,
                        this.StartIpAddress,
                        this.EndIpAddress);
                    break;

                case AllowAllAzureServicesParameterSet:

                    //Determine which rule name to use.
                    string ruleName = AllowAllAzureServicesRuleName;
                    if (this.MyInvocation.BoundParameters.ContainsKey("RuleName"))
                    {
                        ruleName = this.RuleName;
                    }

                    //Create the rule
                    context = this.NewAzureSqlDatabaseServerFirewallRuleProcess(
                        this.ParameterSetName,
                        this.ServerName,
                        ruleName,
                        AllowAzureServicesRuleAddress,
                        AllowAzureServicesRuleAddress);
                    break;
                }

                if (context != null)
                {
                    this.WriteObject(context, true);
                }
            }
            catch (Exception ex)
            {
                this.WriteWindowsAzureError(new ErrorRecord(ex, string.Empty, ErrorCategory.WriteError, null));
            }
        }