[node operator] Add Azure client

Signed-off-by: Malte Poll <mp@edgeless.systems>
This commit is contained in:
Malte Poll 2022-07-18 10:18:29 +02:00 committed by Malte Poll
parent a50cc2b64d
commit c74360bf62
17 changed files with 1341 additions and 2 deletions

View file

@ -0,0 +1,54 @@
package client
import (
"context"
"fmt"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v2"
)
// GetScalingGroupImage returns the image URI of the scaling group.
func (c *Client) GetScalingGroupImage(ctx context.Context, scalingGroupID string) (string, error) {
_, resourceGroup, scaleSet, err := splitVMSSID(scalingGroupID)
if err != nil {
return "", err
}
res, err := c.scaleSetsAPI.Get(ctx, resourceGroup, scaleSet, nil)
if err != nil {
return "", err
}
if res.Properties == nil ||
res.Properties.VirtualMachineProfile == nil ||
res.Properties.VirtualMachineProfile.StorageProfile == nil ||
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference == nil ||
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.ID == nil {
return "", fmt.Errorf("scalet set %q does not have valid image reference", scalingGroupID)
}
return *res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.ID, nil
}
// SetScalingGroupImage sets the image URI of the scaling group.
func (c *Client) SetScalingGroupImage(ctx context.Context, scalingGroupID, imageURI string) error {
_, resourceGroup, scaleSet, err := splitVMSSID(scalingGroupID)
if err != nil {
return err
}
poller, err := c.scaleSetsAPI.BeginUpdate(ctx, resourceGroup, scaleSet, armcompute.VirtualMachineScaleSetUpdate{
Properties: &armcompute.VirtualMachineScaleSetUpdateProperties{
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetUpdateVMProfile{
StorageProfile: &armcompute.VirtualMachineScaleSetUpdateStorageProfile{
ImageReference: &armcompute.ImageReference{
ID: &imageURI,
},
},
},
},
}, nil)
if err != nil {
return err
}
if _, err := poller.PollUntilDone(ctx, nil); err != nil {
return err
}
return nil
}