summaryrefslogtreecommitdiff
path: root/cloud.go
blob: e6f9ef23e6045c95b83acafc604b3db11700d8c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package virtigolib

// makes a Cluster interface which is:

// a number of hypervisors (the physical machines)
// a list of the virtual machines
// functions to start, stop, etc virtual machines

// virtual machines are often called droplets to make it easier to understand

import (
	"context"
	"errors"

	"go.wit.com/lib/protobuf/virtpb"
)

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  cloudAPI
	cluster *virtpb.OldCluster
}

// cloudAPIt defines the methods required from the API client.
// This is useful if you want to mock this client for testing.
type cloudAPI interface {
	GetDropletByName(name string) *virtpb.Droplet

	StartCluster(clusterID string) error
	StopCluster(clusterID string) error
	ListDroplets() ([]*virtpb.Droplet, error)

	GetClusterStatus(clusterID string) (string, error)
}

func NewCloud() *CloudManager {
	// client := virtpb.NewRealCloudAPIClient()
	// clusterManager := NewCloudManager(myClient)
	newCloudManager := &CloudManager{client: myClient}

	ctx = context.Background()

	return newCloudManager
}

// NewCloudManager creates a new CloudManager with the provided API client.
// func NewCloudManager(client cloudAPI) *CloudManager {
// 	return &CloudManager{client: client}
// }

// FindByName retrieves a cluster by name.
func (m *CloudManager) FindDropletByName(name string) (*virtpb.Droplet, error) {
	if m.cluster == nil {
		return nil, nil
	}
	d := m.cluster.FindDropletByName(name)
	return d, nil
}

// Start initiates the startup process for the specified cluster.
func (m *CloudManager) Start(cluster *virtpb.OldCluster) 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)
		}
	*/
	return nil
}

// Stop halts the specified cluster.
func (m *CloudManager) Stop(cluster *virtpb.OldCluster) 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)
		}
	*/
	return nil
}

// List retrieves all available clusters.
func (m *CloudManager) List() ([]*virtpb.OldCluster, error) {
	/*
		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 *CloudManager) Status(cluster *virtpb.OldCluster) (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)
		}
	*/
	return "", nil
}