...

Source file src/github.com/Azure/azure-sdk-for-go/services/classic/management/osimage/client.go

Documentation: github.com/Azure/azure-sdk-for-go/services/classic/management/osimage

     1  // +build go1.7
     2  
     3  // Package osimage provides a client for Operating System Images.
     4  package osimage
     5  
     6  // Copyright (c) Microsoft Corporation. All rights reserved.
     7  // Licensed under the MIT License. See License.txt in the project root for license information.
     8  
     9  import (
    10  	"encoding/xml"
    11  
    12  	"github.com/Azure/azure-sdk-for-go/services/classic/management"
    13  )
    14  
    15  const (
    16  	azureImageListURL    = "services/images"
    17  	errInvalidImage      = "Can not find image %s in specified subscription, please specify another image name."
    18  	errParamNotSpecified = "Parameter %s is not specified."
    19  )
    20  
    21  // NewClient is used to instantiate a new OSImageClient from an Azure client.
    22  func NewClient(client management.Client) OSImageClient {
    23  	return OSImageClient{client: client}
    24  }
    25  
    26  func (c OSImageClient) ListOSImages() (ListOSImagesResponse, error) {
    27  	var l ListOSImagesResponse
    28  
    29  	response, err := c.client.SendAzureGetRequest(azureImageListURL)
    30  	if err != nil {
    31  		return l, err
    32  	}
    33  
    34  	err = xml.Unmarshal(response, &l)
    35  	return l, err
    36  }
    37  
    38  // AddOSImage adds an operating system image to the image repository that is associated with the specified subscription.
    39  //
    40  // See https://msdn.microsoft.com/en-us/library/azure/jj157192.aspx for details.
    41  func (c OSImageClient) AddOSImage(osi *OSImage) (management.OperationID, error) {
    42  	data, err := xml.Marshal(osi)
    43  	if err != nil {
    44  		return "", err
    45  	}
    46  
    47  	return c.client.SendAzurePostRequest(azureImageListURL, data)
    48  
    49  }
    50  

View as plain text