mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
c74360bf62
Signed-off-by: Malte Poll <mp@edgeless.systems>
55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
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
|
|
}
|