/// <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 #2
0
        /// <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);
            }

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

            // Delete the specified firewall rule.
            OperationResponse response = sqlManagementClient.FirewallRules.Delete(serverName, ruleName);

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

            return(operationContext);
        }
Beispiel #3
0
        /// <summary>
        /// Performs the call to export database using the server data service context channel.
        /// </summary>
        /// <param name="serverName">The name of the server to connect to.</param>
        /// <param name="fullyQualifiedServerName">The fully qualfied name of the server to connect to.</param>
        /// <param name="userName">The username for authentication</param>
        /// <param name="password">The password for authentication</param>
        /// <param name="requestId">The request Id of the operation to query</param>
        /// <returns>The status of the import/export operation</returns>
        internal IEnumerable <StatusInfo> GetAzureSqlDatabaseImportExportStatusProcess(
            string serverName,
            string fullyQualifiedServerName,
            string userName,
            string password,
            string requestId)
        {
            // Get the SQL management client for the current subscription
            SqlManagementClient sqlManagementClient = SqlDatabaseCmdletBase.GetCurrentSqlClient();

            // Start the database export operation
            DacGetStatusResponse response = sqlManagementClient.Dacs.GetStatus(
                serverName,
                fullyQualifiedServerName,
                userName,
                password,
                requestId);

            // Construct the result
            IEnumerable <StatusInfo> result = response.StatusInfoList.Select(status => new StatusInfo
            {
                BlobUri          = status.BlobUri.ToString(),
                ServerName       = status.ServerName,
                DatabaseName     = status.DatabaseName,
                Status           = status.Status,
                RequestId        = status.RequestId,
                LastModifiedTime = status.LastModifiedTime,
                QueuedTime       = status.QueuedTime,
                RequestType      = status.RequestType,
                ErrorMessage     = status.ErrorMessage,
            });

            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new firewall rule on the specified server.
        /// </summary>
        /// <param name="parameterSetName">The parameter set for the command.</param>
        /// <param name="serverName">The name of the server in which to create the firewall rule.</param>
        /// <param name="ruleName">The name of the new firewall rule.</param>
        /// <param name="startIpAddress">The starting IP address for the firewall rule.</param>
        /// <param name="endIpAddress">The ending IP address for the firewall rule.</param>
        /// <returns>The context to the newly created firewall rule.</returns>
        internal SqlDatabaseServerFirewallRuleContext NewAzureSqlDatabaseServerFirewallRuleProcess(
            string parameterSetName,
            string serverName,
            string ruleName,
            string startIpAddress,
            string endIpAddress)
        {
            // Get the SQL management client for the current subscription
            SqlManagementClient sqlManagementClient = SqlDatabaseCmdletBase.GetCurrentSqlClient();

            // Create the firewall rule
            FirewallRuleCreateResponse response = sqlManagementClient.FirewallRules.Create(
                serverName,
                new FirewallRuleCreateParameters()
            {
                Name           = ruleName,
                StartIPAddress = startIpAddress,
                EndIPAddress   = endIpAddress,
            });

            SqlDatabaseServerFirewallRuleContext operationContext = new SqlDatabaseServerFirewallRuleContext()
            {
                OperationDescription = CommandRuntime.ToString(),
                OperationStatus      = Services.Constants.OperationSuccess,
                OperationId          = response.RequestId,
                ServerName           = serverName,
                RuleName             = ruleName,
                StartIpAddress       = response.StartIPAddress,
                EndIpAddress         = response.EndIPAddress,
            };

            return(operationContext);
        }
Beispiel #5
0
        /// <summary>
        /// Performs the call to import database using the server data service context channel.
        /// </summary>
        /// <param name="serverName">The name of the server to connect to.</param>
        /// <param name="blobUri">The storage blob Uri to import from.</param>
        /// <param name="storageAccessKey">The access key for the given storage blob.</param>
        /// <param name="fullyQualifiedServerName">The fully qualified server name.</param>
        /// <param name="databaseName">The name of the database for import.</param>
        /// <param name="edition">The edition of the database for import.</param>
        /// <param name="maxDatabaseSizeInGB">The database size for import.</param>
        /// <param name="sqlCredentials">The credentials used to connect to the database.</param>
        /// <returns>The result of the import request.  Upon success the <see cref="ImportExportRequest"/>
        /// for the request</returns>
        internal ImportExportRequest ImportSqlAzureDatabaseProcess(
            string serverName,
            Uri blobUri,
            string storageAccessKey,
            string fullyQualifiedServerName,
            string databaseName,
            string edition,
            int maxDatabaseSizeInGB,
            SqlAuthenticationCredentials sqlCredentials)
        {
            this.WriteVerbose("BlobUri: " + blobUri);
            this.WriteVerbose("ServerName: " + fullyQualifiedServerName);
            this.WriteVerbose("DatabaseName: " + databaseName);
            this.WriteVerbose("Edition: " + edition);
            this.WriteVerbose("MaxDatabaseSizeInGB: " + maxDatabaseSizeInGB);
            this.WriteVerbose("UserName: " + sqlCredentials.UserName);

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

            // Start the database export operation
            DacImportExportResponse response = sqlManagementClient.Dac.Import(
                serverName,
                new DacImportParameters()
            {
                BlobCredentials = new DacImportParameters.BlobCredentialsParameter()
                {
                    Uri = blobUri,
                    StorageAccessKey = storageAccessKey,
                },
                ConnectionInfo = new DacImportParameters.ConnectionInfoParameter()
                {
                    ServerName   = fullyQualifiedServerName,
                    DatabaseName = databaseName,
                    UserName     = sqlCredentials.UserName,
                    Password     = sqlCredentials.Password,
                },
                AzureEdition     = edition,
                DatabaseSizeInGB = maxDatabaseSizeInGB
            });

            ImportExportRequest result = new ImportExportRequest()
            {
                OperationStatus      = Services.Constants.OperationSuccess,
                OperationDescription = CommandRuntime.ToString(),
                OperationId          = response.RequestId,
                RequestGuid          = response.Guid,
                ServerName           = serverName,
                SqlCredentials       = sqlCredentials,
            };

            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// Retrieves one or more firewall rules on the specified server.
        /// </summary>
        /// <param name="serverName">The name of the server to retrieve firewall rules for.</param>
        /// <param name="ruleName">
        /// The specific name of the rule to retrieve, or <c>null</c> to
        /// retrieve all rules on the specified server.
        /// </param>
        /// <returns>A list of firewall rules on the server.</returns>
        internal IEnumerable <SqlDatabaseServerFirewallRuleContext> GetAzureSqlDatabaseServerFirewallRuleProcess(
            string serverName,
            string ruleName)
        {
            // Get the SQL management client for the current subscription
            SqlManagementClient sqlManagementClient = SqlDatabaseCmdletBase.GetCurrentSqlClient();

            // Retrieve the list of databases
            FirewallRuleListResponse   response      = sqlManagementClient.FirewallRules.List(serverName);
            IEnumerable <FirewallRule> firewallRules = response.FirewallRules;

            if (!string.IsNullOrEmpty(ruleName))
            {
                // Firewall rule name is specified, find the one
                // with the specified rule name and return that.
                firewallRules = firewallRules.Where(p => p.Name == ruleName);
                if (!firewallRules.Any())
                {
                    throw new ItemNotFoundException(string.Format(
                                                        CultureInfo.InvariantCulture,
                                                        Resources.GetAzureSqlDatabaseServerFirewallRuleNotFound,
                                                        ruleName,
                                                        serverName));
                }
            }
            else
            {
                // Firewall rule name is not specified, return all
                // firewall rules.
            }

            IEnumerable <SqlDatabaseServerFirewallRuleContext> processResult = firewallRules.Select(p => new SqlDatabaseServerFirewallRuleContext()
            {
                OperationDescription = CommandRuntime.ToString(),
                OperationStatus      = Services.Constants.OperationSuccess,
                OperationId          = response.RequestId,
                ServerName           = serverName,
                RuleName             = p.Name,
                StartIpAddress       = p.StartIPAddress,
                EndIpAddress         = p.EndIPAddress
            });

            return(processResult);
        }
        /// <summary>
        /// Retrieves one or more servers in the current subscription.
        /// </summary>
        /// <param name="serverName">
        /// The specific name of the server to retrieve, or <c>null</c> to
        /// retrieve all servers in the current subscription.
        /// </param>
        /// <returns>A list of servers in the subscription.</returns>
        internal IEnumerable <SqlDatabaseServerContext> GetAzureSqlDatabaseServersProcess(string serverName)
        {
            // Get the SQL management client for the current subscription
            SqlManagementClient sqlManagementClient = SqlDatabaseCmdletBase.GetCurrentSqlClient();

            // Retrieve the list of servers
            ServerListResponse   response = sqlManagementClient.Servers.List();
            IEnumerable <Server> servers  = response.Servers;

            if (!string.IsNullOrEmpty(serverName))
            {
                // Server name is specified, find the one with the
                // specified rule name and return that.
                servers = response.Servers.Where(s => s.Name == serverName);
                if (!servers.Any())
                {
                    throw new ItemNotFoundException(string.Format(
                                                        CultureInfo.InvariantCulture,
                                                        Resources.GetAzureSqlDatabaseServerNotFound,
                                                        serverName));
                }
            }
            else
            {
                // Server name is not specified, return all servers
                // in the subscription.
            }

            // Construct the result
            IEnumerable <SqlDatabaseServerContext> processResult = servers.Select(server => new SqlDatabaseServerContext
            {
                OperationStatus      = Services.Constants.OperationSuccess,
                OperationDescription = CommandRuntime.ToString(),
                OperationId          = response.RequestId,
                ServerName           = server.Name,
                Location             = server.Location,
                AdministratorLogin   = server.AdministratorUserName,
            });

            return(processResult);
        }
        /// <summary>
        /// Creates a new server in the current subscription.
        /// </summary>
        /// <param name="adminLogin">
        /// The administrator login name for the new server.
        /// </param>
        /// <param name="adminLoginPassword">
        /// The administrator login password for the new server.
        /// </param>
        /// <param name="location">
        /// The location in which to create the new server.
        /// </param>
        /// <returns>The context to the newly created server.</returns>
        internal SqlDatabaseServerContext NewAzureSqlDatabaseServerProcess(
            string adminLogin,
            string adminLoginPassword,
            string location)
        {
            // Do nothing if force is not specified and user cancelled the operation
            if (!Force.IsPresent &&
                !ShouldProcess(
                    Resources.NewAzureSqlDatabaseServerDescription,
                    Resources.NewAzureSqlDatabaseServerWarning,
                    Resources.ShouldProcessCaption))
            {
                return(null);
            }

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

            // Issue the create server request
            ServerCreateResponse response = sqlManagementClient.Servers.Create(
                new ServerCreateParameters()
            {
                Location = location,
                AdministratorUserName = adminLogin,
                AdministratorPassword = adminLoginPassword
            });

            SqlDatabaseServerContext operationContext = new SqlDatabaseServerContext()
            {
                OperationStatus      = Services.Constants.OperationSuccess,
                OperationDescription = CommandRuntime.ToString(),
                OperationId          = response.RequestId,
                ServerName           = response.ServerName,
                Location             = location,
                AdministratorLogin   = adminLogin,
            };

            return(operationContext);
        }