hmm. try this I guess
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
97050dcb9d
commit
15efe46bc4
51
cloud.go
51
cloud.go
|
@ -3,55 +3,54 @@ package virtigolib
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"go.wit.com/lib/protobuf/virtbuf"
|
"go.wit.com/lib/protobuf/virtbuf"
|
||||||
)
|
)
|
||||||
|
|
||||||
var me context.Context
|
var ctx context.Context
|
||||||
var myClient CloudAPIClient
|
var myClient cloudAPI
|
||||||
|
|
||||||
// CloudManager is a concrete implementation of the Manager interface.
|
// CloudManager is a concrete implementation of the Manager interface.
|
||||||
type CloudManager struct {
|
type CloudManager struct {
|
||||||
// client represents a hypothetical API client for interacting with the cloud.
|
// client represents a hypothetical API client for interacting with the cloud.
|
||||||
client CloudAPIClient
|
client cloudAPI
|
||||||
cluster *virtbuf.NewCluster
|
cluster *virtbuf.NewCluster
|
||||||
}
|
}
|
||||||
|
|
||||||
// CloudAPIClient defines the methods required from the API client.
|
// cloudAPIt defines the methods required from the API client.
|
||||||
// This is useful if you want to mock this client for testing.
|
// This is useful if you want to mock this client for testing.
|
||||||
type CloudAPIClient interface {
|
type cloudAPI interface {
|
||||||
GetDropletByName(name string) (*virtbuf.Droplet, error)
|
GetDropletByName(name string) *virtbuf.Droplet
|
||||||
StartCluster(ctx context.Context, clusterID string) error
|
|
||||||
StopCluster(ctx context.Context, clusterID string) error
|
StartCluster(clusterID string) error
|
||||||
ListClusters(ctx context.Context) ([]*virtbuf.NewCluster, error)
|
StopCluster(clusterID string) error
|
||||||
GetClusterStatus(ctx context.Context, clusterID string) (string, error)
|
ListDroplets() ([]*virtbuf.Droplet, error)
|
||||||
|
|
||||||
|
GetClusterStatus(clusterID string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCloud() *CloudManager {
|
func NewCloud() *CloudManager {
|
||||||
// client := NewRealCloudAPIClient() // This should be replaced with a real implementation
|
// clusterManager := NewCloudManager(myClient)
|
||||||
clusterManager := NewCloudManager(myClient)
|
newCloudManager := &CloudManager{client: myClient}
|
||||||
|
|
||||||
me = context.Background()
|
ctx = context.Background()
|
||||||
return clusterManager
|
|
||||||
|
return newCloudManager
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCloudManager creates a new CloudManager with the provided API client.
|
// NewCloudManager creates a new CloudManager with the provided API client.
|
||||||
func NewCloudManager(client CloudAPIClient) *CloudManager {
|
// func NewCloudManager(client cloudAPI) *CloudManager {
|
||||||
return &CloudManager{client: client}
|
// return &CloudManager{client: client}
|
||||||
}
|
// }
|
||||||
|
|
||||||
// FindByName retrieves a cluster by name.
|
// FindByName retrieves a cluster by name.
|
||||||
func (m *CloudManager) FindDropletByName(name string) (*virtbuf.Droplet, error) {
|
func (m *CloudManager) FindDropletByName(name string) (*virtbuf.Droplet, error) {
|
||||||
d, err := m.client.GetDropletByName(name)
|
d := m.cluster.FindDropletByName(name)
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error finding cluster by name %q: %w", name, err)
|
|
||||||
}
|
|
||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start initiates the startup process for the specified cluster.
|
// Start initiates the startup process for the specified cluster.
|
||||||
func (m *CloudManager) Start(ctx context.Context, cluster *virtbuf.NewCluster) error {
|
func (m *CloudManager) Start(cluster *virtbuf.NewCluster) error {
|
||||||
if cluster == nil {
|
if cluster == nil {
|
||||||
return errors.New("cluster cannot be nil")
|
return errors.New("cluster cannot be nil")
|
||||||
}
|
}
|
||||||
|
@ -65,7 +64,7 @@ func (m *CloudManager) Start(ctx context.Context, cluster *virtbuf.NewCluster) e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop halts the specified cluster.
|
// Stop halts the specified cluster.
|
||||||
func (m *CloudManager) Stop(ctx context.Context, cluster *virtbuf.NewCluster) error {
|
func (m *CloudManager) Stop(cluster *virtbuf.NewCluster) error {
|
||||||
if cluster == nil {
|
if cluster == nil {
|
||||||
return errors.New("cluster cannot be nil")
|
return errors.New("cluster cannot be nil")
|
||||||
}
|
}
|
||||||
|
@ -79,7 +78,7 @@ func (m *CloudManager) Stop(ctx context.Context, cluster *virtbuf.NewCluster) er
|
||||||
}
|
}
|
||||||
|
|
||||||
// List retrieves all available clusters.
|
// List retrieves all available clusters.
|
||||||
func (m *CloudManager) List(ctx context.Context) ([]*virtbuf.NewCluster, error) {
|
func (m *CloudManager) List() ([]*virtbuf.NewCluster, error) {
|
||||||
/*
|
/*
|
||||||
clusters, err := m.client.ListClusters(ctx)
|
clusters, err := m.client.ListClusters(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -91,7 +90,7 @@ func (m *CloudManager) List(ctx context.Context) ([]*virtbuf.NewCluster, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status checks the current status of a specified cluster.
|
// Status checks the current status of a specified cluster.
|
||||||
func (m *CloudManager) Status(ctx context.Context, cluster *virtbuf.NewCluster) (string, error) {
|
func (m *CloudManager) Status(cluster *virtbuf.NewCluster) (string, error) {
|
||||||
if cluster == nil {
|
if cluster == nil {
|
||||||
return "", errors.New("cluster cannot be nil")
|
return "", errors.New("cluster cannot be nil")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue