1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
11 "git.curoverse.com/arvados.git/sdk/go/arvados"
12 "golang.org/x/crypto/ssh"
15 // A RateLimitError should be returned by an InstanceSet when the
16 // cloud service indicates it is rejecting all API calls for some time
18 type RateLimitError interface {
19 // Time before which the caller should expect requests to
21 EarliestRetry() time.Time
25 // A QuotaError should be returned by an InstanceSet when the cloud
26 // service indicates the account cannot create more VMs than already
28 type QuotaError interface {
29 // If true, don't create more instances until some existing
30 // instances are destroyed. If false, don't handle the error
36 type InstanceSetID string
37 type InstanceTags map[string]string
38 type InstanceID string
41 // An Executor executes commands on an ExecutorTarget.
42 type Executor interface {
43 // Update the set of private keys used to authenticate to
45 SetSigners(...ssh.Signer)
47 // Set the target used for subsequent command executions.
48 SetTarget(ExecutorTarget)
50 // Return the current target.
51 Target() ExecutorTarget
53 // Execute a shell command and return the resulting stdout and
54 // stderr. stdin can be nil.
55 Execute(cmd string, stdin io.Reader) (stdout, stderr []byte, err error)
58 // An ExecutorTarget is a remote command execution service.
59 type ExecutorTarget interface {
60 // SSH server hostname or IP address, or empty string if
61 // unknown while instance is booting.
64 // Return nil if the given public key matches the instance's
65 // SSH server key. If the provided Dialer is not nil,
66 // VerifyHostKey can use it to make outgoing network
67 // connections from the instance -- e.g., to use the cloud's
68 // "this instance's metadata" API.
69 VerifyHostKey(ssh.PublicKey, *ssh.Client) error
72 // Instance is implemented by the provider-specific instance types.
73 type Instance interface {
76 // ID returns the provider's instance ID. It must be stable
77 // for the life of the instance.
80 // String typically returns the cloud-provided instance ID.
83 // Cloud provider's "instance type" ID. Matches a ProviderType
84 // in the cluster's InstanceTypes configuration.
90 // Replace tags with the given tags
91 SetTags(InstanceTags) error
97 // An InstanceSet manages a set of VM instances created by an elastic
98 // cloud provider like AWS, GCE, or Azure.
100 // All public methods of an InstanceSet, and all public methods of the
101 // instances it returns, are goroutine safe.
102 type InstanceSet interface {
103 // Create a new instance. If supported by the driver, add the
104 // provided public key to /root/.ssh/authorized_keys.
106 // The returned error should implement RateLimitError and
107 // QuotaError where applicable.
108 Create(arvados.InstanceType, ImageID, InstanceTags, ssh.PublicKey) (Instance, error)
110 // Return all instances, including ones that are booting or
111 // shutting down. Optionally, filter out nodes that don't have
112 // all of the given InstanceTags (the caller will ignore these
115 // An instance returned by successive calls to Instances() may
116 // -- but does not need to -- be represented by the same
117 // Instance object each time. Thus, the caller is responsible
118 // for de-duplicating the returned instances by comparing the
119 // InstanceIDs returned by the instances' ID() methods.
120 Instances(InstanceTags) ([]Instance, error)
122 // Stop any background tasks and release other resources.
126 // A Driver returns an InstanceSet that uses the given InstanceSetID
127 // and driver-dependent configuration parameters.
129 // The supplied id will be of the form "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
130 // where each z can be any alphanum. The returned InstanceSet must use
131 // this id to tag long-lived cloud resources that it creates, and must
132 // assume control of any existing resources that are tagged with the
133 // same id. Tagging can be accomplished by including the ID in
134 // resource names, using the cloud provider's tagging feature, or any
135 // other mechanism. The tags must be visible to another instance of
136 // the same driver running on a different host.
138 // The returned InstanceSet must ignore existing resources that are
139 // visible but not tagged with the given id, except that it should log
140 // a summary of such resources -- only once -- when it starts
141 // up. Thus, two identically configured InstanceSets running on
142 // different hosts with different ids should log about the existence
143 // of each other's resources at startup, but will not interfere with
148 // type exampleInstanceSet struct {
153 // type exampleDriver struct {}
155 // func (*exampleDriver) InstanceSet(config map[string]interface{}, id InstanceSetID) (InstanceSet, error) {
156 // var is exampleInstanceSet
157 // if err := mapstructure.Decode(config, &is); err != nil {
164 // var _ = registerCloudDriver("example", &exampleDriver{})
165 type Driver interface {
166 InstanceSet(config map[string]interface{}, id InstanceSetID) (InstanceSet, error)
169 // DriverFunc makes a Driver using the provided function as its
170 // InstanceSet method. This is similar to http.HandlerFunc.
171 func DriverFunc(fn func(config map[string]interface{}, id InstanceSetID) (InstanceSet, error)) Driver {
172 return driverFunc(fn)
175 type driverFunc func(config map[string]interface{}, id InstanceSetID) (InstanceSet, error)
177 func (df driverFunc) InstanceSet(config map[string]interface{}, id InstanceSetID) (InstanceSet, error) {
178 return df(config, id)