summaryrefslogtreecommitdiff
path: root/cloud.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-06 04:23:13 -0600
committerJeff Carr <[email protected]>2024-11-06 04:23:13 -0600
commit15efe46bc4f99975bab107c5387b8c8a70e0020a (patch)
tree7a31b8d1cef503eb51cdbc65e655ae8bc2dfecf2 /cloud.go
parent97050dcb9db146c4e0e7a747a612faf3f3945459 (diff)
hmm. try this I guess
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'cloud.go')
-rw-r--r--cloud.go51
1 files changed, 25 insertions, 26 deletions
diff --git a/cloud.go b/cloud.go
index d177320..6f601cf 100644
--- a/cloud.go
+++ b/cloud.go
@@ -3,55 +3,54 @@ package virtigolib
import (
"context"
"errors"
- "fmt"
"go.wit.com/lib/protobuf/virtbuf"
)
-var me context.Context
-var myClient CloudAPIClient
+var ctx context.Context
+var myClient cloudAPI
// CloudManager is a concrete implementation of the Manager interface.
type CloudManager struct {
// client represents a hypothetical API client for interacting with the cloud.
- client CloudAPIClient
+ client cloudAPI
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.
-type CloudAPIClient interface {
- GetDropletByName(name string) (*virtbuf.Droplet, error)
- StartCluster(ctx context.Context, clusterID string) error
- StopCluster(ctx context.Context, clusterID string) error
- ListClusters(ctx context.Context) ([]*virtbuf.NewCluster, error)
- GetClusterStatus(ctx context.Context, clusterID string) (string, error)
+type cloudAPI interface {
+ GetDropletByName(name string) *virtbuf.Droplet
+
+ StartCluster(clusterID string) error
+ StopCluster(clusterID string) error
+ ListDroplets() ([]*virtbuf.Droplet, error)
+
+ GetClusterStatus(clusterID string) (string, error)
}
func NewCloud() *CloudManager {
- // client := NewRealCloudAPIClient() // This should be replaced with a real implementation
- clusterManager := NewCloudManager(myClient)
+ // clusterManager := NewCloudManager(myClient)
+ newCloudManager := &CloudManager{client: myClient}
+
+ ctx = context.Background()
- me = context.Background()
- return clusterManager
+ return newCloudManager
}
// NewCloudManager creates a new CloudManager with the provided API client.
-func NewCloudManager(client CloudAPIClient) *CloudManager {
- return &CloudManager{client: client}
-}
+// func NewCloudManager(client cloudAPI) *CloudManager {
+// return &CloudManager{client: client}
+// }
// FindByName retrieves a cluster by name.
func (m *CloudManager) FindDropletByName(name string) (*virtbuf.Droplet, error) {
- d, err := m.client.GetDropletByName(name)
- if err != nil {
- return nil, fmt.Errorf("error finding cluster by name %q: %w", name, err)
- }
+ d := m.cluster.FindDropletByName(name)
return d, nil
}
// 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 {
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.
-func (m *CloudManager) Stop(ctx context.Context, cluster *virtbuf.NewCluster) error {
+func (m *CloudManager) Stop(cluster *virtbuf.NewCluster) error {
if cluster == 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.
-func (m *CloudManager) List(ctx context.Context) ([]*virtbuf.NewCluster, error) {
+func (m *CloudManager) List() ([]*virtbuf.NewCluster, error) {
/*
clusters, err := m.client.ListClusters(ctx)
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.
-func (m *CloudManager) Status(ctx context.Context, cluster *virtbuf.NewCluster) (string, error) {
+func (m *CloudManager) Status(cluster *virtbuf.NewCluster) (string, error) {
if cluster == nil {
return "", errors.New("cluster cannot be nil")
}