1package containerinstance 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// ContainerLogsClient is the client for the ContainerLogs methods of the Containerinstance service. 29type ContainerLogsClient struct { 30 BaseClient 31} 32 33// NewContainerLogsClient creates an instance of the ContainerLogsClient client. 34func NewContainerLogsClient(subscriptionID string) ContainerLogsClient { 35 return NewContainerLogsClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewContainerLogsClientWithBaseURI creates an instance of the ContainerLogsClient client using a custom endpoint. 39// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 40func NewContainerLogsClientWithBaseURI(baseURI string, subscriptionID string) ContainerLogsClient { 41 return ContainerLogsClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// List get the logs for a specified container instance in a specified resource group and container group. 45// Parameters: 46// resourceGroupName - the name of the resource group that contains the container instance. 47// containerName - the name of the container instance. 48// containerGroupName - the name of the container group the container instance belongs to. 49// tail - the number of lines to show from the tail of the container instance log. If not provided, all 50// available logs are shown up to 4mb. 51func (client ContainerLogsClient) List(ctx context.Context, resourceGroupName string, containerName string, containerGroupName string, tail *int32) (result Logs, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/ContainerLogsClient.List") 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.ListPreparer(ctx, resourceGroupName, containerName, containerGroupName, tail) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "containerinstance.ContainerLogsClient", "List", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.ListSender(req) 69 if err != nil { 70 result.Response = autorest.Response{Response: resp} 71 err = autorest.NewErrorWithError(err, "containerinstance.ContainerLogsClient", "List", resp, "Failure sending request") 72 return 73 } 74 75 result, err = client.ListResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "containerinstance.ContainerLogsClient", "List", resp, "Failure responding to request") 78 } 79 80 return 81} 82 83// ListPreparer prepares the List request. 84func (client ContainerLogsClient) ListPreparer(ctx context.Context, resourceGroupName string, containerName string, containerGroupName string, tail *int32) (*http.Request, error) { 85 pathParameters := map[string]interface{}{ 86 "containerGroupName": autorest.Encode("path", containerGroupName), 87 "containerName": autorest.Encode("path", containerName), 88 "resourceGroupName": autorest.Encode("path", resourceGroupName), 89 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 90 } 91 92 const APIVersion = "2017-08-01-preview" 93 queryParameters := map[string]interface{}{ 94 "api-version": APIVersion, 95 } 96 if tail != nil { 97 queryParameters["tail"] = autorest.Encode("query", *tail) 98 } 99 100 preparer := autorest.CreatePreparer( 101 autorest.AsGet(), 102 autorest.WithBaseURL(client.BaseURI), 103 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroupName}/containers/{containerName}/logs", pathParameters), 104 autorest.WithQueryParameters(queryParameters)) 105 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 106} 107 108// ListSender sends the List request. The method will close the 109// http.Response Body if it receives an error. 110func (client ContainerLogsClient) ListSender(req *http.Request) (*http.Response, error) { 111 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 112} 113 114// ListResponder handles the response to the List request. The method always 115// closes the http.Response Body. 116func (client ContainerLogsClient) ListResponder(resp *http.Response) (result Logs, err error) { 117 err = autorest.Respond( 118 resp, 119 client.ByInspecting(), 120 azure.WithErrorUnlessStatusCode(http.StatusOK), 121 autorest.ByUnmarshallingJSON(&result), 122 autorest.ByClosing()) 123 result.Response = autorest.Response{Response: resp} 124 return 125} 126