2022-07-18 04:18:29 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
|
|
|
|
armcomputev2 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v2"
|
|
|
|
"github.com/edgelesssys/constellation/operators/constellation-node-operator/internal/poller"
|
2022-07-22 10:28:09 -04:00
|
|
|
"github.com/spf13/afero"
|
2022-07-18 04:18:29 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Client is a client for the Azure Cloud.
|
|
|
|
type Client struct {
|
|
|
|
scaleSetsAPI
|
|
|
|
virtualMachineScaleSetVMsAPI
|
|
|
|
capacityPollerGenerator func(resourceGroup, scaleSet string, wantedCapacity int64) capacityPoller
|
|
|
|
pollerOptions *poller.PollUntilDoneOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewFromDefault creates a client with initialized clients.
|
2022-07-22 10:28:09 -04:00
|
|
|
func NewFromDefault(configPath string) (*Client, error) {
|
|
|
|
config, err := loadConfig(afero.NewOsFs(), configPath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-07-18 04:18:29 -04:00
|
|
|
cred, err := azidentity.NewDefaultAzureCredential(nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-07-22 10:28:09 -04:00
|
|
|
scaleSetAPI, err := armcomputev2.NewVirtualMachineScaleSetsClient(config.SubscriptionID, cred, nil)
|
2022-07-18 04:18:29 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-07-22 10:28:09 -04:00
|
|
|
virtualMachineScaleSetVMsAPI, err := armcomputev2.NewVirtualMachineScaleSetVMsClient(config.SubscriptionID, cred, nil)
|
2022-07-18 04:18:29 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Client{
|
|
|
|
scaleSetsAPI: scaleSetAPI,
|
|
|
|
virtualMachineScaleSetVMsAPI: virtualMachineScaleSetVMsAPI,
|
|
|
|
capacityPollerGenerator: func(resourceGroup, scaleSet string, wantedCapacity int64) capacityPoller {
|
|
|
|
return poller.New[int64](&capacityPollingHandler{
|
|
|
|
resourceGroup: resourceGroup,
|
|
|
|
scaleSet: scaleSet,
|
|
|
|
wantedCapacity: wantedCapacity,
|
|
|
|
scaleSetsAPI: scaleSetAPI,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|