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