summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloud.go75
1 files changed, 44 insertions, 31 deletions
diff --git a/cloud.go b/cloud.go
index 76e7e5c..d177320 100644
--- a/cloud.go
+++ b/cloud.go
@@ -4,89 +4,102 @@ import (
"context"
"errors"
"fmt"
+
"go.wit.com/lib/protobuf/virtbuf"
)
-// CloudClusterManager is a concrete implementation of the ClusterManager interface.
-type CloudClusterManager struct {
+var me context.Context
+var myClient CloudAPIClient
+
+// 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 CloudAPIClient
+ cluster *virtbuf.NewCluster
}
// CloudAPIClient defines the methods required from the API client.
// This is useful if you want to mock this client for testing.
type CloudAPIClient interface {
- GetClusterByName(ctx context.Context, name string) (*virtbuf.NewCluster, error)
+ 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)
}
-// NewCloudClusterManager creates a new CloudClusterManager with the provided API client.
-func NewCloudClusterManager(client CloudAPIClient) *CloudClusterManager {
- return &CloudClusterManager{client: client}
+func NewCloud() *CloudManager {
+ // client := NewRealCloudAPIClient() // This should be replaced with a real implementation
+ clusterManager := NewCloudManager(myClient)
+
+ me = context.Background()
+ return clusterManager
+}
+
+// NewCloudManager creates a new CloudManager with the provided API client.
+func NewCloudManager(client CloudAPIClient) *CloudManager {
+ return &CloudManager{client: client}
}
// FindByName retrieves a cluster by name.
-func (m *CloudClusterManager) FindByName(ctx context.Context, name string) (*virtbuf.NewCluster, error) {
- cluster, err := m.client.GetClusterByName(ctx, 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)
}
- return cluster, nil
+ return d, nil
}
// Start initiates the startup process for the specified cluster.
-func (m *CloudClusterManager) Start(ctx context.Context, cluster *virtbuf.NewCluster) error {
+func (m *CloudManager) Start(ctx context.Context, cluster *virtbuf.NewCluster) error {
if cluster == nil {
return errors.New("cluster cannot be nil")
}
/*
- err := m.client.StartCluster(ctx, cluster.Id)
- if err != nil {
- return fmt.Errorf("error starting cluster %q: %w", cluster.Id, err)
- }
+ err := m.client.StartCluster(ctx, cluster.Id)
+ if err != nil {
+ return fmt.Errorf("error starting cluster %q: %w", cluster.Id, err)
+ }
*/
return nil
}
// Stop halts the specified cluster.
-func (m *CloudClusterManager) Stop(ctx context.Context, cluster *virtbuf.NewCluster) error {
+func (m *CloudManager) Stop(ctx context.Context, cluster *virtbuf.NewCluster) error {
if cluster == nil {
return errors.New("cluster cannot be nil")
}
/*
- err := m.client.StopCluster(ctx, cluster.Id)
- if err != nil {
- return fmt.Errorf("error stopping cluster %q: %w", cluster.Id, err)
- }
+ err := m.client.StopCluster(ctx, cluster.Id)
+ if err != nil {
+ return fmt.Errorf("error stopping cluster %q: %w", cluster.Id, err)
+ }
*/
return nil
}
// List retrieves all available clusters.
-func (m *CloudClusterManager) List(ctx context.Context) ([]*virtbuf.NewCluster, error) {
+func (m *CloudManager) List(ctx context.Context) ([]*virtbuf.NewCluster, error) {
/*
- clusters, err := m.client.ListClusters(ctx)
- if err != nil {
- return nil, fmt.Errorf("error listing clusters: %w", err)
- }
- return clusters, nil
+ clusters, err := m.client.ListClusters(ctx)
+ if err != nil {
+ return nil, fmt.Errorf("error listing clusters: %w", err)
+ }
+ return clusters, nil
*/
return nil, errors.New("List not done yet")
}
// Status checks the current status of a specified cluster.
-func (m *CloudClusterManager) Status(ctx context.Context, cluster *virtbuf.NewCluster) (string, error) {
+func (m *CloudManager) Status(ctx context.Context, cluster *virtbuf.NewCluster) (string, error) {
if cluster == nil {
return "", errors.New("cluster cannot be nil")
}
/*
- status, err := m.client.GetClusterStatus(ctx, cluster.Id)
- if err != nil {
- return "", fmt.Errorf("error getting status of cluster %q: %w", cluster.Id, err)
- }
+ status, err := m.client.GetClusterStatus(ctx, cluster.Id)
+ if err != nil {
+ return "", fmt.Errorf("error getting status of cluster %q: %w", cluster.Id, err)
+ }
*/
return "", nil
}