upload/azure: rename Image to PageBlob

The UploadImage method doesn't actually create an image. It creates a Page
Blob. Blob is something like S3 object but in the Azure terminology. Page
Blob means that's optimized for random access and it's the only blob type
that can be used to create images.

This commit cleans up the terminology so it's less confusing.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Ondřej Budai 2021-03-03 12:09:08 +01:00 committed by Tom Gundersen
parent 478f69e092
commit 4f66ab5d7c
4 changed files with 16 additions and 16 deletions

View file

@ -43,9 +43,9 @@ func main() {
os.Exit(1)
}
err = c.UploadImage(
azure.ImageMetadata{
ImageName: path.Base(fileName),
err = c.UploadPageBlob(
azure.BlobMetadata{
BlobName: path.Base(fileName),
ContainerName: containerName,
},
fileName,

View file

@ -234,13 +234,13 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
continue
}
metadata := azure.ImageMetadata{
metadata := azure.BlobMetadata{
ContainerName: options.Container,
ImageName: t.ImageName,
BlobName: t.ImageName,
}
const azureMaxUploadGoroutines = 4
err = azureStorageClient.UploadImage(
err = azureStorageClient.UploadPageBlob(
metadata,
path.Join(outputDirectory, options.Filename),
azureMaxUploadGoroutines,

View file

@ -82,9 +82,9 @@ func GetAzureCredentialsFromEnv() (*azureCredentials, error) {
// UploadImageToAzure mimics the upload feature of osbuild-composer.
func UploadImageToAzure(c *azureCredentials, imagePath string, imageName string) error {
metadata := azure.ImageMetadata{
metadata := azure.BlobMetadata{
ContainerName: c.ContainerName,
ImageName: imageName,
BlobName: imageName,
}
client, err := azure.NewStorageClient(c.StorageAccount, c.StorageAccessKey)
if err != nil {

View file

@ -39,21 +39,21 @@ func NewStorageClient(storageAccount, storageAccessKey string) (*StorageClient,
}, nil
}
// ImageMetadata contains information needed to store the image in a proper place.
// 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 ImageMetadata struct {
type BlobMetadata struct {
StorageAccount string
ContainerName string
ImageName string
BlobName string
}
// UploadImage takes the metadata and credentials required to upload the image specified by `fileName`
// 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.
func (c StorageClient) UploadImage(metadata ImageMetadata, fileName string, threads int) error {
func (c StorageClient) UploadPageBlob(metadata BlobMetadata, fileName string, threads int) error {
// Azure cannot create an image from a storage blob without .vhd extension
if !strings.HasSuffix(metadata.ImageName, ".vhd") {
metadata.ImageName = metadata.ImageName + ".vhd"
if !strings.HasSuffix(metadata.BlobName, ".vhd") {
metadata.BlobName = metadata.BlobName + ".vhd"
}
// get storage account blob service URL endpoint.
@ -94,7 +94,7 @@ func (c StorageClient) UploadImage(metadata ImageMetadata, fileName string, thre
}
// Create page blob URL. Page blob is required for VM images
blobURL := newPageBlobURL(containerURL, metadata.ImageName)
blobURL := newPageBlobURL(containerURL, metadata.BlobName)
_, err = blobURL.Create(ctx, stat.Size(), 0, azblob.BlobHTTPHeaders{}, azblob.Metadata{}, azblob.BlobAccessConditions{})
if err != nil {
return fmt.Errorf("cannot create the blob URL: %v", err)