From 1a17b799f1f0304a5257ae6a7f4731c3e2310a58 Mon Sep 17 00:00:00 2001 From: He Guimin Date: Wed, 15 Aug 2018 00:14:02 +0800 Subject: [PATCH] Support describing and checking source image coming from marketplace --- .../alicloud/ecs/step_check_source_image.go | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/builder/alicloud/ecs/step_check_source_image.go b/builder/alicloud/ecs/step_check_source_image.go index 6090d8868..f0fbf46e2 100644 --- a/builder/alicloud/ecs/step_check_source_image.go +++ b/builder/alicloud/ecs/step_check_source_image.go @@ -18,8 +18,12 @@ func (s *stepCheckAlicloudSourceImage) Run(_ context.Context, state multistep.St client := state.Get("client").(*ecs.Client) config := state.Get("config").(Config) ui := state.Get("ui").(packer.Ui) - images, _, err := client.DescribeImages(&ecs.DescribeImagesArgs{RegionId: common.Region(config.AlicloudRegion), - ImageId: config.AlicloudSourceImage}) + args := &ecs.DescribeImagesArgs{ + RegionId: common.Region(config.AlicloudRegion), + ImageId: config.AlicloudSourceImage, + } + args.PageSize = 50 + images, _, err := client.DescribeImages(args) if err != nil { err := fmt.Errorf("Error querying alicloud image: %s", err) state.Put("error", err) @@ -27,6 +31,19 @@ func (s *stepCheckAlicloudSourceImage) Run(_ context.Context, state multistep.St return multistep.ActionHalt } + // Describe markerplace image + args.ImageOwnerAlias = ecs.ImageOwnerMarketplace + imageMarkets, _, err := client.DescribeImages(args) + if err != nil { + err := fmt.Errorf("Error querying alicloud marketplace image: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + if len(imageMarkets) > 0 { + images = append(images, imageMarkets...) + } + if len(images) == 0 { err := fmt.Errorf("No alicloud image was found matching filters: %v", config.AlicloudSourceImage) state.Put("error", err)