1package siterecovery 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/tracing" 25 "net/http" 26) 27 28// ReplicationProtectableItemsClient is the client for the ReplicationProtectableItems methods of the Siterecovery 29// service. 30type ReplicationProtectableItemsClient struct { 31 BaseClient 32} 33 34// NewReplicationProtectableItemsClient creates an instance of the ReplicationProtectableItemsClient client. 35func NewReplicationProtectableItemsClient(subscriptionID string, resourceGroupName string, resourceName string) ReplicationProtectableItemsClient { 36 return NewReplicationProtectableItemsClientWithBaseURI(DefaultBaseURI, subscriptionID, resourceGroupName, resourceName) 37} 38 39// NewReplicationProtectableItemsClientWithBaseURI creates an instance of the ReplicationProtectableItemsClient client 40// using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 41// clouds, Azure stack). 42func NewReplicationProtectableItemsClientWithBaseURI(baseURI string, subscriptionID string, resourceGroupName string, resourceName string) ReplicationProtectableItemsClient { 43 return ReplicationProtectableItemsClient{NewWithBaseURI(baseURI, subscriptionID, resourceGroupName, resourceName)} 44} 45 46// Get the operation to get the details of a protectable item. 47// Parameters: 48// fabricName - fabric name. 49// protectionContainerName - protection container name. 50// protectableItemName - protectable item name. 51func (client ReplicationProtectableItemsClient) Get(ctx context.Context, fabricName string, protectionContainerName string, protectableItemName string) (result ProtectableItem, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectableItemsClient.Get") 54 defer func() { 55 sc := -1 56 if result.Response.Response != nil { 57 sc = result.Response.Response.StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 req, err := client.GetPreparer(ctx, fabricName, protectionContainerName, protectableItemName) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "Get", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.GetSender(req) 69 if err != nil { 70 result.Response = autorest.Response{Response: resp} 71 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "Get", resp, "Failure sending request") 72 return 73 } 74 75 result, err = client.GetResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "Get", resp, "Failure responding to request") 78 return 79 } 80 81 return 82} 83 84// GetPreparer prepares the Get request. 85func (client ReplicationProtectableItemsClient) GetPreparer(ctx context.Context, fabricName string, protectionContainerName string, protectableItemName string) (*http.Request, error) { 86 pathParameters := map[string]interface{}{ 87 "fabricName": autorest.Encode("path", fabricName), 88 "protectableItemName": autorest.Encode("path", protectableItemName), 89 "protectionContainerName": autorest.Encode("path", protectionContainerName), 90 "resourceGroupName": autorest.Encode("path", client.ResourceGroupName), 91 "resourceName": autorest.Encode("path", client.ResourceName), 92 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 93 } 94 95 const APIVersion = "2016-08-10" 96 queryParameters := map[string]interface{}{ 97 "api-version": APIVersion, 98 } 99 100 preparer := autorest.CreatePreparer( 101 autorest.AsGet(), 102 autorest.WithBaseURL(client.BaseURI), 103 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectableItems/{protectableItemName}", pathParameters), 104 autorest.WithQueryParameters(queryParameters)) 105 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 106} 107 108// GetSender sends the Get request. The method will close the 109// http.Response Body if it receives an error. 110func (client ReplicationProtectableItemsClient) GetSender(req *http.Request) (*http.Response, error) { 111 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 112} 113 114// GetResponder handles the response to the Get request. The method always 115// closes the http.Response Body. 116func (client ReplicationProtectableItemsClient) GetResponder(resp *http.Response) (result ProtectableItem, err error) { 117 err = autorest.Respond( 118 resp, 119 azure.WithErrorUnlessStatusCode(http.StatusOK), 120 autorest.ByUnmarshallingJSON(&result), 121 autorest.ByClosing()) 122 result.Response = autorest.Response{Response: resp} 123 return 124} 125 126// ListByReplicationProtectionContainers lists the protectable items in a protection container. 127// Parameters: 128// fabricName - fabric name. 129// protectionContainerName - protection container name. 130func (client ReplicationProtectableItemsClient) ListByReplicationProtectionContainers(ctx context.Context, fabricName string, protectionContainerName string) (result ProtectableItemCollectionPage, err error) { 131 if tracing.IsEnabled() { 132 ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectableItemsClient.ListByReplicationProtectionContainers") 133 defer func() { 134 sc := -1 135 if result.pic.Response.Response != nil { 136 sc = result.pic.Response.Response.StatusCode 137 } 138 tracing.EndSpan(ctx, sc, err) 139 }() 140 } 141 result.fn = client.listByReplicationProtectionContainersNextResults 142 req, err := client.ListByReplicationProtectionContainersPreparer(ctx, fabricName, protectionContainerName) 143 if err != nil { 144 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request") 145 return 146 } 147 148 resp, err := client.ListByReplicationProtectionContainersSender(req) 149 if err != nil { 150 result.pic.Response = autorest.Response{Response: resp} 151 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", resp, "Failure sending request") 152 return 153 } 154 155 result.pic, err = client.ListByReplicationProtectionContainersResponder(resp) 156 if err != nil { 157 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", resp, "Failure responding to request") 158 return 159 } 160 if result.pic.hasNextLink() && result.pic.IsEmpty() { 161 err = result.NextWithContext(ctx) 162 return 163 } 164 165 return 166} 167 168// ListByReplicationProtectionContainersPreparer prepares the ListByReplicationProtectionContainers request. 169func (client ReplicationProtectableItemsClient) ListByReplicationProtectionContainersPreparer(ctx context.Context, fabricName string, protectionContainerName string) (*http.Request, error) { 170 pathParameters := map[string]interface{}{ 171 "fabricName": autorest.Encode("path", fabricName), 172 "protectionContainerName": autorest.Encode("path", protectionContainerName), 173 "resourceGroupName": autorest.Encode("path", client.ResourceGroupName), 174 "resourceName": autorest.Encode("path", client.ResourceName), 175 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 176 } 177 178 const APIVersion = "2016-08-10" 179 queryParameters := map[string]interface{}{ 180 "api-version": APIVersion, 181 } 182 183 preparer := autorest.CreatePreparer( 184 autorest.AsGet(), 185 autorest.WithBaseURL(client.BaseURI), 186 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectableItems", pathParameters), 187 autorest.WithQueryParameters(queryParameters)) 188 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 189} 190 191// ListByReplicationProtectionContainersSender sends the ListByReplicationProtectionContainers request. The method will close the 192// http.Response Body if it receives an error. 193func (client ReplicationProtectableItemsClient) ListByReplicationProtectionContainersSender(req *http.Request) (*http.Response, error) { 194 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 195} 196 197// ListByReplicationProtectionContainersResponder handles the response to the ListByReplicationProtectionContainers request. The method always 198// closes the http.Response Body. 199func (client ReplicationProtectableItemsClient) ListByReplicationProtectionContainersResponder(resp *http.Response) (result ProtectableItemCollection, err error) { 200 err = autorest.Respond( 201 resp, 202 azure.WithErrorUnlessStatusCode(http.StatusOK), 203 autorest.ByUnmarshallingJSON(&result), 204 autorest.ByClosing()) 205 result.Response = autorest.Response{Response: resp} 206 return 207} 208 209// listByReplicationProtectionContainersNextResults retrieves the next set of results, if any. 210func (client ReplicationProtectableItemsClient) listByReplicationProtectionContainersNextResults(ctx context.Context, lastResults ProtectableItemCollection) (result ProtectableItemCollection, err error) { 211 req, err := lastResults.protectableItemCollectionPreparer(ctx) 212 if err != nil { 213 return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "listByReplicationProtectionContainersNextResults", nil, "Failure preparing next results request") 214 } 215 if req == nil { 216 return 217 } 218 resp, err := client.ListByReplicationProtectionContainersSender(req) 219 if err != nil { 220 result.Response = autorest.Response{Response: resp} 221 return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "listByReplicationProtectionContainersNextResults", resp, "Failure sending next results request") 222 } 223 result, err = client.ListByReplicationProtectionContainersResponder(resp) 224 if err != nil { 225 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "listByReplicationProtectionContainersNextResults", resp, "Failure responding to next results request") 226 } 227 return 228} 229 230// ListByReplicationProtectionContainersComplete enumerates all values, automatically crossing page boundaries as required. 231func (client ReplicationProtectableItemsClient) ListByReplicationProtectionContainersComplete(ctx context.Context, fabricName string, protectionContainerName string) (result ProtectableItemCollectionIterator, err error) { 232 if tracing.IsEnabled() { 233 ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectableItemsClient.ListByReplicationProtectionContainers") 234 defer func() { 235 sc := -1 236 if result.Response().Response.Response != nil { 237 sc = result.page.Response().Response.Response.StatusCode 238 } 239 tracing.EndSpan(ctx, sc, err) 240 }() 241 } 242 result.page, err = client.ListByReplicationProtectionContainers(ctx, fabricName, protectionContainerName) 243 return 244} 245