github.com/openshift/installer@v1.4.17/pkg/types/nutanix/client.go (about)

     1  package nutanix
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"strconv"
     7  	"time"
     8  
     9  	nutanixclient "github.com/nutanix-cloud-native/prism-go-client"
    10  	nutanixclientv3 "github.com/nutanix-cloud-native/prism-go-client/v3"
    11  )
    12  
    13  // CreateNutanixClient creates a Nutanix V3 Client.
    14  func CreateNutanixClient(ctx context.Context, prismCentral, port, username, password string) (*nutanixclientv3.Client, error) {
    15  	ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
    16  	defer cancel()
    17  
    18  	cred := nutanixclient.Credentials{
    19  		URL:      fmt.Sprintf("%s:%s", prismCentral, port),
    20  		Username: username,
    21  		Password: password,
    22  		Port:     port,
    23  		Endpoint: prismCentral,
    24  	}
    25  
    26  	return nutanixclientv3.NewV3Client(cred)
    27  }
    28  
    29  // CreateNutanixClientFromPlatform creates a Nutanix V3 clinet based on the platform configuration.
    30  func CreateNutanixClientFromPlatform(platform *Platform) (*nutanixclientv3.Client, error) {
    31  	return CreateNutanixClient(context.TODO(),
    32  		platform.PrismCentral.Endpoint.Address,
    33  		strconv.Itoa(int(platform.PrismCentral.Endpoint.Port)),
    34  		platform.PrismCentral.Username,
    35  		platform.PrismCentral.Password)
    36  }