forked from evergreen-ci/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud_host.go
65 lines (53 loc) · 2.08 KB
/
cloud_host.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
package cloud
import (
"context"
"github.com/evergreen-ci/evergreen"
"github.com/evergreen-ci/evergreen/model/host"
"github.com/pkg/errors"
)
//CloudHost is a provider-agnostic host object that delegates methods
//like status checks, ssh options, DNS name checks, termination, etc. to the
//underlying provider's implementation.
type CloudHost struct {
Host *host.Host
KeyPath string
CloudMgr Manager
}
// GetCloudHost returns an instance of CloudHost wrapping the given model.Host,
// giving access to the provider-specific methods to manipulate on the host.
func GetCloudHost(ctx context.Context, host *host.Host, env evergreen.Environment) (*CloudHost, error) {
mgrOpts, err := GetManagerOptions(host.Distro)
if err != nil {
return nil, errors.Wrapf(err, "can't get ManagerOpts for '%s'", host.Id)
}
mgr, err := GetManager(ctx, env, mgrOpts)
if err != nil {
return nil, err
}
keyPath := ""
if host.Distro.SSHKey != "" {
keyPath = env.Settings().Keys[host.Distro.SSHKey]
}
return &CloudHost{host, keyPath, mgr}, nil
}
func (cloudHost *CloudHost) IsUp(ctx context.Context) (bool, error) {
return cloudHost.CloudMgr.IsUp(ctx, cloudHost.Host)
}
func (cloudHost *CloudHost) ModifyHost(ctx context.Context, opts host.HostModifyOptions) error {
return cloudHost.CloudMgr.ModifyHost(ctx, cloudHost.Host, opts)
}
func (cloudHost *CloudHost) TerminateInstance(ctx context.Context, user, reason string) error {
return cloudHost.CloudMgr.TerminateInstance(ctx, cloudHost.Host, user, reason)
}
func (cloudHost *CloudHost) StopInstance(ctx context.Context, user string) error {
return cloudHost.CloudMgr.StopInstance(ctx, cloudHost.Host, user)
}
func (cloudHost *CloudHost) StartInstance(ctx context.Context, user string) error {
return cloudHost.CloudMgr.StartInstance(ctx, cloudHost.Host, user)
}
func (cloudHost *CloudHost) GetInstanceStatus(ctx context.Context) (CloudStatus, error) {
return cloudHost.CloudMgr.GetInstanceStatus(ctx, cloudHost.Host)
}
func (cloudHost *CloudHost) GetDNSName(ctx context.Context) (string, error) {
return cloudHost.CloudMgr.GetDNSName(ctx, cloudHost.Host)
}