...

Source file src/github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2021-03-31/devices/iothub.go

Documentation: github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2021-03-31/devices

     1  package devices
     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  // IotHubClient is the use this API to manage the IoT hubs in your Azure subscription.
    19  type IotHubClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewIotHubClient creates an instance of the IotHubClient client.
    24  func NewIotHubClient(subscriptionID string) IotHubClient {
    25  	return NewIotHubClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewIotHubClientWithBaseURI creates an instance of the IotHubClient client using a custom endpoint.  Use this when
    29  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewIotHubClientWithBaseURI(baseURI string, subscriptionID string) IotHubClient {
    31  	return IotHubClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // ManualFailover manually initiate a failover for the IoT Hub to its secondary region. To learn more, see
    35  // https://aka.ms/manualfailover
    36  // Parameters:
    37  // iotHubName - name of the IoT hub to failover
    38  // failoverInput - region to failover to. Must be the Azure paired region. Get the value from the secondary
    39  // location in the locations property. To learn more, see https://aka.ms/manualfailover/region
    40  // resourceGroupName - name of the resource group containing the IoT hub resource
    41  func (client IotHubClient) ManualFailover(ctx context.Context, iotHubName string, failoverInput FailoverInput, resourceGroupName string) (result IotHubManualFailoverFuture, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/IotHubClient.ManualFailover")
    44  		defer func() {
    45  			sc := -1
    46  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    47  				sc = result.FutureAPI.Response().StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	if err := validation.Validate([]validation.Validation{
    53  		{TargetValue: failoverInput,
    54  			Constraints: []validation.Constraint{{Target: "failoverInput.FailoverRegion", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
    55  		return result, validation.NewError("devices.IotHubClient", "ManualFailover", err.Error())
    56  	}
    57  
    58  	req, err := client.ManualFailoverPreparer(ctx, iotHubName, failoverInput, resourceGroupName)
    59  	if err != nil {
    60  		err = autorest.NewErrorWithError(err, "devices.IotHubClient", "ManualFailover", nil, "Failure preparing request")
    61  		return
    62  	}
    63  
    64  	result, err = client.ManualFailoverSender(req)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "devices.IotHubClient", "ManualFailover", result.Response(), "Failure sending request")
    67  		return
    68  	}
    69  
    70  	return
    71  }
    72  
    73  // ManualFailoverPreparer prepares the ManualFailover request.
    74  func (client IotHubClient) ManualFailoverPreparer(ctx context.Context, iotHubName string, failoverInput FailoverInput, resourceGroupName string) (*http.Request, error) {
    75  	pathParameters := map[string]interface{}{
    76  		"iotHubName":        autorest.Encode("path", iotHubName),
    77  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    78  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    79  	}
    80  
    81  	const APIVersion = "2021-03-31"
    82  	queryParameters := map[string]interface{}{
    83  		"api-version": APIVersion,
    84  	}
    85  
    86  	preparer := autorest.CreatePreparer(
    87  		autorest.AsContentType("application/json; charset=utf-8"),
    88  		autorest.AsPost(),
    89  		autorest.WithBaseURL(client.BaseURI),
    90  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{iotHubName}/failover", pathParameters),
    91  		autorest.WithJSON(failoverInput),
    92  		autorest.WithQueryParameters(queryParameters))
    93  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    94  }
    95  
    96  // ManualFailoverSender sends the ManualFailover request. The method will close the
    97  // http.Response Body if it receives an error.
    98  func (client IotHubClient) ManualFailoverSender(req *http.Request) (future IotHubManualFailoverFuture, err error) {
    99  	var resp *http.Response
   100  	future.FutureAPI = &azure.Future{}
   101  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   102  	if err != nil {
   103  		return
   104  	}
   105  	var azf azure.Future
   106  	azf, err = azure.NewFutureFromResponse(resp)
   107  	future.FutureAPI = &azf
   108  	future.Result = future.result
   109  	return
   110  }
   111  
   112  // ManualFailoverResponder handles the response to the ManualFailover request. The method always
   113  // closes the http.Response Body.
   114  func (client IotHubClient) ManualFailoverResponder(resp *http.Response) (result autorest.Response, err error) {
   115  	err = autorest.Respond(
   116  		resp,
   117  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   118  		autorest.ByClosing())
   119  	result.Response = resp
   120  	return
   121  }
   122  

View as plain text