func (s *stepUpdateImageVisibility) Run(state multistep.StateBag) multistep.StepAction {
	imageId := state.Get("image").(string)
	ui := state.Get("ui").(packer.Ui)
	config := state.Get("config").(Config)

	if config.ImageVisibility == "" {
		return multistep.ActionContinue
	}
	imageClient, err := config.imageV2Client()
	if err != nil {
		err = fmt.Errorf("Error initializing image service client: %s", err)
		state.Put("error", err)
		return multistep.ActionHalt
	}

	ui.Say(fmt.Sprintf("Updating image visibility to %s", config.ImageVisibility))
	r := imageservice.Update(
		imageClient,
		imageId,
		imageservice.UpdateOpts{
			imageservice.UpdateVisibility{
				Visibility: config.ImageVisibility,
			},
		},
	)

	if _, err = r.Extract(); err != nil {
		err = fmt.Errorf("Error updating image visibility: %s", err)
		state.Put("error", err)
		return multistep.ActionHalt
	}

	return multistep.ActionContinue
}
Exemplo n.º 2
0
func TestUpdateImage(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	HandleImageUpdateSuccessfully(t)

	actualImage, err := images.Update(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", images.UpdateOpts{
		images.ReplaceImageName{NewName: "Fedora 17"},
		images.ReplaceImageTags{NewTags: []string{"fedora", "beefy"}},
	}).Extract()

	th.AssertNoErr(t, err)

	sizebytes := int64(2254249)
	checksum := "2cec138d7dae2aa59038ef8c9aec2390"
	file := actualImage.File
	createdDate := actualImage.CreatedAt
	lastUpdate := actualImage.UpdatedAt
	schema := "/v2/schemas/image"

	expectedImage := images.Image{
		ID:         "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
		Name:       "Fedora 17",
		Status:     images.ImageStatusActive,
		Visibility: images.ImageVisibilityPublic,

		SizeBytes: sizebytes,
		Checksum:  checksum,

		Tags: []string{
			"fedora",
			"beefy",
		},

		Owner:            "",
		MinRAMMegabytes:  0,
		MinDiskGigabytes: 0,

		DiskFormat:      "",
		ContainerFormat: "",
		File:            file,
		CreatedAt:       createdDate,
		UpdatedAt:       lastUpdate,
		Schema:          schema,
	}

	th.AssertDeepEquals(t, &expectedImage, actualImage)
}