Skip to content

Commit

Permalink
Merge pull request #271 from mkumatag/cap_destination
Browse files Browse the repository at this point in the history
introduce capture destination option
  • Loading branch information
ppc64le-cloud-bot authored Jan 23, 2025
2 parents 8abdd5d + b4d14de commit d4dc7be
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 16 deletions.
6 changes: 4 additions & 2 deletions builder/powervs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ func (b *Builder) Prepare(raws ...interface{}) (generatedVars []string, warnings
}

packer.LogSecretFilter.Set(b.config.APIKey)
packer.LogSecretFilter.Set(b.config.Capture.COS.AccessKey)
packer.LogSecretFilter.Set(b.config.Capture.COS.SecretKey)
if b.config.Capture.COS != nil {
packer.LogSecretFilter.Set(b.config.Capture.COS.AccessKey)
packer.LogSecretFilter.Set(b.config.Capture.COS.SecretKey)
}

return []string{}, nil, nil
}
Expand Down
7 changes: 5 additions & 2 deletions builder/powervs/common/run_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ type StockImage struct {
}

type Capture struct {
Name string `mapstructure:"name" required:"true"`
COS *CaptureCOS `mapstructure:"cos" required:"false"`
Name string `mapstructure:"name" required:"true"`
// The destination determines how the image is captured. Options: ('image-catalog', 'cloud-storage', 'both'). The default is 'cloud-storage'.
// if image-catalog is specified then cos field content will be ignored
Destination string `mapstructure:"destination" required:"false"`
COS *CaptureCOS `mapstructure:"cos" required:"false"`
}

type CaptureCOS struct {
Expand Down
10 changes: 6 additions & 4 deletions builder/powervs/common/run_config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions builder/powervs/step_capture_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package powervs
import (
"context"
"fmt"
"time"

"github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/power-go-client/power/models"
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/ppc64le-cloud/packer-plugin-powervs/builder/powervs/common"
"time"
)

const (
Expand All @@ -17,7 +18,7 @@ const (
)

var (
CaptureDestinationCloudStorage = "cloud-storage"
CaptureDestinationDefault = "cloud-storage"
)

type StepCaptureInstance struct {
Expand All @@ -38,13 +39,20 @@ func (s *StepCaptureInstance) Run(_ context.Context, state multistep.StateBag) m
return multistep.ActionHalt
}

captureDestination := CaptureDestinationDefault
if s.Capture.Destination != "" {
captureDestination = s.Capture.Destination
}

body := &models.PVMInstanceCapture{
CaptureDestination: &CaptureDestinationCloudStorage,
CaptureName: &s.Capture.Name,
CloudStorageAccessKey: s.Capture.COS.AccessKey,
CloudStorageImagePath: s.Capture.COS.Bucket,
CloudStorageRegion: s.Capture.COS.Region,
CloudStorageSecretKey: s.Capture.COS.SecretKey,
CaptureDestination: &captureDestination,
CaptureName: &s.Capture.Name,
}
if s.Capture.COS != nil {
body.CloudStorageAccessKey = s.Capture.COS.AccessKey
body.CloudStorageImagePath = s.Capture.COS.Bucket
body.CloudStorageRegion = s.Capture.COS.Region
body.CloudStorageSecretKey = s.Capture.COS.SecretKey
}
jobRef, err := instanceClient.CaptureInstanceToImageCatalogV2(*i.PvmInstanceID, body)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions docs-partials/builder/powervs/common/Capture-not-required.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<!-- Code generated from the comments of the Capture struct in builder/powervs/common/run_config.go; DO NOT EDIT MANUALLY -->

- `destination` (string) - The destination determines how the image is captured. Options: ('image-catalog', 'cloud-storage', 'both'). The default is 'cloud-storage'.
if image-catalog is specified then cos field content will be ignored

- `cos` (\*CaptureCOS) - COS

<!-- End of code generated from the comments of the Capture struct in builder/powervs/common/run_config.go; -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- Code generated from the comments of the RunConfig struct in builder/powervs/common/run_config.go; DO NOT EDIT MANUALLY -->

- `subnet_ids` ([]string) - Subnet I Ds

- `dhcp_network` (bool) - DHCP Network

<!-- End of code generated from the comments of the RunConfig struct in builder/powervs/common/run_config.go; -->

0 comments on commit d4dc7be

Please sign in to comment.