azure

package
v0.34.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultUploadThreads = 16

DefaultUploadThreads defines a tested default value for the UploadPageBlob method's threads parameter.

View Source
const PageBlobMaxUploadPagesBytes = 4 * common.MiB

PageBlobMaxUploadPagesBytes defines how much bytes can we upload in a single UploadPages call. See https://learn.microsoft.com/en-us/rest/api/storageservices/put-page

Variables

This section is empty.

Functions

func EnsureVHDExtension

func EnsureVHDExtension(s string) string

EnsureVHDExtension returns the given string with .vhd suffix if it already doesn't have one.

func RandomStorageAccountName

func RandomStorageAccountName(prefix string) string

RandomStorageAccountName returns a randomly generated name that can be used for a storage account. This means that it must use only alphanumeric characters and its length must be 24 or lower.

Types

type BlobMetadata

type BlobMetadata struct {
	StorageAccount string
	ContainerName  string
	BlobName       string
}

BlobMetadata contains information needed to store the image in a proper place. In case of Azure cloud storage this includes container name and blob name.

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(credentials Credentials, tenantID string) (*Client, error)

NewClient creates a client for accessing the Azure API. See https://docs.microsoft.com/en-us/rest/api/azure/ If you need to work with the Azure Storage API, see NewStorageClient

func (Client) CreateStorageAccount

func (ac Client) CreateStorageAccount(ctx context.Context, subscriptionID, resourceGroup, name, location string, tag Tag) error

CreateStorageAccount creates a storage account in the specified resource group. The location parameter can be used to specify its location. The tag can be used to specify a tag attached to the account. The location is optional and if not provided, it is determined from the resource group.

func (Client) GetResourceGroupLocation

func (ac Client) GetResourceGroupLocation(ctx context.Context, subscriptionID, resourceGroup string) (string, error)

GetResourceGroupLocation returns the location of the given resource group.

func (Client) GetResourceNameByTag

func (ac Client) GetResourceNameByTag(ctx context.Context, subscriptionID, resourceGroup string, tag Tag) (string, error)

GetResourceNameByTag returns a name of an Azure resource tagged with the given `tag`. Note that if multiple resources with the same tag exists in the specified resource group, only one name is returned. It's undefined which one it is.

func (Client) GetStorageAccountKey

func (ac Client) GetStorageAccountKey(ctx context.Context, subscriptionID, resourceGroup string, storageAccount string) (string, error)

GetStorageAccountKey returns a storage account key that can be used to access the given storage account. This method always returns only the first key.

func (Client) RegisterImage

func (ac Client) RegisterImage(ctx context.Context, subscriptionID, resourceGroup, storageAccount, storageContainer, blobName, imageName, location string) error

RegisterImage creates a generalized V1 Linux image from a given blob. The location is optional and if not provided, it is determined from the resource group.

type Credentials

type Credentials struct {
	// contains filtered or unexported fields
}

func ParseAzureCredentialsFile

func ParseAzureCredentialsFile(filename string) (*Credentials, error)

ParseAzureCredentialsFile parses a credentials file for azure. The file is in toml format and contains two keys: client_id and client_secret

Example of the file: client_id = "clientIdOfMyApplication" client_secret = "ToucanToucan~"

type StorageClient

type StorageClient struct {
	// contains filtered or unexported fields
}

StorageClient is a client for the Azure Storage API, see the docs: https://docs.microsoft.com/en-us/rest/api/storageservices/

func NewStorageClient

func NewStorageClient(storageAccount, storageAccessKey string) (*StorageClient, error)

NewStorageClient creates a new client for Azure Storage API. See the following keys how to retrieve the storageAccessKey using the Azure's API: https://docs.microsoft.com/en-us/rest/api/storagerp/storageaccounts/listkeys

func (StorageClient) CreateStorageContainerIfNotExist

func (c StorageClient) CreateStorageContainerIfNotExist(ctx context.Context, storageAccount, name string) error

CreateStorageContainerIfNotExist creates an empty storage container inside a storage account. If a container with the same name already exists, this method is no-op.

func (StorageClient) TagBlob

func (c StorageClient) TagBlob(ctx context.Context, metadata BlobMetadata, tags map[string]string) error

func (StorageClient) UploadPageBlob

func (c StorageClient) UploadPageBlob(metadata BlobMetadata, fileName string, threads int) error

UploadPageBlob takes the metadata and credentials required to upload the image specified by `fileName` It can speed up the upload by using goroutines. The number of parallel goroutines is bounded by the `threads` argument.

Note that if you want to create an image out of the page blob, make sure that metadata.BlobName has a .vhd extension, see EnsureVHDExtension.

type Tag

type Tag struct {
	Name  string
	Value string
}

Tag is a name-value pair representing the tag structure in Azure

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL