1package containerinstance 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 9import ( 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// ContainerClient is the client for the Container methods of the Containerinstance service. 18type ContainerClient struct { 19 BaseClient 20} 21 22// NewContainerClient creates an instance of the ContainerClient client. 23func NewContainerClient(subscriptionID string) ContainerClient { 24 return NewContainerClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewContainerClientWithBaseURI creates an instance of the ContainerClient client using a custom endpoint. Use this 28// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 29func NewContainerClientWithBaseURI(baseURI string, subscriptionID string) ContainerClient { 30 return ContainerClient{NewWithBaseURI(baseURI, subscriptionID)} 31} 32 33// ExecuteCommand executes a command for a specific container instance in a specified resource group and container 34// group. 35// Parameters: 36// resourceGroupName - the name of the resource group. 37// containerGroupName - the name of the container group. 38// containerName - the name of the container instance. 39// containerExecRequest - the request for the exec command. 40func (client ContainerClient) ExecuteCommand(ctx context.Context, resourceGroupName string, containerGroupName string, containerName string, containerExecRequest ContainerExecRequest) (result ContainerExecResponse, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/ContainerClient.ExecuteCommand") 43 defer func() { 44 sc := -1 45 if result.Response.Response != nil { 46 sc = result.Response.Response.StatusCode 47 } 48 tracing.EndSpan(ctx, sc, err) 49 }() 50 } 51 req, err := client.ExecuteCommandPreparer(ctx, resourceGroupName, containerGroupName, containerName, containerExecRequest) 52 if err != nil { 53 err = autorest.NewErrorWithError(err, "containerinstance.ContainerClient", "ExecuteCommand", nil, "Failure preparing request") 54 return 55 } 56 57 resp, err := client.ExecuteCommandSender(req) 58 if err != nil { 59 result.Response = autorest.Response{Response: resp} 60 err = autorest.NewErrorWithError(err, "containerinstance.ContainerClient", "ExecuteCommand", resp, "Failure sending request") 61 return 62 } 63 64 result, err = client.ExecuteCommandResponder(resp) 65 if err != nil { 66 err = autorest.NewErrorWithError(err, "containerinstance.ContainerClient", "ExecuteCommand", resp, "Failure responding to request") 67 return 68 } 69 70 return 71} 72 73// ExecuteCommandPreparer prepares the ExecuteCommand request. 74func (client ContainerClient) ExecuteCommandPreparer(ctx context.Context, resourceGroupName string, containerGroupName string, containerName string, containerExecRequest ContainerExecRequest) (*http.Request, error) { 75 pathParameters := map[string]interface{}{ 76 "containerGroupName": autorest.Encode("path", containerGroupName), 77 "containerName": autorest.Encode("path", containerName), 78 "resourceGroupName": autorest.Encode("path", resourceGroupName), 79 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 80 } 81 82 const APIVersion = "2018-10-01" 83 queryParameters := map[string]interface{}{ 84 "api-version": APIVersion, 85 } 86 87 preparer := autorest.CreatePreparer( 88 autorest.AsContentType("application/json; charset=utf-8"), 89 autorest.AsPost(), 90 autorest.WithBaseURL(client.BaseURI), 91 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroupName}/containers/{containerName}/exec", pathParameters), 92 autorest.WithJSON(containerExecRequest), 93 autorest.WithQueryParameters(queryParameters)) 94 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 95} 96 97// ExecuteCommandSender sends the ExecuteCommand request. The method will close the 98// http.Response Body if it receives an error. 99func (client ContainerClient) ExecuteCommandSender(req *http.Request) (*http.Response, error) { 100 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 101} 102 103// ExecuteCommandResponder handles the response to the ExecuteCommand request. The method always 104// closes the http.Response Body. 105func (client ContainerClient) ExecuteCommandResponder(resp *http.Response) (result ContainerExecResponse, err error) { 106 err = autorest.Respond( 107 resp, 108 azure.WithErrorUnlessStatusCode(http.StatusOK), 109 autorest.ByUnmarshallingJSON(&result), 110 autorest.ByClosing()) 111 result.Response = autorest.Response{Response: resp} 112 return 113} 114 115// ListLogs get the logs for a specified container instance in a specified resource group and container group. 116// Parameters: 117// resourceGroupName - the name of the resource group. 118// containerGroupName - the name of the container group. 119// containerName - the name of the container instance. 120// tail - the number of lines to show from the tail of the container instance log. If not provided, all 121// available logs are shown up to 4mb. 122func (client ContainerClient) ListLogs(ctx context.Context, resourceGroupName string, containerGroupName string, containerName string, tail *int32) (result Logs, err error) { 123 if tracing.IsEnabled() { 124 ctx = tracing.StartSpan(ctx, fqdn+"/ContainerClient.ListLogs") 125 defer func() { 126 sc := -1 127 if result.Response.Response != nil { 128 sc = result.Response.Response.StatusCode 129 } 130 tracing.EndSpan(ctx, sc, err) 131 }() 132 } 133 req, err := client.ListLogsPreparer(ctx, resourceGroupName, containerGroupName, containerName, tail) 134 if err != nil { 135 err = autorest.NewErrorWithError(err, "containerinstance.ContainerClient", "ListLogs", nil, "Failure preparing request") 136 return 137 } 138 139 resp, err := client.ListLogsSender(req) 140 if err != nil { 141 result.Response = autorest.Response{Response: resp} 142 err = autorest.NewErrorWithError(err, "containerinstance.ContainerClient", "ListLogs", resp, "Failure sending request") 143 return 144 } 145 146 result, err = client.ListLogsResponder(resp) 147 if err != nil { 148 err = autorest.NewErrorWithError(err, "containerinstance.ContainerClient", "ListLogs", resp, "Failure responding to request") 149 return 150 } 151 152 return 153} 154 155// ListLogsPreparer prepares the ListLogs request. 156func (client ContainerClient) ListLogsPreparer(ctx context.Context, resourceGroupName string, containerGroupName string, containerName string, tail *int32) (*http.Request, error) { 157 pathParameters := map[string]interface{}{ 158 "containerGroupName": autorest.Encode("path", containerGroupName), 159 "containerName": autorest.Encode("path", containerName), 160 "resourceGroupName": autorest.Encode("path", resourceGroupName), 161 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 162 } 163 164 const APIVersion = "2018-10-01" 165 queryParameters := map[string]interface{}{ 166 "api-version": APIVersion, 167 } 168 if tail != nil { 169 queryParameters["tail"] = autorest.Encode("query", *tail) 170 } 171 172 preparer := autorest.CreatePreparer( 173 autorest.AsGet(), 174 autorest.WithBaseURL(client.BaseURI), 175 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroupName}/containers/{containerName}/logs", pathParameters), 176 autorest.WithQueryParameters(queryParameters)) 177 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 178} 179 180// ListLogsSender sends the ListLogs request. The method will close the 181// http.Response Body if it receives an error. 182func (client ContainerClient) ListLogsSender(req *http.Request) (*http.Response, error) { 183 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 184} 185 186// ListLogsResponder handles the response to the ListLogs request. The method always 187// closes the http.Response Body. 188func (client ContainerClient) ListLogsResponder(resp *http.Response) (result Logs, err error) { 189 err = autorest.Respond( 190 resp, 191 azure.WithErrorUnlessStatusCode(http.StatusOK), 192 autorest.ByUnmarshallingJSON(&result), 193 autorest.ByClosing()) 194 result.Response = autorest.Response{Response: resp} 195 return 196} 197