cloud/aws: move maintenance calls to separate file
This commit is contained in:
parent
66c2c31a1c
commit
8fc91d1c6d
4 changed files with 95 additions and 75 deletions
|
|
@ -534,59 +534,6 @@ func (a *AWS) shareSnapshot(snapshotId string, userIds []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (a *AWS) RemoveSnapshotAndDeregisterImage(image *ec2types.Image) error {
|
||||
if image == nil {
|
||||
return fmt.Errorf("image is nil")
|
||||
}
|
||||
|
||||
var snapshots []*string
|
||||
for _, bdm := range image.BlockDeviceMappings {
|
||||
snapshots = append(snapshots, bdm.Ebs.SnapshotId)
|
||||
}
|
||||
|
||||
_, err := a.ec2.DeregisterImage(
|
||||
context.Background(),
|
||||
&ec2.DeregisterImageInput{
|
||||
ImageId: image.ImageId,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, s := range snapshots {
|
||||
_, err = a.ec2.DeleteSnapshot(
|
||||
context.Background(),
|
||||
&ec2.DeleteSnapshotInput{
|
||||
SnapshotId: s,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
// TODO return err?
|
||||
logrus.Warn("Unable to remove snapshot", s)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// For service maintenance images are discovered by the "Name:composer-api-*" tag filter. Currently
|
||||
// all image names in the service are generated, so they're guaranteed to be unique as well. If
|
||||
// users are ever allowed to name their images, an extra tag should be added.
|
||||
func (a *AWS) DescribeImagesByTag(tagKey, tagValue string) ([]ec2types.Image, error) {
|
||||
imgs, err := a.ec2.DescribeImages(
|
||||
context.Background(),
|
||||
&ec2.DescribeImagesInput{
|
||||
Filters: []ec2types.Filter{
|
||||
{
|
||||
Name: aws.String(fmt.Sprintf("tag:%s", tagKey)),
|
||||
Values: []string{tagValue},
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
return imgs.Images, err
|
||||
}
|
||||
|
||||
func (a *AWS) S3ObjectPresignedURL(bucket, objectKey string) (string, error) {
|
||||
logrus.Infof("[AWS] 📋 Generating Presigned URL for S3 object %s/%s", bucket, objectKey)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue