-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinstance.go
More file actions
175 lines (154 loc) · 6.08 KB
/
Copy pathinstance.go
File metadata and controls
175 lines (154 loc) · 6.08 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package v1
import (
"context"
"fmt"
"time"
"github.com/alecthomas/units"
)
type CloudInstanceReader interface {
GetInstance(ctx context.Context, id CloudProviderInstanceID) (*Instance, error)
ListInstances(ctx context.Context, args ListInstancesArgs) ([]Instance, error)
GetInstancePollTime() time.Duration
}
type CloudCreateTerminateInstance interface {
// CreateInstance expects an instance object to exist if successful, and no instance to exist if there is ANY error
// CloudClient Implementers: ensure that the instance is terminated if there is an error
// Public ip is not always returned from create, but will exist when instance is in running state
CreateInstance(ctx context.Context, attrs CreateInstanceAttrs) (*Instance, error)
TerminateInstance(ctx context.Context, instanceID CloudProviderInstanceID) error // may or may not be locationally scoped
GetMaxCreateRequestsPerMinute() int
CloudInstanceType
CloudInstanceReader
}
type CloudStopStartInstance interface {
StopInstance(ctx context.Context, instanceID CloudProviderInstanceID) error
StartInstance(ctx context.Context, instanceID CloudProviderInstanceID) error
}
type CloudRebootInstance interface {
RebootInstance(ctx context.Context, instanceID CloudProviderInstanceID) error
}
type CloudChangeInstanceType interface {
ChangeInstanceType(ctx context.Context, instanceID CloudProviderInstanceID, instanceType string) error
}
type CloudInstanceTags interface {
UpdateInstanceTags(ctx context.Context, args UpdateInstanceTagsArgs) error
}
// this is used by the control plane to efficiently update instances
type UpdateHandler interface {
MergeInstanceForUpdate(currInst Instance, newInst Instance) Instance
MergeInstanceTypeForUpdate(currIt InstanceType, newIt InstanceType) InstanceType
}
type Instance struct {
Name string
RefID string
CloudCredRefID string // cloudCred used to create the Instance
CreatedAt time.Time
CloudID CloudProviderInstanceID
IPAllocationID *string
PublicIP string // Public ip is not always returned from create, but will exist when instance is in running state
PublicDNS string
PrivateIP string
Hostname string
ImageID string
InstanceType string
DiskSize units.Base2Bytes // TODO: deprecate in favor of DiskSizeByteValue
DiskSizeBytes Bytes
VolumeType string
PubKeyFingerprint string
SSHUser string
SSHPort int
Status Status
MetaEndpointEnabled bool
MetaTagsEnabled bool
VPCID string
SubnetID string
Spot bool
FirewallRules FirewallRules
RetiredAt *time.Time
RetireTimeout *time.Duration
LastStopTransitionTime *time.Time
Location string
SubLocation string
Tags Tags
Stoppable bool
Rebootable bool
IsContainer bool
UserPrivilegeEscalationDisabled bool
NotPrivileged bool
InstanceTypeID InstanceTypeID
AdditionalDisks []Disk
// As of 08/26/2024 only used for Launchpad cloud.
// Because there is port forwarding from a GPU node to Bastion node,
// there is port mappings from the GPU node itself to the Bastion node.
// i.e. Verb SSH port 2222 is mapped to 2022 on the Bastion node
InternalPortMappings []PortMapping
}
type Status struct {
LifecycleStatus LifecycleStatus
Messages []string
}
type LifecycleStatus string
const (
LifecycleStatusPending LifecycleStatus = "pending"
LifecycleStatusRunning LifecycleStatus = "running"
LifecycleStatusStopping LifecycleStatus = "stopping"
LifecycleStatusStopped LifecycleStatus = "stopped"
LifecycleStatusSuspending LifecycleStatus = "suspending"
LifecycleStatusSuspended LifecycleStatus = "suspended"
LifecycleStatusTerminating LifecycleStatus = "terminating"
LifecycleStatusTerminated LifecycleStatus = "terminated"
LifecycleStatusFailed LifecycleStatus = "failed"
)
const (
PendingToRunningTimeout = 20 * time.Minute
RunningToStoppedTimeout = 10 * time.Minute
StoppedToRunningTimeout = 20 * time.Minute
RunningToTerminatedTimeout = 20 * time.Minute
)
type CloudProviderInstanceID string
type ListInstancesArgs struct {
InstanceIDs []CloudProviderInstanceID
TagFilters map[string][]string
Locations LocationsFilter
}
type CreateInstanceAttrs struct {
Location string
SubLocation string
Name string
RefID string // required also can be used for idempotency
VPCID string
SubnetID string
PublicKey string // must be in openssh format
KeyPairName *string
ImageID string
InstanceType string
UserDataBase64 string
DiskSize units.Base2Bytes // TODO: deprecate in favor of DiskSizeByteValue
DiskSizeBytes Bytes
Tags Tags
FirewallRules FirewallRules
UseSpot bool
UsePersistentIP bool
UseMultiAttachVolume bool
RetireTimeout *time.Duration
// Additional Environment Variables.
// Note: As of May 2024, the only cloud provider we have this implemented for
// is the Akash provider.
AdditionalEnvVars map[string]string
AdditionalDisks []Disk
}
type UpdateInstanceTagsArgs struct {
InstanceID CloudProviderInstanceID
Tags Tags
}
func makeDebuggableName(name string) (string, error) {
pt, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
return "", err
}
if name == "" {
name = "test"
}
return fmt.Sprintf("%s-%s", name, time.Now().In(pt).Format("2006-01-02-15-04-05")), nil
}
const RunningSSHTimeout = 10 * time.Minute