...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-08-10/siterecovery/replicationalertsettings.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-08-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/tracing"
    14  	"net/http"
    15  )
    16  
    17  // ReplicationAlertSettingsClient is the client for the ReplicationAlertSettings methods of the Siterecovery service.
    18  type ReplicationAlertSettingsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewReplicationAlertSettingsClient creates an instance of the ReplicationAlertSettingsClient client.
    23  func NewReplicationAlertSettingsClient(subscriptionID string, resourceGroupName string, resourceName string) ReplicationAlertSettingsClient {
    24  	return NewReplicationAlertSettingsClientWithBaseURI(DefaultBaseURI, subscriptionID, resourceGroupName, resourceName)
    25  }
    26  
    27  // NewReplicationAlertSettingsClientWithBaseURI creates an instance of the ReplicationAlertSettingsClient client using
    28  // a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
    29  // clouds, Azure stack).
    30  func NewReplicationAlertSettingsClientWithBaseURI(baseURI string, subscriptionID string, resourceGroupName string, resourceName string) ReplicationAlertSettingsClient {
    31  	return ReplicationAlertSettingsClient{NewWithBaseURI(baseURI, subscriptionID, resourceGroupName, resourceName)}
    32  }
    33  
    34  // Create create or update an email notification(alert) configuration.
    35  // Parameters:
    36  // alertSettingName - the name of the email notification(alert) configuration.
    37  // request - the input to configure the email notification(alert).
    38  func (client ReplicationAlertSettingsClient) Create(ctx context.Context, alertSettingName string, request ConfigureAlertRequest) (result Alert, err error) {
    39  	if tracing.IsEnabled() {
    40  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationAlertSettingsClient.Create")
    41  		defer func() {
    42  			sc := -1
    43  			if result.Response.Response != nil {
    44  				sc = result.Response.Response.StatusCode
    45  			}
    46  			tracing.EndSpan(ctx, sc, err)
    47  		}()
    48  	}
    49  	req, err := client.CreatePreparer(ctx, alertSettingName, request)
    50  	if err != nil {
    51  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationAlertSettingsClient", "Create", nil, "Failure preparing request")
    52  		return
    53  	}
    54  
    55  	resp, err := client.CreateSender(req)
    56  	if err != nil {
    57  		result.Response = autorest.Response{Response: resp}
    58  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationAlertSettingsClient", "Create", resp, "Failure sending request")
    59  		return
    60  	}
    61  
    62  	result, err = client.CreateResponder(resp)
    63  	if err != nil {
    64  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationAlertSettingsClient", "Create", resp, "Failure responding to request")
    65  		return
    66  	}
    67  
    68  	return
    69  }
    70  
    71  // CreatePreparer prepares the Create request.
    72  func (client ReplicationAlertSettingsClient) CreatePreparer(ctx context.Context, alertSettingName string, request ConfigureAlertRequest) (*http.Request, error) {
    73  	pathParameters := map[string]interface{}{
    74  		"alertSettingName":  autorest.Encode("path", alertSettingName),
    75  		"resourceGroupName": autorest.Encode("path", client.ResourceGroupName),
    76  		"resourceName":      autorest.Encode("path", client.ResourceName),
    77  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    78  	}
    79  
    80  	const APIVersion = "2016-08-10"
    81  	queryParameters := map[string]interface{}{
    82  		"api-version": APIVersion,
    83  	}
    84  
    85  	preparer := autorest.CreatePreparer(
    86  		autorest.AsContentType("application/json; charset=utf-8"),
    87  		autorest.AsPut(),
    88  		autorest.WithBaseURL(client.BaseURI),
    89  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationAlertSettings/{alertSettingName}", pathParameters),
    90  		autorest.WithJSON(request),
    91  		autorest.WithQueryParameters(queryParameters))
    92  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    93  }
    94  
    95  // CreateSender sends the Create request. The method will close the
    96  // http.Response Body if it receives an error.
    97  func (client ReplicationAlertSettingsClient) CreateSender(req *http.Request) (*http.Response, error) {
    98  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
    99  }
   100  
   101  // CreateResponder handles the response to the Create request. The method always
   102  // closes the http.Response Body.
   103  func (client ReplicationAlertSettingsClient) CreateResponder(resp *http.Response) (result Alert, err error) {
   104  	err = autorest.Respond(
   105  		resp,
   106  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   107  		autorest.ByUnmarshallingJSON(&result),
   108  		autorest.ByClosing())
   109  	result.Response = autorest.Response{Response: resp}
   110  	return
   111  }
   112  
   113  // Get gets the details of the specified email notification(alert) configuration.
   114  // Parameters:
   115  // alertSettingName - the name of the email notification configuration.
   116  func (client ReplicationAlertSettingsClient) Get(ctx context.Context, alertSettingName string) (result Alert, err error) {
   117  	if tracing.IsEnabled() {
   118  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationAlertSettingsClient.Get")
   119  		defer func() {
   120  			sc := -1
   121  			if result.Response.Response != nil {
   122  				sc = result.Response.Response.StatusCode
   123  			}
   124  			tracing.EndSpan(ctx, sc, err)
   125  		}()
   126  	}
   127  	req, err := client.GetPreparer(ctx, alertSettingName)
   128  	if err != nil {
   129  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationAlertSettingsClient", "Get", nil, "Failure preparing request")
   130  		return
   131  	}
   132  
   133  	resp, err := client.GetSender(req)
   134  	if err != nil {
   135  		result.Response = autorest.Response{Response: resp}
   136  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationAlertSettingsClient", "Get", resp, "Failure sending request")
   137  		return
   138  	}
   139  
   140  	result, err = client.GetResponder(resp)
   141  	if err != nil {
   142  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationAlertSettingsClient", "Get", resp, "Failure responding to request")
   143  		return
   144  	}
   145  
   146  	return
   147  }
   148  
   149  // GetPreparer prepares the Get request.
   150  func (client ReplicationAlertSettingsClient) GetPreparer(ctx context.Context, alertSettingName string) (*http.Request, error) {
   151  	pathParameters := map[string]interface{}{
   152  		"alertSettingName":  autorest.Encode("path", alertSettingName),
   153  		"resourceGroupName": autorest.Encode("path", client.ResourceGroupName),
   154  		"resourceName":      autorest.Encode("path", client.ResourceName),
   155  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   156  	}
   157  
   158  	const APIVersion = "2016-08-10"
   159  	queryParameters := map[string]interface{}{
   160  		"api-version": APIVersion,
   161  	}
   162  
   163  	preparer := autorest.CreatePreparer(
   164  		autorest.AsGet(),
   165  		autorest.WithBaseURL(client.BaseURI),
   166  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationAlertSettings/{alertSettingName}", pathParameters),
   167  		autorest.WithQueryParameters(queryParameters))
   168  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   169  }
   170  
   171  // GetSender sends the Get request. The method will close the
   172  // http.Response Body if it receives an error.
   173  func (client ReplicationAlertSettingsClient) GetSender(req *http.Request) (*http.Response, error) {
   174  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   175  }
   176  
   177  // GetResponder handles the response to the Get request. The method always
   178  // closes the http.Response Body.
   179  func (client ReplicationAlertSettingsClient) GetResponder(resp *http.Response) (result Alert, err error) {
   180  	err = autorest.Respond(
   181  		resp,
   182  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   183  		autorest.ByUnmarshallingJSON(&result),
   184  		autorest.ByClosing())
   185  	result.Response = autorest.Response{Response: resp}
   186  	return
   187  }
   188  
   189  // List gets the list of email notification(alert) configurations for the vault.
   190  func (client ReplicationAlertSettingsClient) List(ctx context.Context) (result AlertCollectionPage, err error) {
   191  	if tracing.IsEnabled() {
   192  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationAlertSettingsClient.List")
   193  		defer func() {
   194  			sc := -1
   195  			if result.ac.Response.Response != nil {
   196  				sc = result.ac.Response.Response.StatusCode
   197  			}
   198  			tracing.EndSpan(ctx, sc, err)
   199  		}()
   200  	}
   201  	result.fn = client.listNextResults
   202  	req, err := client.ListPreparer(ctx)
   203  	if err != nil {
   204  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationAlertSettingsClient", "List", nil, "Failure preparing request")
   205  		return
   206  	}
   207  
   208  	resp, err := client.ListSender(req)
   209  	if err != nil {
   210  		result.ac.Response = autorest.Response{Response: resp}
   211  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationAlertSettingsClient", "List", resp, "Failure sending request")
   212  		return
   213  	}
   214  
   215  	result.ac, err = client.ListResponder(resp)
   216  	if err != nil {
   217  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationAlertSettingsClient", "List", resp, "Failure responding to request")
   218  		return
   219  	}
   220  	if result.ac.hasNextLink() && result.ac.IsEmpty() {
   221  		err = result.NextWithContext(ctx)
   222  		return
   223  	}
   224  
   225  	return
   226  }
   227  
   228  // ListPreparer prepares the List request.
   229  func (client ReplicationAlertSettingsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
   230  	pathParameters := map[string]interface{}{
   231  		"resourceGroupName": autorest.Encode("path", client.ResourceGroupName),
   232  		"resourceName":      autorest.Encode("path", client.ResourceName),
   233  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   234  	}
   235  
   236  	const APIVersion = "2016-08-10"
   237  	queryParameters := map[string]interface{}{
   238  		"api-version": APIVersion,
   239  	}
   240  
   241  	preparer := autorest.CreatePreparer(
   242  		autorest.AsGet(),
   243  		autorest.WithBaseURL(client.BaseURI),
   244  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationAlertSettings", pathParameters),
   245  		autorest.WithQueryParameters(queryParameters))
   246  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   247  }
   248  
   249  // ListSender sends the List request. The method will close the
   250  // http.Response Body if it receives an error.
   251  func (client ReplicationAlertSettingsClient) ListSender(req *http.Request) (*http.Response, error) {
   252  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   253  }
   254  
   255  // ListResponder handles the response to the List request. The method always
   256  // closes the http.Response Body.
   257  func (client ReplicationAlertSettingsClient) ListResponder(resp *http.Response) (result AlertCollection, err error) {
   258  	err = autorest.Respond(
   259  		resp,
   260  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   261  		autorest.ByUnmarshallingJSON(&result),
   262  		autorest.ByClosing())
   263  	result.Response = autorest.Response{Response: resp}
   264  	return
   265  }
   266  
   267  // listNextResults retrieves the next set of results, if any.
   268  func (client ReplicationAlertSettingsClient) listNextResults(ctx context.Context, lastResults AlertCollection) (result AlertCollection, err error) {
   269  	req, err := lastResults.alertCollectionPreparer(ctx)
   270  	if err != nil {
   271  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationAlertSettingsClient", "listNextResults", nil, "Failure preparing next results request")
   272  	}
   273  	if req == nil {
   274  		return
   275  	}
   276  	resp, err := client.ListSender(req)
   277  	if err != nil {
   278  		result.Response = autorest.Response{Response: resp}
   279  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationAlertSettingsClient", "listNextResults", resp, "Failure sending next results request")
   280  	}
   281  	result, err = client.ListResponder(resp)
   282  	if err != nil {
   283  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationAlertSettingsClient", "listNextResults", resp, "Failure responding to next results request")
   284  	}
   285  	return
   286  }
   287  
   288  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   289  func (client ReplicationAlertSettingsClient) ListComplete(ctx context.Context) (result AlertCollectionIterator, err error) {
   290  	if tracing.IsEnabled() {
   291  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationAlertSettingsClient.List")
   292  		defer func() {
   293  			sc := -1
   294  			if result.Response().Response.Response != nil {
   295  				sc = result.page.Response().Response.Response.StatusCode
   296  			}
   297  			tracing.EndSpan(ctx, sc, err)
   298  		}()
   299  	}
   300  	result.page, err = client.List(ctx)
   301  	return
   302  }
   303  

View as plain text