Skip to content

Commit

Permalink
Set region
Browse files Browse the repository at this point in the history
  • Loading branch information
eliorerz committed Feb 17, 2025
1 parent 3584490 commit fa1957c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,10 @@ func getClusterRegion(cd *hivev1.ClusterDeployment) string {
return cd.Spec.Platform.GCP.Region
case cd.Spec.Platform.IBMCloud != nil:
return cd.Spec.Platform.IBMCloud.Region
case cd.Spec.Platform.Nutanix != nil:
if len(cd.Spec.Platform.Nutanix.PrismElements) == 1 {
return cd.Spec.Platform.Nutanix.PrismElements[0].Name
}
}
return regionUnknown
}
Expand Down
53 changes: 53 additions & 0 deletions pkg/nutanixclient/client.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,58 @@
package nutanixclient

import (
"context"
"fmt"
"strings"

nutanixClient "github.com/nutanix-cloud-native/prism-go-client"
nutanixClientV3 "github.com/nutanix-cloud-native/prism-go-client/v3"
"github.com/openshift/hive/apis/hive/v1/nutanix"
)

func NewNutanixClient(nutanixProvider *nutanix.Platform, username, password string) (*nutanixClientV3.Client, error) {
credentials := nutanixClient.Credentials{
Username: username,
Password: password,
Endpoint: nutanixProvider.PrismCentral.Endpoint.Address,
Port: string(nutanixProvider.PrismCentral.Endpoint.Port),
}

client, err := nutanixClientV3.NewV3Client(credentials)
if err != nil {
return nil, err
}
return client, err

}

func GetPrismCentralClusterName(client *nutanixClientV3.Client) (string, error) {
clusterList, err := client.V3.ListAllCluster(context.TODO(), "")
if err != nil {
return "", err
}

foundPCs := make([]*nutanixClientV3.ClusterIntentResponse, 0)
for _, cl := range clusterList.Entities {
if cl.Status != nil && cl.Status.Resources != nil && cl.Status.Resources.Config != nil {
serviceList := cl.Status.Resources.Config.ServiceList
for _, svc := range serviceList {
if svc != nil && strings.ToUpper(*svc) == "PRISM_CENTRAL" {
foundPCs = append(foundPCs, cl)
}
}
}
}
numFoundPCs := len(foundPCs)
if numFoundPCs == 1 {
return *foundPCs[0].Spec.Name, nil
}
if len(foundPCs) == 0 {
return "", fmt.Errorf("failed to retrieve Prism Central cluster")
}
return "", fmt.Errorf("found more than one Prism Central cluster: %v", numFoundPCs)
}

//import (
// "context"
// "fmt"
Expand Down

0 comments on commit fa1957c

Please sign in to comment.