mirror of https://github.com/docker/compose.git
Add first volume create in ACI
Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
parent
fda09712c0
commit
45179a5bff
|
@ -67,6 +67,20 @@ func NewStorageAccountsClient(subscriptionID string) (storage.AccountsClient, er
|
|||
return containerGroupsClient, nil
|
||||
}
|
||||
|
||||
// NewStorageAccountsClient get client to manipulate storage accounts
|
||||
func NewFileShareClient(subscriptionID string) (storage.FileSharesClient, error) {
|
||||
containerGroupsClient := storage.NewFileSharesClient(subscriptionID)
|
||||
err := setupClient(&containerGroupsClient.Client)
|
||||
if err != nil {
|
||||
return storage.FileSharesClient{}, err
|
||||
}
|
||||
containerGroupsClient.PollingDelay = 5 * time.Second
|
||||
containerGroupsClient.RetryAttempts = 30
|
||||
containerGroupsClient.RetryDuration = 1 * time.Second
|
||||
return containerGroupsClient, nil
|
||||
}
|
||||
|
||||
|
||||
// NewSubscriptionsClient get subscription client
|
||||
func NewSubscriptionsClient() (subscription.SubscriptionsClient, error) {
|
||||
subc := subscription.NewSubscriptionsClient()
|
||||
|
|
|
@ -19,6 +19,7 @@ package login
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
|
@ -48,3 +49,62 @@ func (helper StorageAccountHelper) GetAzureStorageAccountKey(ctx context.Context
|
|||
key := (*result.Keys)[0]
|
||||
return *key.Value, nil
|
||||
}
|
||||
|
||||
func (helper StorageAccountHelper) ListFileShare(ctx context.Context) ([]string, error) {
|
||||
aciContext := helper.AciContext
|
||||
accountClient, err := NewStorageAccountsClient(aciContext.SubscriptionID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result, err := accountClient.ListByResourceGroup(ctx, aciContext.ResourceGroup)
|
||||
accounts := result.Value
|
||||
fileShareClient, err := NewFileShareClient(aciContext.SubscriptionID)
|
||||
fileShares := []string{}
|
||||
for _, account := range *accounts {
|
||||
fileSharePage, err := fileShareClient.List(ctx, aciContext.ResourceGroup, *account.Name, "", "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for ; fileSharePage.NotDone() ; fileSharePage.NextWithContext(ctx) {
|
||||
values := fileSharePage.Values()
|
||||
for _, fileShare := range values {
|
||||
fileShares = append(fileShares, *fileShare.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return fileShares, nil
|
||||
}
|
||||
|
||||
func (helper StorageAccountHelper) CreateFileShare(ctx context.Context, accountName string, fileShareName string) (storage.FileShare, error) {
|
||||
aciContext := helper.AciContext
|
||||
accountClient, err := NewStorageAccountsClient(aciContext.SubscriptionID)
|
||||
if err != nil {
|
||||
return storage.FileShare{}, err
|
||||
}
|
||||
account, err := accountClient.GetProperties(ctx, aciContext.ResourceGroup, accountName, "")
|
||||
if err != nil {
|
||||
//TODO check err not found
|
||||
parameters := storage.AccountCreateParameters{
|
||||
Location: &aciContext.Location,
|
||||
Sku:&storage.Sku{
|
||||
Name: storage.StandardLRS,
|
||||
Tier: storage.Standard,
|
||||
},
|
||||
}
|
||||
// TODO progress account creation
|
||||
future, err := accountClient.Create(ctx, aciContext.ResourceGroup, accountName, parameters)
|
||||
if err != nil {
|
||||
return storage.FileShare{}, err
|
||||
}
|
||||
account, err = future.Result(accountClient)
|
||||
}
|
||||
fileShareClient, err := NewFileShareClient(aciContext.SubscriptionID)
|
||||
fileShare, err := fileShareClient.Get(ctx, aciContext.ResourceGroup, *account.Name, fileShareName, "")
|
||||
if err != nil {
|
||||
// TODO check err not found
|
||||
fileShare, err = fileShareClient.Create(ctx, aciContext.ResourceGroup, *account.Name, fileShareName, storage.FileShare{})
|
||||
}
|
||||
|
||||
return fileShare, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue