forked from solo-io/unik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_images.go
39 lines (36 loc) · 1.02 KB
/
list_images.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package aws
import (
"github.com/Sirupsen/logrus"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/emc-advanced-dev/pkg/errors"
"github.com/emc-advanced-dev/unik/pkg/types"
)
const UNIK_IMAGE_ID = "UNIK_IMAGE_ID"
func (p *AwsProvider) ListImages() ([]*types.Image, error) {
if len(p.state.GetImages()) < 1 {
return []*types.Image{}, nil
}
imageIds := []*string{}
for imageId := range p.state.GetImages() {
imageIds = append(imageIds, aws.String(imageId))
}
param := &ec2.DescribeImagesInput{
ImageIds: imageIds,
}
output, err := p.newEC2().DescribeImages(param)
if err != nil {
return nil, errors.New("running ec2 describe images ", err)
}
images := []*types.Image{}
for _, ec2Image := range output.Images {
imageId := *ec2Image.ImageId
image, ok := p.state.GetImages()[imageId]
if !ok {
logrus.WithFields(logrus.Fields{"ec2Image": ec2Image}).Errorf("found an image that unik has no record of")
continue
}
images = append(images, image)
}
return images, nil
}