Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge main #1

Merged
merged 6 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
run: make build

- name: Trivy scan
uses: aquasecurity/trivy-action@0.7.1
uses: aquasecurity/trivy-action@0.8.0
with:
scan-type: "fs"
ignore-unfixed: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/trivy-scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/checkout@v3

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@0.7.1
uses: aquasecurity/trivy-action@0.8.0
with:
scan-type: "fs"
format: "sarif"
Expand Down
6 changes: 4 additions & 2 deletions builder/nutanix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ const (

type Config struct {
common.PackerConfig `mapstructure:",squash"`
CommConfig communicator.Config `mapstructure:",squash"`
CommConfig communicator.Config `mapstructure:",squash"`
commonsteps.CDConfig `mapstructure:",squash"`
shutdowncommand.ShutdownConfig `mapstructure:",squash"`
ClusterConfig `mapstructure:",squash"`
VmConfig `mapstructure:",squash"`
ForceDeregister bool `mapstructure:"force_deregister" json:"force_deregister" required:"false"`
ForceDeregister bool `mapstructure:"force_deregister" json:"force_deregister" required:"false"`



ctx interpolate.Context
Expand Down Expand Up @@ -161,6 +162,7 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {

errs = packersdk.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(&c.ctx)...)
errs = packersdk.MultiErrorAppend(errs, c.CDConfig.Prepare(&c.ctx)...)
errs = packersdk.MultiErrorAppend(errs, c.CommConfig.Prepare(&c.ctx)...)

if errs != nil && len(errs.Errors) > 0 {
return warnings, errs
Expand Down
32 changes: 13 additions & 19 deletions builder/nutanix/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,34 +739,28 @@ func (d *NutanixDriver) SaveVMDisk(diskUUID string, imageName string, ForceDereg
}
if *ImageList.Metadata.TotalMatches==0 {
log.Println("Image with given Name not found, no need to deregister")
}
if *ImageList.Metadata.TotalMatches>1 {
log.Println("More than one mage with given Name found, will not deregister")
}
if *ImageList.Metadata.TotalMatches==1 {
log.Println("Exactly one mage with given Name found, will deregister")
} else if *ImageList.Metadata.TotalMatches>1 {
log.Println("More than one image with given Name found, will not deregister")
} else if *ImageList.Metadata.TotalMatches==1 {
log.Println("Exactly one image with given Name found, will deregister")

resp,err:= conn.V3.DeleteImage(*ImageList.Entities[0].Metadata.UUID)
if err != nil {
return nil, fmt.Errorf("error while DeleteImage, %s", err.Error())
}
taskUUID := resp.Status.ExecutionContext.TaskUUID.(string)
log.Printf("Wait until delete Image %s is finished, %s\n",*ImageList.Entities[0].Metadata.UUID,taskUUID)
// Wait for the Image to be deleted
for {
for i := 0; i < 1200; i++ {
resp, err := conn.V3.GetTask(taskUUID)
if err == nil {
if *resp.Status == "SUCCEEDED" {
log.Printf("existing image deleted")
break
} else {
log.Printf("Current status is: " + *resp.Status)
time.Sleep(5 * time.Second)
}
} else {
log.Printf("Error while Image Delete getting Task Status, %s", err.Error())
return nil, err
if err != nil || *resp.Status != "SUCCEEDED" {
<-time.After(1 * time.Second)
continue
}

if *resp.Status == "SUCCEEDED" {
break
}
return nil, fmt.Errorf("error while Image Delete getting Task Status, %s", err.Error())
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion example/source.nutanix.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ source "nutanix" "centos" {
subnet_name = var.nutanix_subnet
}

image_name ="centos-{{isotime `Jan-_2-15:04:05`}}"
image_name = "centos-packer-image"
force_deregister = true
user_data = "I2Nsb3VkLWNvbmZpZwp1c2VyczoKICAtIG5hbWU6IGNlbnRvcwogICAgc3VkbzogWydBTEw9KEFMTCkgTk9QQVNTV0Q6QUxMJ10KY2hwYXNzd2Q6CiAgbGlzdDogfAogICAgY2VudG9zOnBhY2tlcgogIGV4cGlyZTogRmFsc2UKc3NoX3B3YXV0aDogVHJ1ZQ=="

shutdown_command = "echo 'packer' | sudo -S shutdown -P now"
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module github.com/nutanix-cloud-native/packer-plugin-nutanix

go 1.17
go 1.19

replace (
github.com/hashicorp/consul => github.com/hashicorp/consul v1.10.4
github.com/hashicorp/vault => github.com/hashicorp/vault v1.4.2
)

require (
github.com/hashicorp/hcl/v2 v2.14.0
github.com/hashicorp/hcl/v2 v2.14.1
github.com/hashicorp/packer-plugin-sdk v0.3.2
github.com/nutanix-cloud-native/prism-go-client v0.2.0
github.com/zclconf/go-cty v1.10.0
Expand Down Expand Up @@ -94,7 +94,7 @@ require (
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
google.golang.org/api v0.56.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
Loading