-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
interfaces.go
152 lines (111 loc) · 4.43 KB
/
interfaces.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
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
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package spotinst
import (
"context"
"time"
)
type (
// InstanceGroup wraps a cloud-specific instance group object.
InstanceGroup interface {
// Id returns the ID of the InstanceGroup.
Id() string
// Type returns the type of the InstanceGroup.
Type() InstanceGroupType
// Name returns the name of the InstanceGroup.
Name() string
// MinSize returns the minimum size of the InstanceGroup.
MinSize() int
// MaxSize returns the maximum size of the InstanceGroup.
MaxSize() int
// CreatedAt returns the timestamp when the InstanceGroup has been created.
CreatedAt() time.Time
// UpdatedAt returns the timestamp when the InstanceGroup has been updated.
UpdatedAt() time.Time
// Obj returns the raw object which is a cloud-specific implementation.
Obj() interface{}
}
// Instance wraps a cloud-specific instance object.
Instance interface {
// Id returns the ID of the instance.
Id() string
// CreatedAt returns the timestamp when the Instance has been created.
CreatedAt() time.Time
// Obj returns the raw object which is a cloud-specific implementation.
Obj() interface{}
}
// LaunchSpec wraps a cloud-specific launch specification object.
LaunchSpec interface {
// Id returns the ID of the LaunchSpec.
Id() string
// Name returns the name of the LaunchSpec.
Name() string
// OceanId returns the ID of the Ocean instance group.
OceanId() string
// CreatedAt returns the timestamp when the LaunchSpec has been created.
CreatedAt() time.Time
// UpdatedAt returns the timestamp when the LaunchSpec has been updated.
UpdatedAt() time.Time
// Obj returns the raw object which is a cloud-specific implementation.
Obj() interface{}
}
// Cloud wraps all services provided by Spotinst.
Cloud interface {
// Elastigroups returns a new Elastigroup service.
Elastigroup() InstanceGroupService
// Ocean returns a new Ocean service.
Ocean() InstanceGroupService
// LaunchSpec returns a new LaunchSpec service.
LaunchSpec() LaunchSpecService
}
// InstanceGroupService wraps all common functionality for InstanceGroups.
InstanceGroupService interface {
// List returns a list of InstanceGroups.
List(ctx context.Context) ([]InstanceGroup, error)
// Create creates a new InstanceGroup and returns its ID.
Create(ctx context.Context, group InstanceGroup) (string, error)
// Read returns an existing InstanceGroup by ID.
Read(ctx context.Context, groupID string) (InstanceGroup, error)
// Update updates an existing InstanceGroup.
Update(ctx context.Context, group InstanceGroup) error
// Delete deletes an existing InstanceGroup by ID.
Delete(ctx context.Context, groupID string) error
// Detach removes one or more instances from the specified InstanceGroup.
Detach(ctx context.Context, groupID string, instanceIDs []string) error
// Instances returns a list of all instances that belong to specified InstanceGroup.
Instances(ctx context.Context, groupID string) ([]Instance, error)
}
// LaunchSpecService wraps all common functionality for LaunchSpecs.
LaunchSpecService interface {
// List returns a list of LaunchSpecs.
List(ctx context.Context, oceanID string) ([]LaunchSpec, error)
// Create creates a new LaunchSpec and returns its ID.
Create(ctx context.Context, spec LaunchSpec) (string, error)
// Read returns an existing LaunchSpec by ID.
Read(ctx context.Context, specID string) (LaunchSpec, error)
// Update updates an existing LaunchSpec.
Update(ctx context.Context, spec LaunchSpec) error
// Delete deletes an existing LaunchSpec by ID.
Delete(ctx context.Context, specID string) error
}
)
type ResourceType string
const (
ResourceTypeInstanceGroup ResourceType = "instancegroup"
ResourceTypeLaunchSpec ResourceType = "launchspec"
)
type InstanceGroupType string
const (
InstanceGroupElastigroup InstanceGroupType = "elastigroup"
InstanceGroupOcean InstanceGroupType = "ocean"
)