...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2019-07-01-preview/devices/iothub.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2019-07-01-preview/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 perform manual fail over of given hub
    35  // Parameters:
    36  // iotHubName - iotHub to fail over
    37  // failoverInput - region to failover to. Must be a azure DR pair
    38  // resourceGroupName - resource group which Iot Hub belongs to
    39  func (client IotHubClient) ManualFailover(ctx context.Context, iotHubName string, failoverInput FailoverInput, resourceGroupName string) (result IotHubManualFailoverFuture, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/IotHubClient.ManualFailover")
    42  		defer func() {
    43  			sc := -1
    44  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    45  				sc = result.FutureAPI.Response().StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	if err := validation.Validate([]validation.Validation{
    51  		{TargetValue: failoverInput,
    52  			Constraints: []validation.Constraint{{Target: "failoverInput.FailoverRegion", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
    53  		return result, validation.NewError("devices.IotHubClient", "ManualFailover", err.Error())
    54  	}
    55  
    56  	req, err := client.ManualFailoverPreparer(ctx, iotHubName, failoverInput, resourceGroupName)
    57  	if err != nil {
    58  		err = autorest.NewErrorWithError(err, "devices.IotHubClient", "ManualFailover", nil, "Failure preparing request")
    59  		return
    60  	}
    61  
    62  	result, err = client.ManualFailoverSender(req)
    63  	if err != nil {
    64  		err = autorest.NewErrorWithError(err, "devices.IotHubClient", "ManualFailover", result.Response(), "Failure sending request")
    65  		return
    66  	}
    67  
    68  	return
    69  }
    70  
    71  // ManualFailoverPreparer prepares the ManualFailover request.
    72  func (client IotHubClient) ManualFailoverPreparer(ctx context.Context, iotHubName string, failoverInput FailoverInput, resourceGroupName string) (*http.Request, error) {
    73  	pathParameters := map[string]interface{}{
    74  		"iotHubName":        autorest.Encode("path", iotHubName),
    75  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    76  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    77  	}
    78  
    79  	const APIVersion = "2019-07-01-preview"
    80  	queryParameters := map[string]interface{}{
    81  		"api-version": APIVersion,
    82  	}
    83  
    84  	preparer := autorest.CreatePreparer(
    85  		autorest.AsContentType("application/json; charset=utf-8"),
    86  		autorest.AsPost(),
    87  		autorest.WithBaseURL(client.BaseURI),
    88  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{iotHubName}/failover", pathParameters),
    89  		autorest.WithJSON(failoverInput),
    90  		autorest.WithQueryParameters(queryParameters))
    91  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    92  }
    93  
    94  // ManualFailoverSender sends the ManualFailover request. The method will close the
    95  // http.Response Body if it receives an error.
    96  func (client IotHubClient) ManualFailoverSender(req *http.Request) (future IotHubManualFailoverFuture, err error) {
    97  	var resp *http.Response
    98  	future.FutureAPI = &azure.Future{}
    99  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   100  	if err != nil {
   101  		return
   102  	}
   103  	var azf azure.Future
   104  	azf, err = azure.NewFutureFromResponse(resp)
   105  	future.FutureAPI = &azf
   106  	future.Result = future.result
   107  	return
   108  }
   109  
   110  // ManualFailoverResponder handles the response to the ManualFailover request. The method always
   111  // closes the http.Response Body.
   112  func (client IotHubClient) ManualFailoverResponder(resp *http.Response) (result autorest.Response, err error) {
   113  	err = autorest.Respond(
   114  		resp,
   115  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   116  		autorest.ByClosing())
   117  	result.Response = resp
   118  	return
   119  }
   120  

View as plain text