Skip to content

Commit

Permalink
remove FIQL filter to avoid bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxtof committed Oct 2, 2024
1 parent 22dd37e commit f0dd188
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Then, run [`packer init`](https://www.packer.io/docs/commands/init).
packer {
required_plugins {
nutanix = {
version = ">= 0.9.3"
version = ">= 0.9.4"
source = "github.com/nutanix-cloud-native/nutanix"
}
}
Expand Down
47 changes: 21 additions & 26 deletions builder/nutanix/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io"
"log"
"net/http"
"net/url"
"path"
"strings"
"time"
Expand Down Expand Up @@ -64,9 +63,7 @@ type nutanixImage struct {
}

func findProjectByName(ctx context.Context, conn *v3.Client, name string) (*v3.Project, error) {
encodedName := url.QueryEscape(name)
filter := fmt.Sprintf("name==%s", encodedName)
resp, err := conn.V3.ListAllProject(ctx, filter)
resp, err := conn.V3.ListAllProject(ctx, "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -96,9 +93,7 @@ func findProjectByName(ctx context.Context, conn *v3.Client, name string) (*v3.P
}

func findClusterByName(ctx context.Context, conn *v3.Client, name string) (*v3.ClusterIntentResponse, error) {
encodedName := url.QueryEscape(name)
filter := fmt.Sprintf("name==%s", encodedName)
resp, err := conn.V3.ListAllCluster(ctx, filter)
resp, err := conn.V3.ListAllCluster(ctx, "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -132,9 +127,7 @@ func findSubnetByUUID(ctx context.Context, conn *v3.Client, uuid string) (*v3.Su
}

func findSubnetByName(ctx context.Context, conn *v3.Client, name string) ([]*v3.SubnetIntentResponse, error) {
encodedName := url.QueryEscape(name)
filter := fmt.Sprintf("name==%s", encodedName)
resp, err := conn.V3.ListAllSubnet(ctx, filter, getEmptyClientSideFilter())
resp, err := conn.V3.ListAllSubnet(ctx, "", nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -187,9 +180,7 @@ func findGPUByName(ctx context.Context, conn *v3.Client, name string) (*v3.VMGpu
}

func sourceImageExists(ctx context.Context, conn *v3.Client, name string, uri string) (*v3.ImageIntentResponse, error) {
encodedName := url.QueryEscape(name)
filter := fmt.Sprintf("name==%s", encodedName)
resp, err := conn.V3.ListAllImage(ctx, filter)
resp, err := conn.V3.ListAllImage(ctx, "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -218,9 +209,7 @@ func findImageByUUID(ctx context.Context, conn *v3.Client, uuid string) (*v3.Ima
}

func findImageByName(ctx context.Context, conn *v3.Client, name string) (*v3.ImageIntentResponse, error) {
encodedName := url.QueryEscape(name)
filter := fmt.Sprintf("name==%s", encodedName)
resp, err := conn.V3.ListAllImage(ctx, filter)
resp, err := conn.V3.ListAllImage(ctx, "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -984,23 +973,33 @@ func (d *NutanixDriver) SaveVMDisk(ctx context.Context, diskUUID string, index i
// When force_deregister, check if image already exists
if d.Config.ForceDeregister {
log.Println("force_deregister is set, check if image already exists")
ImageList, err := conn.V3.ListAllImage(ctx, fmt.Sprintf("name==%s", name))
resp, err := conn.V3.ListAllImage(ctx, "")
if err != nil {
return nil, fmt.Errorf("error while ListAllImage, %s", err.Error())
}
if *ImageList.Metadata.TotalMatches == 0 {

entities := resp.Entities

found := make([]*v3.ImageIntentResponse, 0)
for _, v := range entities {
if *v.Spec.Name == name {
found = append(found, v)
}
}

if len(found) == 0 {
log.Println("image with given Name not found, no need to deregister")
} else if *ImageList.Metadata.TotalMatches > 1 {
} else if len(found) > 1 {
log.Println("more than one image with given Name found, will not deregister")
} else if *ImageList.Metadata.TotalMatches == 1 {
} else if len(found) == 1 {
log.Println("exactly one image with given Name found, will deregister")

resp, err := conn.V3.DeleteImage(ctx, *ImageList.Entities[0].Metadata.UUID)
resp, err := conn.V3.DeleteImage(ctx, *found[0].Metadata.UUID)
if err != nil {
return nil, fmt.Errorf("error while Deleting Image, %s", err.Error())
}

log.Printf("deleting image %s...\n", *ImageList.Entities[0].Metadata.UUID)
log.Printf("deleting image %s...\n", *found[0].Metadata.UUID)
err = checkTask(ctx, conn, resp.Status.ExecutionContext.TaskUUID.(string))

if err != nil {
Expand Down Expand Up @@ -1049,7 +1048,3 @@ func (d *NutanixDriver) SaveVMDisk(ctx context.Context, diskUUID string, index i
}

}

func getEmptyClientSideFilter() []*client.AdditionalFilter {
return make([]*client.AdditionalFilter, 0)
}
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

var (
// Version is the main version number that is being run at the moment.
Version = "0.9.3"
Version = "0.9.4"

// VersionPrerelease is A pre-release marker for the Version. If this is ""
// (empty string) then it means that it is a final release. Otherwise, this
Expand Down

0 comments on commit f0dd188

Please sign in to comment.