|
6 | 6 | "strings"
|
7 | 7 |
|
8 | 8 | prismgoclient "github.com/nutanix-cloud-native/prism-go-client"
|
9 |
| - "github.com/nutanix-cloud-native/prism-go-client/utils" |
10 | 9 | v3 "github.com/nutanix-cloud-native/prism-go-client/v3"
|
11 | 10 |
|
12 | 11 | "github.com/aws/eks-anywhere/pkg/providers/nutanix"
|
@@ -44,30 +43,39 @@ func NewPrismClient(endpoint, port string, insecure bool) (PrismClient, error) {
|
44 | 43 |
|
45 | 44 | // GetImageUUIDFromName retrieves the image uuid from the given image name.
|
46 | 45 | func (c *client) GetImageUUIDFromName(ctx context.Context, imageName string) (*string, error) {
|
47 |
| - res, err := c.V3.ListImage(ctx, &v3.DSMetadata{ |
48 |
| - Filter: utils.StringPtr(fmt.Sprintf("name==%s", imageName)), |
49 |
| - }) |
50 |
| - if err != nil || len(res.Entities) == 0 { |
| 46 | + res, err := c.V3.ListAllImage(ctx, "") |
| 47 | + if err != nil { |
| 48 | + return nil, fmt.Errorf("failed to list images: %v", err) |
| 49 | + } |
| 50 | + |
| 51 | + images := make([]*v3.ImageIntentResponse, 0) |
| 52 | + |
| 53 | + for _, image := range res.Entities { |
| 54 | + if image.Spec.Name != nil && *image.Spec.Name == imageName { |
| 55 | + images = append(images, image) |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + if len(images) == 0 { |
51 | 60 | return nil, fmt.Errorf("failed to find image by name %q: %v", imageName, err)
|
52 | 61 | }
|
53 | 62 |
|
54 |
| - if len(res.Entities) > 1 { |
55 |
| - return nil, fmt.Errorf("found more than one (%v) image with name %q", len(res.Entities), imageName) |
| 63 | + if len(images) > 1 { |
| 64 | + return nil, fmt.Errorf("found more than one (%v) image with name %q", len(images), imageName) |
56 | 65 | }
|
57 | 66 |
|
58 |
| - return res.Entities[0].Metadata.UUID, nil |
| 67 | + return images[0].Metadata.UUID, nil |
59 | 68 | }
|
60 | 69 |
|
61 | 70 | // GetClusterUUIDFromName retrieves the cluster uuid from the given cluster name.
|
62 | 71 | //
|
63 | 72 | //nolint:gocyclo
|
64 | 73 | func (c *client) GetClusterUUIDFromName(ctx context.Context, clusterName string) (*string, error) {
|
65 |
| - res, err := c.V3.ListCluster(ctx, &v3.DSMetadata{ |
66 |
| - Filter: utils.StringPtr(fmt.Sprintf("name==%s", clusterName)), |
67 |
| - }) |
| 74 | + res, err := c.V3.ListAllCluster(ctx, "") |
68 | 75 | if err != nil {
|
69 |
| - return nil, fmt.Errorf("failed to find cluster by name %q: %v", clusterName, err) |
| 76 | + return nil, fmt.Errorf("failed to list clusters: %v", err) |
70 | 77 | }
|
| 78 | + |
71 | 79 | entities := make([]*v3.ClusterIntentResponse, 0)
|
72 | 80 | for _, entity := range res.Entities {
|
73 | 81 | if entity.Status != nil && entity.Status.Resources != nil && entity.Status.Resources.Config != nil {
|
@@ -97,16 +105,26 @@ func (c *client) GetClusterUUIDFromName(ctx context.Context, clusterName string)
|
97 | 105 |
|
98 | 106 | // GetSubnetUUIDFromName retrieves the subnet uuid from the given subnet name.
|
99 | 107 | func (c *client) GetSubnetUUIDFromName(ctx context.Context, subnetName string) (*string, error) {
|
100 |
| - res, err := c.V3.ListSubnet(ctx, &v3.DSMetadata{ |
101 |
| - Filter: utils.StringPtr(fmt.Sprintf("name==%s", subnetName)), |
102 |
| - }) |
103 |
| - if err != nil || len(res.Entities) == 0 { |
| 108 | + res, err := c.V3.ListAllSubnet(ctx, "", nil) |
| 109 | + if err != nil { |
| 110 | + return nil, fmt.Errorf("failed to list subnets: %v", err) |
| 111 | + } |
| 112 | + |
| 113 | + subnets := make([]*v3.SubnetIntentResponse, 0) |
| 114 | + |
| 115 | + for _, subnet := range res.Entities { |
| 116 | + if subnet.Spec.Name != nil && *subnet.Spec.Name == subnetName { |
| 117 | + subnets = append(subnets, subnet) |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + if len(subnets) == 0 { |
104 | 122 | return nil, fmt.Errorf("failed to find subnet by name %q: %v", subnetName, err)
|
105 | 123 | }
|
106 | 124 |
|
107 |
| - if len(res.Entities) > 1 { |
108 |
| - return nil, fmt.Errorf("found more than one (%v) subnet with name %q", len(res.Entities), subnetName) |
| 125 | + if len(subnets) > 1 { |
| 126 | + return nil, fmt.Errorf("found more than one (%v) subnet with name %q", len(subnets), subnetName) |
109 | 127 | }
|
110 | 128 |
|
111 |
| - return res.Entities[0].Metadata.UUID, nil |
| 129 | + return subnets[0].Metadata.UUID, nil |
112 | 130 | }
|
0 commit comments