internal/upload/azure: make location optional in various methods
Make the `location` argument optional (can be now empty "") in `RegisterImage()` and `CreateStorageAccount()` methods. If the provided `location` argument is an empty string, then the location is determined from the provided Resource Group instead. Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
parent
641f7a7d29
commit
4df3b0ca03
1 changed files with 20 additions and 0 deletions
|
|
@ -74,10 +74,20 @@ func (ac Client) GetResourceGroupLocation(ctx context.Context, subscriptionID, r
|
||||||
// CreateStorageAccount creates a storage account in the specified resource
|
// CreateStorageAccount creates a storage account in the specified resource
|
||||||
// group. The location parameter can be used to specify its location. The tag
|
// group. The location parameter can be used to specify its location. The tag
|
||||||
// can be used to specify a tag attached to the account.
|
// 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 (ac Client) CreateStorageAccount(ctx context.Context, subscriptionID, resourceGroup, name, location string, tag Tag) error {
|
func (ac Client) CreateStorageAccount(ctx context.Context, subscriptionID, resourceGroup, name, location string, tag Tag) error {
|
||||||
c := storage.NewAccountsClient(subscriptionID)
|
c := storage.NewAccountsClient(subscriptionID)
|
||||||
c.Authorizer = ac.authorizer
|
c.Authorizer = ac.authorizer
|
||||||
|
|
||||||
|
var err error
|
||||||
|
if location == "" {
|
||||||
|
location, err = ac.GetResourceGroupLocation(ctx, subscriptionID, resourceGroup)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("retrieving resource group location failed: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result, err := c.Create(ctx, resourceGroup, name, storage.AccountCreateParameters{
|
result, err := c.Create(ctx, resourceGroup, name, storage.AccountCreateParameters{
|
||||||
Sku: &storage.Sku{
|
Sku: &storage.Sku{
|
||||||
Name: storage.StandardLRS,
|
Name: storage.StandardLRS,
|
||||||
|
|
@ -125,12 +135,22 @@ func (ac Client) GetStorageAccountKey(ctx context.Context, subscriptionID, resou
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterImage creates a generalized V1 Linux image from a given blob.
|
// 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.
|
||||||
func (ac Client) RegisterImage(ctx context.Context, subscriptionID, resourceGroup, storageAccount, storageContainer, blobName, imageName, location string) error {
|
func (ac Client) RegisterImage(ctx context.Context, subscriptionID, resourceGroup, storageAccount, storageContainer, blobName, imageName, location string) error {
|
||||||
c := compute.NewImagesClient(subscriptionID)
|
c := compute.NewImagesClient(subscriptionID)
|
||||||
c.Authorizer = ac.authorizer
|
c.Authorizer = ac.authorizer
|
||||||
|
|
||||||
blobURI := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", storageAccount, storageContainer, blobName)
|
blobURI := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", storageAccount, storageContainer, blobName)
|
||||||
|
|
||||||
|
var err error
|
||||||
|
if location == "" {
|
||||||
|
location, err = ac.GetResourceGroupLocation(ctx, subscriptionID, resourceGroup)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("retrieving resource group location failed: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
imageFuture, err := c.CreateOrUpdate(ctx, resourceGroup, imageName, compute.Image{
|
imageFuture, err := c.CreateOrUpdate(ctx, resourceGroup, imageName, compute.Image{
|
||||||
Response: autorest.Response{},
|
Response: autorest.Response{},
|
||||||
ImageProperties: &compute.ImageProperties{
|
ImageProperties: &compute.ImageProperties{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue