packer-cn/builder/ucloud/uhost/step_check_source_image.go

36 lines
906 B
Go
Raw Normal View History

2019-06-13 03:16:49 -04:00
package uhost
import (
"context"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
)
type stepCheckSourceImageId struct {
SourceUHostImageId string
}
func (s *stepCheckSourceImageId) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
client := state.Get("client").(*UCloudClient)
ui.Say("Querying source image id...")
imageSet, err := client.DescribeImageById(s.SourceUHostImageId)
if err != nil {
if isNotFoundError(err) {
return halt(state, err, "")
}
return halt(state, err, "Error on querying source_image_id")
}
2019-06-13 08:17:08 -04:00
if imageSet.OsType == osTypeWindows {
return halt(state, err, "The builder of ucloud-uhost not support build Windows image yet")
2019-06-13 03:16:49 -04:00
}
state.Put("source_image", imageSet)
return multistep.ActionContinue
}
func (s *stepCheckSourceImageId) Cleanup(multistep.StateBag) {}