mirror of
https://github.com/octoleo/restic.git
synced 2024-12-03 10:28:27 +00:00
61cb1cc6f8
This includes github.com/kurin/blazer 0.2.0, which resolves #1291
419 lines
18 KiB
Go
419 lines
18 KiB
Go
package sql
|
|
|
|
// Copyright (c) Microsoft and contributors. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
//
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
// Code generated by Microsoft (R) AutoRest Code Generator.
|
|
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
|
|
import (
|
|
"github.com/Azure/go-autorest/autorest"
|
|
"github.com/Azure/go-autorest/autorest/azure"
|
|
"net/http"
|
|
)
|
|
|
|
// ReplicationLinksClient is the the Azure SQL Database management API provides a RESTful set of web services that
|
|
// interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update,
|
|
// and delete databases.
|
|
type ReplicationLinksClient struct {
|
|
ManagementClient
|
|
}
|
|
|
|
// NewReplicationLinksClient creates an instance of the ReplicationLinksClient client.
|
|
func NewReplicationLinksClient(subscriptionID string) ReplicationLinksClient {
|
|
return NewReplicationLinksClientWithBaseURI(DefaultBaseURI, subscriptionID)
|
|
}
|
|
|
|
// NewReplicationLinksClientWithBaseURI creates an instance of the ReplicationLinksClient client.
|
|
func NewReplicationLinksClientWithBaseURI(baseURI string, subscriptionID string) ReplicationLinksClient {
|
|
return ReplicationLinksClient{NewWithBaseURI(baseURI, subscriptionID)}
|
|
}
|
|
|
|
// Delete deletes a database replication link. Cannot be done during failover.
|
|
//
|
|
// resourceGroupName is the name of the resource group that contains the resource. You can obtain this value from the
|
|
// Azure Resource Manager API or the portal. serverName is the name of the server. databaseName is the name of the
|
|
// database that has the replication link to be dropped. linkID is the ID of the replication link to be deleted.
|
|
func (client ReplicationLinksClient) Delete(resourceGroupName string, serverName string, databaseName string, linkID string) (result autorest.Response, err error) {
|
|
req, err := client.DeletePreparer(resourceGroupName, serverName, databaseName, linkID)
|
|
if err != nil {
|
|
err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Delete", nil, "Failure preparing request")
|
|
return
|
|
}
|
|
|
|
resp, err := client.DeleteSender(req)
|
|
if err != nil {
|
|
result.Response = resp
|
|
err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Delete", resp, "Failure sending request")
|
|
return
|
|
}
|
|
|
|
result, err = client.DeleteResponder(resp)
|
|
if err != nil {
|
|
err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Delete", resp, "Failure responding to request")
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// DeletePreparer prepares the Delete request.
|
|
func (client ReplicationLinksClient) DeletePreparer(resourceGroupName string, serverName string, databaseName string, linkID string) (*http.Request, error) {
|
|
pathParameters := map[string]interface{}{
|
|
"databaseName": autorest.Encode("path", databaseName),
|
|
"linkId": autorest.Encode("path", linkID),
|
|
"resourceGroupName": autorest.Encode("path", resourceGroupName),
|
|
"serverName": autorest.Encode("path", serverName),
|
|
"subscriptionId": autorest.Encode("path", client.SubscriptionID),
|
|
}
|
|
|
|
const APIVersion = "2014-04-01"
|
|
queryParameters := map[string]interface{}{
|
|
"api-version": APIVersion,
|
|
}
|
|
|
|
preparer := autorest.CreatePreparer(
|
|
autorest.AsDelete(),
|
|
autorest.WithBaseURL(client.BaseURI),
|
|
autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}", pathParameters),
|
|
autorest.WithQueryParameters(queryParameters))
|
|
return preparer.Prepare(&http.Request{})
|
|
}
|
|
|
|
// DeleteSender sends the Delete request. The method will close the
|
|
// http.Response Body if it receives an error.
|
|
func (client ReplicationLinksClient) DeleteSender(req *http.Request) (*http.Response, error) {
|
|
return autorest.SendWithSender(client, req)
|
|
}
|
|
|
|
// DeleteResponder handles the response to the Delete request. The method always
|
|
// closes the http.Response Body.
|
|
func (client ReplicationLinksClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
|
|
err = autorest.Respond(
|
|
resp,
|
|
client.ByInspecting(),
|
|
azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
|
|
autorest.ByClosing())
|
|
result.Response = resp
|
|
return
|
|
}
|
|
|
|
// Failover sets which replica database is primary by failing over from the current primary replica database. This
|
|
// method may poll for completion. Polling can be canceled by passing the cancel channel argument. The channel will be
|
|
// used to cancel polling and any outstanding HTTP requests.
|
|
//
|
|
// resourceGroupName is the name of the resource group that contains the resource. You can obtain this value from the
|
|
// Azure Resource Manager API or the portal. serverName is the name of the server. databaseName is the name of the
|
|
// database that has the replication link to be failed over. linkID is the ID of the replication link to be failed
|
|
// over.
|
|
func (client ReplicationLinksClient) Failover(resourceGroupName string, serverName string, databaseName string, linkID string, cancel <-chan struct{}) (<-chan autorest.Response, <-chan error) {
|
|
resultChan := make(chan autorest.Response, 1)
|
|
errChan := make(chan error, 1)
|
|
go func() {
|
|
var err error
|
|
var result autorest.Response
|
|
defer func() {
|
|
if err != nil {
|
|
errChan <- err
|
|
}
|
|
resultChan <- result
|
|
close(resultChan)
|
|
close(errChan)
|
|
}()
|
|
req, err := client.FailoverPreparer(resourceGroupName, serverName, databaseName, linkID, cancel)
|
|
if err != nil {
|
|
err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Failover", nil, "Failure preparing request")
|
|
return
|
|
}
|
|
|
|
resp, err := client.FailoverSender(req)
|
|
if err != nil {
|
|
result.Response = resp
|
|
err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Failover", resp, "Failure sending request")
|
|
return
|
|
}
|
|
|
|
result, err = client.FailoverResponder(resp)
|
|
if err != nil {
|
|
err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Failover", resp, "Failure responding to request")
|
|
}
|
|
}()
|
|
return resultChan, errChan
|
|
}
|
|
|
|
// FailoverPreparer prepares the Failover request.
|
|
func (client ReplicationLinksClient) FailoverPreparer(resourceGroupName string, serverName string, databaseName string, linkID string, cancel <-chan struct{}) (*http.Request, error) {
|
|
pathParameters := map[string]interface{}{
|
|
"databaseName": autorest.Encode("path", databaseName),
|
|
"linkId": autorest.Encode("path", linkID),
|
|
"resourceGroupName": autorest.Encode("path", resourceGroupName),
|
|
"serverName": autorest.Encode("path", serverName),
|
|
"subscriptionId": autorest.Encode("path", client.SubscriptionID),
|
|
}
|
|
|
|
const APIVersion = "2014-04-01"
|
|
queryParameters := map[string]interface{}{
|
|
"api-version": APIVersion,
|
|
}
|
|
|
|
preparer := autorest.CreatePreparer(
|
|
autorest.AsPost(),
|
|
autorest.WithBaseURL(client.BaseURI),
|
|
autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/failover", pathParameters),
|
|
autorest.WithQueryParameters(queryParameters))
|
|
return preparer.Prepare(&http.Request{Cancel: cancel})
|
|
}
|
|
|
|
// FailoverSender sends the Failover request. The method will close the
|
|
// http.Response Body if it receives an error.
|
|
func (client ReplicationLinksClient) FailoverSender(req *http.Request) (*http.Response, error) {
|
|
return autorest.SendWithSender(client,
|
|
req,
|
|
azure.DoPollForAsynchronous(client.PollingDelay))
|
|
}
|
|
|
|
// FailoverResponder handles the response to the Failover request. The method always
|
|
// closes the http.Response Body.
|
|
func (client ReplicationLinksClient) FailoverResponder(resp *http.Response) (result autorest.Response, err error) {
|
|
err = autorest.Respond(
|
|
resp,
|
|
client.ByInspecting(),
|
|
azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent, http.StatusAccepted),
|
|
autorest.ByClosing())
|
|
result.Response = resp
|
|
return
|
|
}
|
|
|
|
// FailoverAllowDataLoss sets which replica database is primary by failing over from the current primary replica
|
|
// database. This operation might result in data loss. This method may poll for completion. Polling can be canceled by
|
|
// passing the cancel channel argument. The channel will be used to cancel polling and any outstanding HTTP requests.
|
|
//
|
|
// resourceGroupName is the name of the resource group that contains the resource. You can obtain this value from the
|
|
// Azure Resource Manager API or the portal. serverName is the name of the server. databaseName is the name of the
|
|
// database that has the replication link to be failed over. linkID is the ID of the replication link to be failed
|
|
// over.
|
|
func (client ReplicationLinksClient) FailoverAllowDataLoss(resourceGroupName string, serverName string, databaseName string, linkID string, cancel <-chan struct{}) (<-chan autorest.Response, <-chan error) {
|
|
resultChan := make(chan autorest.Response, 1)
|
|
errChan := make(chan error, 1)
|
|
go func() {
|
|
var err error
|
|
var result autorest.Response
|
|
defer func() {
|
|
if err != nil {
|
|
errChan <- err
|
|
}
|
|
resultChan <- result
|
|
close(resultChan)
|
|
close(errChan)
|
|
}()
|
|
req, err := client.FailoverAllowDataLossPreparer(resourceGroupName, serverName, databaseName, linkID, cancel)
|
|
if err != nil {
|
|
err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "FailoverAllowDataLoss", nil, "Failure preparing request")
|
|
return
|
|
}
|
|
|
|
resp, err := client.FailoverAllowDataLossSender(req)
|
|
if err != nil {
|
|
result.Response = resp
|
|
err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "FailoverAllowDataLoss", resp, "Failure sending request")
|
|
return
|
|
}
|
|
|
|
result, err = client.FailoverAllowDataLossResponder(resp)
|
|
if err != nil {
|
|
err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "FailoverAllowDataLoss", resp, "Failure responding to request")
|
|
}
|
|
}()
|
|
return resultChan, errChan
|
|
}
|
|
|
|
// FailoverAllowDataLossPreparer prepares the FailoverAllowDataLoss request.
|
|
func (client ReplicationLinksClient) FailoverAllowDataLossPreparer(resourceGroupName string, serverName string, databaseName string, linkID string, cancel <-chan struct{}) (*http.Request, error) {
|
|
pathParameters := map[string]interface{}{
|
|
"databaseName": autorest.Encode("path", databaseName),
|
|
"linkId": autorest.Encode("path", linkID),
|
|
"resourceGroupName": autorest.Encode("path", resourceGroupName),
|
|
"serverName": autorest.Encode("path", serverName),
|
|
"subscriptionId": autorest.Encode("path", client.SubscriptionID),
|
|
}
|
|
|
|
const APIVersion = "2014-04-01"
|
|
queryParameters := map[string]interface{}{
|
|
"api-version": APIVersion,
|
|
}
|
|
|
|
preparer := autorest.CreatePreparer(
|
|
autorest.AsPost(),
|
|
autorest.WithBaseURL(client.BaseURI),
|
|
autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/forceFailoverAllowDataLoss", pathParameters),
|
|
autorest.WithQueryParameters(queryParameters))
|
|
return preparer.Prepare(&http.Request{Cancel: cancel})
|
|
}
|
|
|
|
// FailoverAllowDataLossSender sends the FailoverAllowDataLoss request. The method will close the
|
|
// http.Response Body if it receives an error.
|
|
func (client ReplicationLinksClient) FailoverAllowDataLossSender(req *http.Request) (*http.Response, error) {
|
|
return autorest.SendWithSender(client,
|
|
req,
|
|
azure.DoPollForAsynchronous(client.PollingDelay))
|
|
}
|
|
|
|
// FailoverAllowDataLossResponder handles the response to the FailoverAllowDataLoss request. The method always
|
|
// closes the http.Response Body.
|
|
func (client ReplicationLinksClient) FailoverAllowDataLossResponder(resp *http.Response) (result autorest.Response, err error) {
|
|
err = autorest.Respond(
|
|
resp,
|
|
client.ByInspecting(),
|
|
azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent, http.StatusAccepted),
|
|
autorest.ByClosing())
|
|
result.Response = resp
|
|
return
|
|
}
|
|
|
|
// Get gets a database replication link.
|
|
//
|
|
// resourceGroupName is the name of the resource group that contains the resource. You can obtain this value from the
|
|
// Azure Resource Manager API or the portal. serverName is the name of the server. databaseName is the name of the
|
|
// database to get the link for. linkID is the replication link ID to be retrieved.
|
|
func (client ReplicationLinksClient) Get(resourceGroupName string, serverName string, databaseName string, linkID string) (result ReplicationLink, err error) {
|
|
req, err := client.GetPreparer(resourceGroupName, serverName, databaseName, linkID)
|
|
if err != nil {
|
|
err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Get", nil, "Failure preparing request")
|
|
return
|
|
}
|
|
|
|
resp, err := client.GetSender(req)
|
|
if err != nil {
|
|
result.Response = autorest.Response{Response: resp}
|
|
err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Get", resp, "Failure sending request")
|
|
return
|
|
}
|
|
|
|
result, err = client.GetResponder(resp)
|
|
if err != nil {
|
|
err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Get", resp, "Failure responding to request")
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// GetPreparer prepares the Get request.
|
|
func (client ReplicationLinksClient) GetPreparer(resourceGroupName string, serverName string, databaseName string, linkID string) (*http.Request, error) {
|
|
pathParameters := map[string]interface{}{
|
|
"databaseName": autorest.Encode("path", databaseName),
|
|
"linkId": autorest.Encode("path", linkID),
|
|
"resourceGroupName": autorest.Encode("path", resourceGroupName),
|
|
"serverName": autorest.Encode("path", serverName),
|
|
"subscriptionId": autorest.Encode("path", client.SubscriptionID),
|
|
}
|
|
|
|
const APIVersion = "2014-04-01"
|
|
queryParameters := map[string]interface{}{
|
|
"api-version": APIVersion,
|
|
}
|
|
|
|
preparer := autorest.CreatePreparer(
|
|
autorest.AsGet(),
|
|
autorest.WithBaseURL(client.BaseURI),
|
|
autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}", pathParameters),
|
|
autorest.WithQueryParameters(queryParameters))
|
|
return preparer.Prepare(&http.Request{})
|
|
}
|
|
|
|
// GetSender sends the Get request. The method will close the
|
|
// http.Response Body if it receives an error.
|
|
func (client ReplicationLinksClient) GetSender(req *http.Request) (*http.Response, error) {
|
|
return autorest.SendWithSender(client, req)
|
|
}
|
|
|
|
// GetResponder handles the response to the Get request. The method always
|
|
// closes the http.Response Body.
|
|
func (client ReplicationLinksClient) GetResponder(resp *http.Response) (result ReplicationLink, err error) {
|
|
err = autorest.Respond(
|
|
resp,
|
|
client.ByInspecting(),
|
|
azure.WithErrorUnlessStatusCode(http.StatusOK),
|
|
autorest.ByUnmarshallingJSON(&result),
|
|
autorest.ByClosing())
|
|
result.Response = autorest.Response{Response: resp}
|
|
return
|
|
}
|
|
|
|
// ListByDatabase lists a database's replication links.
|
|
//
|
|
// resourceGroupName is the name of the resource group that contains the resource. You can obtain this value from the
|
|
// Azure Resource Manager API or the portal. serverName is the name of the server. databaseName is the name of the
|
|
// database to retrieve links for.
|
|
func (client ReplicationLinksClient) ListByDatabase(resourceGroupName string, serverName string, databaseName string) (result ReplicationLinkListResult, err error) {
|
|
req, err := client.ListByDatabasePreparer(resourceGroupName, serverName, databaseName)
|
|
if err != nil {
|
|
err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "ListByDatabase", nil, "Failure preparing request")
|
|
return
|
|
}
|
|
|
|
resp, err := client.ListByDatabaseSender(req)
|
|
if err != nil {
|
|
result.Response = autorest.Response{Response: resp}
|
|
err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "ListByDatabase", resp, "Failure sending request")
|
|
return
|
|
}
|
|
|
|
result, err = client.ListByDatabaseResponder(resp)
|
|
if err != nil {
|
|
err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "ListByDatabase", resp, "Failure responding to request")
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// ListByDatabasePreparer prepares the ListByDatabase request.
|
|
func (client ReplicationLinksClient) ListByDatabasePreparer(resourceGroupName string, serverName string, databaseName string) (*http.Request, error) {
|
|
pathParameters := map[string]interface{}{
|
|
"databaseName": autorest.Encode("path", databaseName),
|
|
"resourceGroupName": autorest.Encode("path", resourceGroupName),
|
|
"serverName": autorest.Encode("path", serverName),
|
|
"subscriptionId": autorest.Encode("path", client.SubscriptionID),
|
|
}
|
|
|
|
const APIVersion = "2014-04-01"
|
|
queryParameters := map[string]interface{}{
|
|
"api-version": APIVersion,
|
|
}
|
|
|
|
preparer := autorest.CreatePreparer(
|
|
autorest.AsGet(),
|
|
autorest.WithBaseURL(client.BaseURI),
|
|
autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks", pathParameters),
|
|
autorest.WithQueryParameters(queryParameters))
|
|
return preparer.Prepare(&http.Request{})
|
|
}
|
|
|
|
// ListByDatabaseSender sends the ListByDatabase request. The method will close the
|
|
// http.Response Body if it receives an error.
|
|
func (client ReplicationLinksClient) ListByDatabaseSender(req *http.Request) (*http.Response, error) {
|
|
return autorest.SendWithSender(client, req)
|
|
}
|
|
|
|
// ListByDatabaseResponder handles the response to the ListByDatabase request. The method always
|
|
// closes the http.Response Body.
|
|
func (client ReplicationLinksClient) ListByDatabaseResponder(resp *http.Response) (result ReplicationLinkListResult, err error) {
|
|
err = autorest.Respond(
|
|
resp,
|
|
client.ByInspecting(),
|
|
azure.WithErrorUnlessStatusCode(http.StatusOK),
|
|
autorest.ByUnmarshallingJSON(&result),
|
|
autorest.ByClosing())
|
|
result.Response = autorest.Response{Response: resp}
|
|
return
|
|
}
|