-
Notifications
You must be signed in to change notification settings - Fork 232
/
client.go
69 lines (57 loc) · 1.73 KB
/
client.go
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
package machine
import (
"context"
"time"
crcConfig "github.com/crc-org/crc/v2/pkg/crc/config"
"github.com/crc-org/crc/v2/pkg/crc/machine/state"
"github.com/crc-org/crc/v2/pkg/crc/machine/types"
"github.com/crc-org/crc/v2/pkg/crc/network"
crcPreset "github.com/crc-org/crc/v2/pkg/crc/preset"
"github.com/kofalt/go-memoize"
)
type Client interface {
GetName() string
GetConsoleURL() (*types.ConsoleResult, error)
ConnectionDetails() (*types.ConnectionDetails, error)
Delete() error
Exists() (bool, error)
PowerOff() error
Start(ctx context.Context, startConfig types.StartConfig) (*types.StartResult, error)
Status() (*types.ClusterStatusResult, error)
GetClusterLoad() (*types.ClusterLoadResult, error)
Stop() (state.State, error)
IsRunning() (bool, error)
GenerateBundle(forceStop bool) error
GetPreset() crcPreset.Preset
}
type client struct {
name string
debug bool
config crcConfig.Storage
diskDetails *memoize.Memoizer
ramDetails *memoize.Memoizer
}
func NewClient(name string, debug bool, config crcConfig.Storage) Client {
return &client{
name: name,
debug: debug,
config: config,
diskDetails: memoize.NewMemoizer(time.Minute, 5*time.Minute),
ramDetails: memoize.NewMemoizer(30*time.Second, 2*time.Minute),
}
}
func (client *client) GetName() string {
return client.name
}
func (client *client) GetPreset() crcPreset.Preset {
return crcConfig.GetPreset(client.config)
}
func (client *client) useVSock() bool {
return client.networkMode() == network.UserNetworkingMode
}
func (client *client) networkMode() network.Mode {
return crcConfig.GetNetworkMode(client.config)
}
func (client *client) monitoringEnabled() bool {
return client.config.Get(crcConfig.EnableClusterMonitoring).AsBool()
}