...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2018-07-10/siterecovery/replicationvaultsetting.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2018-07-10/siterecovery

     1  package siterecovery
     2  
     3  // Copyright (c) Microsoft Corporation. All rights reserved.
     4  // Licensed under the MIT License. See License.txt in the project root for license information.
     5  //
     6  // Code generated by Microsoft (R) AutoRest Code Generator.
     7  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
     8  
     9  import (
    10  	"context"
    11  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // ReplicationVaultSettingClient is the client for the ReplicationVaultSetting methods of the Siterecovery service.
    19  type ReplicationVaultSettingClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewReplicationVaultSettingClient creates an instance of the ReplicationVaultSettingClient client.
    24  func NewReplicationVaultSettingClient(subscriptionID string, resourceGroupName string, resourceName string) ReplicationVaultSettingClient {
    25  	return NewReplicationVaultSettingClientWithBaseURI(DefaultBaseURI, subscriptionID, resourceGroupName, resourceName)
    26  }
    27  
    28  // NewReplicationVaultSettingClientWithBaseURI creates an instance of the ReplicationVaultSettingClient client using a
    29  // custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
    30  // Azure stack).
    31  func NewReplicationVaultSettingClientWithBaseURI(baseURI string, subscriptionID string, resourceGroupName string, resourceName string) ReplicationVaultSettingClient {
    32  	return ReplicationVaultSettingClient{NewWithBaseURI(baseURI, subscriptionID, resourceGroupName, resourceName)}
    33  }
    34  
    35  // Create the operation to configure vault setting.
    36  // Parameters:
    37  // vaultSettingName - vault setting name.
    38  // input - vault setting creation input.
    39  func (client ReplicationVaultSettingClient) Create(ctx context.Context, vaultSettingName string, input VaultSettingCreationInput) (result VaultSetting, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationVaultSettingClient.Create")
    42  		defer func() {
    43  			sc := -1
    44  			if result.Response.Response != nil {
    45  				sc = result.Response.Response.StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	if err := validation.Validate([]validation.Validation{
    51  		{TargetValue: input,
    52  			Constraints: []validation.Constraint{{Target: "input.Properties", Name: validation.Null, Rule: true,
    53  				Chain: []validation.Constraint{{Target: "input.Properties.MigrationSolutionID", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
    54  		return result, validation.NewError("siterecovery.ReplicationVaultSettingClient", "Create", err.Error())
    55  	}
    56  
    57  	req, err := client.CreatePreparer(ctx, vaultSettingName, input)
    58  	if err != nil {
    59  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationVaultSettingClient", "Create", nil, "Failure preparing request")
    60  		return
    61  	}
    62  
    63  	resp, err := client.CreateSender(req)
    64  	if err != nil {
    65  		result.Response = autorest.Response{Response: resp}
    66  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationVaultSettingClient", "Create", resp, "Failure sending request")
    67  		return
    68  	}
    69  
    70  	result, err = client.CreateResponder(resp)
    71  	if err != nil {
    72  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationVaultSettingClient", "Create", resp, "Failure responding to request")
    73  		return
    74  	}
    75  
    76  	return
    77  }
    78  
    79  // CreatePreparer prepares the Create request.
    80  func (client ReplicationVaultSettingClient) CreatePreparer(ctx context.Context, vaultSettingName string, input VaultSettingCreationInput) (*http.Request, error) {
    81  	pathParameters := map[string]interface{}{
    82  		"resourceGroupName": autorest.Encode("path", client.ResourceGroupName),
    83  		"resourceName":      autorest.Encode("path", client.ResourceName),
    84  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    85  		"vaultSettingName":  autorest.Encode("path", vaultSettingName),
    86  	}
    87  
    88  	const APIVersion = "2018-07-10"
    89  	queryParameters := map[string]interface{}{
    90  		"api-version": APIVersion,
    91  	}
    92  
    93  	preparer := autorest.CreatePreparer(
    94  		autorest.AsContentType("application/json; charset=utf-8"),
    95  		autorest.AsPut(),
    96  		autorest.WithBaseURL(client.BaseURI),
    97  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationVaultSettings/{vaultSettingName}", pathParameters),
    98  		autorest.WithJSON(input),
    99  		autorest.WithQueryParameters(queryParameters))
   100  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   101  }
   102  
   103  // CreateSender sends the Create request. The method will close the
   104  // http.Response Body if it receives an error.
   105  func (client ReplicationVaultSettingClient) CreateSender(req *http.Request) (*http.Response, error) {
   106  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   107  }
   108  
   109  // CreateResponder handles the response to the Create request. The method always
   110  // closes the http.Response Body.
   111  func (client ReplicationVaultSettingClient) CreateResponder(resp *http.Response) (result VaultSetting, err error) {
   112  	err = autorest.Respond(
   113  		resp,
   114  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   115  		autorest.ByUnmarshallingJSON(&result),
   116  		autorest.ByClosing())
   117  	result.Response = autorest.Response{Response: resp}
   118  	return
   119  }
   120  
   121  // Get gets the vault setting. This includes the Migration Hub connection settings.
   122  // Parameters:
   123  // vaultSettingName - vault setting name.
   124  func (client ReplicationVaultSettingClient) Get(ctx context.Context, vaultSettingName string) (result VaultSetting, err error) {
   125  	if tracing.IsEnabled() {
   126  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationVaultSettingClient.Get")
   127  		defer func() {
   128  			sc := -1
   129  			if result.Response.Response != nil {
   130  				sc = result.Response.Response.StatusCode
   131  			}
   132  			tracing.EndSpan(ctx, sc, err)
   133  		}()
   134  	}
   135  	req, err := client.GetPreparer(ctx, vaultSettingName)
   136  	if err != nil {
   137  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationVaultSettingClient", "Get", nil, "Failure preparing request")
   138  		return
   139  	}
   140  
   141  	resp, err := client.GetSender(req)
   142  	if err != nil {
   143  		result.Response = autorest.Response{Response: resp}
   144  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationVaultSettingClient", "Get", resp, "Failure sending request")
   145  		return
   146  	}
   147  
   148  	result, err = client.GetResponder(resp)
   149  	if err != nil {
   150  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationVaultSettingClient", "Get", resp, "Failure responding to request")
   151  		return
   152  	}
   153  
   154  	return
   155  }
   156  
   157  // GetPreparer prepares the Get request.
   158  func (client ReplicationVaultSettingClient) GetPreparer(ctx context.Context, vaultSettingName string) (*http.Request, error) {
   159  	pathParameters := map[string]interface{}{
   160  		"resourceGroupName": autorest.Encode("path", client.ResourceGroupName),
   161  		"resourceName":      autorest.Encode("path", client.ResourceName),
   162  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   163  		"vaultSettingName":  autorest.Encode("path", vaultSettingName),
   164  	}
   165  
   166  	const APIVersion = "2018-07-10"
   167  	queryParameters := map[string]interface{}{
   168  		"api-version": APIVersion,
   169  	}
   170  
   171  	preparer := autorest.CreatePreparer(
   172  		autorest.AsGet(),
   173  		autorest.WithBaseURL(client.BaseURI),
   174  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationVaultSettings/{vaultSettingName}", pathParameters),
   175  		autorest.WithQueryParameters(queryParameters))
   176  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   177  }
   178  
   179  // GetSender sends the Get request. The method will close the
   180  // http.Response Body if it receives an error.
   181  func (client ReplicationVaultSettingClient) GetSender(req *http.Request) (*http.Response, error) {
   182  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   183  }
   184  
   185  // GetResponder handles the response to the Get request. The method always
   186  // closes the http.Response Body.
   187  func (client ReplicationVaultSettingClient) GetResponder(resp *http.Response) (result VaultSetting, err error) {
   188  	err = autorest.Respond(
   189  		resp,
   190  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   191  		autorest.ByUnmarshallingJSON(&result),
   192  		autorest.ByClosing())
   193  	result.Response = autorest.Response{Response: resp}
   194  	return
   195  }
   196  
   197  // List gets the list of vault setting. This includes the Migration Hub connection settings.
   198  func (client ReplicationVaultSettingClient) List(ctx context.Context) (result VaultSettingCollectionPage, err error) {
   199  	if tracing.IsEnabled() {
   200  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationVaultSettingClient.List")
   201  		defer func() {
   202  			sc := -1
   203  			if result.vsc.Response.Response != nil {
   204  				sc = result.vsc.Response.Response.StatusCode
   205  			}
   206  			tracing.EndSpan(ctx, sc, err)
   207  		}()
   208  	}
   209  	result.fn = client.listNextResults
   210  	req, err := client.ListPreparer(ctx)
   211  	if err != nil {
   212  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationVaultSettingClient", "List", nil, "Failure preparing request")
   213  		return
   214  	}
   215  
   216  	resp, err := client.ListSender(req)
   217  	if err != nil {
   218  		result.vsc.Response = autorest.Response{Response: resp}
   219  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationVaultSettingClient", "List", resp, "Failure sending request")
   220  		return
   221  	}
   222  
   223  	result.vsc, err = client.ListResponder(resp)
   224  	if err != nil {
   225  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationVaultSettingClient", "List", resp, "Failure responding to request")
   226  		return
   227  	}
   228  	if result.vsc.hasNextLink() && result.vsc.IsEmpty() {
   229  		err = result.NextWithContext(ctx)
   230  		return
   231  	}
   232  
   233  	return
   234  }
   235  
   236  // ListPreparer prepares the List request.
   237  func (client ReplicationVaultSettingClient) ListPreparer(ctx context.Context) (*http.Request, error) {
   238  	pathParameters := map[string]interface{}{
   239  		"resourceGroupName": autorest.Encode("path", client.ResourceGroupName),
   240  		"resourceName":      autorest.Encode("path", client.ResourceName),
   241  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   242  	}
   243  
   244  	const APIVersion = "2018-07-10"
   245  	queryParameters := map[string]interface{}{
   246  		"api-version": APIVersion,
   247  	}
   248  
   249  	preparer := autorest.CreatePreparer(
   250  		autorest.AsGet(),
   251  		autorest.WithBaseURL(client.BaseURI),
   252  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationVaultSettings", pathParameters),
   253  		autorest.WithQueryParameters(queryParameters))
   254  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   255  }
   256  
   257  // ListSender sends the List request. The method will close the
   258  // http.Response Body if it receives an error.
   259  func (client ReplicationVaultSettingClient) ListSender(req *http.Request) (*http.Response, error) {
   260  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   261  }
   262  
   263  // ListResponder handles the response to the List request. The method always
   264  // closes the http.Response Body.
   265  func (client ReplicationVaultSettingClient) ListResponder(resp *http.Response) (result VaultSettingCollection, err error) {
   266  	err = autorest.Respond(
   267  		resp,
   268  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   269  		autorest.ByUnmarshallingJSON(&result),
   270  		autorest.ByClosing())
   271  	result.Response = autorest.Response{Response: resp}
   272  	return
   273  }
   274  
   275  // listNextResults retrieves the next set of results, if any.
   276  func (client ReplicationVaultSettingClient) listNextResults(ctx context.Context, lastResults VaultSettingCollection) (result VaultSettingCollection, err error) {
   277  	req, err := lastResults.vaultSettingCollectionPreparer(ctx)
   278  	if err != nil {
   279  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationVaultSettingClient", "listNextResults", nil, "Failure preparing next results request")
   280  	}
   281  	if req == nil {
   282  		return
   283  	}
   284  	resp, err := client.ListSender(req)
   285  	if err != nil {
   286  		result.Response = autorest.Response{Response: resp}
   287  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationVaultSettingClient", "listNextResults", resp, "Failure sending next results request")
   288  	}
   289  	result, err = client.ListResponder(resp)
   290  	if err != nil {
   291  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationVaultSettingClient", "listNextResults", resp, "Failure responding to next results request")
   292  	}
   293  	return
   294  }
   295  
   296  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   297  func (client ReplicationVaultSettingClient) ListComplete(ctx context.Context) (result VaultSettingCollectionIterator, err error) {
   298  	if tracing.IsEnabled() {
   299  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationVaultSettingClient.List")
   300  		defer func() {
   301  			sc := -1
   302  			if result.Response().Response.Response != nil {
   303  				sc = result.page.Response().Response.Response.StatusCode
   304  			}
   305  			tracing.EndSpan(ctx, sc, err)
   306  		}()
   307  	}
   308  	result.page, err = client.List(ctx)
   309  	return
   310  }
   311  

View as plain text