@@ -20,37 +20,69 @@ const (
20
20
ImageStatusAvailable ImageStatus = "available"
21
21
)
22
22
23
+ // ImageRegionStatus represents the status of an Image's replica.
24
+ type ImageRegionStatus string
25
+
26
+ // ImageRegionStatus options start with ImageRegionStatus and
27
+ // include all Image replica statuses
28
+ const (
29
+ ImageRegionStatusAvailable ImageRegionStatus = "available"
30
+ ImageRegionStatusCreating ImageRegionStatus = "creating"
31
+ ImageRegionStatusPending ImageRegionStatus = "pending"
32
+ ImageRegionStatusPendingReplication ImageRegionStatus = "pending replication"
33
+ ImageRegionStatusPendingDeletion ImageRegionStatus = "pending deletion"
34
+ ImageRegionStatusReplicating ImageRegionStatus = "replicating"
35
+ )
36
+
37
+ // ImageRegion represents the status of an Image object in a given Region.
38
+ type ImageRegion struct {
39
+ Region string `json:"region"`
40
+ Status ImageRegionStatus `json:"status"`
41
+ }
42
+
23
43
// Image represents a deployable Image object for use with Linode Instances
24
44
type Image struct {
25
- ID string `json:"id"`
26
- CreatedBy string `json:"created_by"`
27
- Capabilities []string `json:"capabilities"`
28
- Label string `json:"label"`
29
- Description string `json:"description"`
30
- Type string `json:"type"`
31
- Vendor string `json:"vendor"`
32
- Status ImageStatus `json:"status"`
33
- Size int `json:"size"`
34
- IsPublic bool `json:"is_public"`
35
- Deprecated bool `json:"deprecated"`
36
- Updated * time.Time `json:"-"`
37
- Created * time.Time `json:"-"`
38
- Expiry * time.Time `json:"-"`
39
- EOL * time.Time `json:"-"`
45
+ ID string `json:"id"`
46
+ CreatedBy string `json:"created_by"`
47
+ Capabilities []string `json:"capabilities"`
48
+ Label string `json:"label"`
49
+ Description string `json:"description"`
50
+ Type string `json:"type"`
51
+ Vendor string `json:"vendor"`
52
+ Status ImageStatus `json:"status"`
53
+ Size int `json:"size"`
54
+ TotalSize int `json:"total_size"`
55
+ IsPublic bool `json:"is_public"`
56
+ Deprecated bool `json:"deprecated"`
57
+ Regions []ImageRegion `json:"regions"`
58
+ Tags []string `json:"tags"`
59
+
60
+ Updated * time.Time `json:"-"`
61
+ Created * time.Time `json:"-"`
62
+ Expiry * time.Time `json:"-"`
63
+ EOL * time.Time `json:"-"`
40
64
}
41
65
42
66
// ImageCreateOptions fields are those accepted by CreateImage
43
67
type ImageCreateOptions struct {
44
- DiskID int `json:"disk_id"`
45
- Label string `json:"label"`
46
- Description string `json:"description,omitempty"`
47
- CloudInit bool `json:"cloud_init,omitempty"`
68
+ DiskID int `json:"disk_id"`
69
+ Label string `json:"label"`
70
+ Description string `json:"description,omitempty"`
71
+ CloudInit bool `json:"cloud_init,omitempty"`
72
+ Tags * []string `json:"tags,omitempty"`
48
73
}
49
74
50
75
// ImageUpdateOptions fields are those accepted by UpdateImage
51
76
type ImageUpdateOptions struct {
52
- Label string `json:"label,omitempty"`
53
- Description * string `json:"description,omitempty"`
77
+ Label string `json:"label,omitempty"`
78
+ Description * string `json:"description,omitempty"`
79
+ Tags * []string `json:"tags,omitempty"`
80
+ }
81
+
82
+ // ImageReplicateOptions represents the options accepted by the
83
+ // ReplicateImage(...) function.
84
+ type ImageReplicateOptions struct {
85
+ Regions []string `json:"regions"`
54
86
}
55
87
56
88
// ImageCreateUploadResponse fields are those returned by CreateImageUpload
@@ -61,18 +93,20 @@ type ImageCreateUploadResponse struct {
61
93
62
94
// ImageCreateUploadOptions fields are those accepted by CreateImageUpload
63
95
type ImageCreateUploadOptions struct {
64
- Region string `json:"region"`
65
- Label string `json:"label"`
66
- Description string `json:"description,omitempty"`
67
- CloudInit bool `json:"cloud_init,omitempty"`
96
+ Region string `json:"region"`
97
+ Label string `json:"label"`
98
+ Description string `json:"description,omitempty"`
99
+ CloudInit bool `json:"cloud_init,omitempty"`
100
+ Tags * []string `json:"tags,omitempty"`
68
101
}
69
102
70
103
// ImageUploadOptions fields are those accepted by UploadImage
71
104
type ImageUploadOptions struct {
72
- Region string `json:"region"`
73
- Label string `json:"label"`
74
- Description string `json:"description,omitempty"`
75
- CloudInit bool `json:"cloud_init"`
105
+ Region string `json:"region"`
106
+ Label string `json:"label"`
107
+ Description string `json:"description,omitempty"`
108
+ CloudInit bool `json:"cloud_init"`
109
+ Tags * []string `json:"tags,omitempty"`
76
110
Image io.Reader
77
111
}
78
112
@@ -109,7 +143,7 @@ func (i Image) GetUpdateOptions() (iu ImageUpdateOptions) {
109
143
return
110
144
}
111
145
112
- // ListImages lists Images
146
+ // ListImages lists Images.
113
147
func (c * Client ) ListImages (ctx context.Context , opts * ListOptions ) ([]Image , error ) {
114
148
return getPaginatedResults [Image ](
115
149
ctx ,
@@ -119,7 +153,7 @@ func (c *Client) ListImages(ctx context.Context, opts *ListOptions) ([]Image, er
119
153
)
120
154
}
121
155
122
- // GetImage gets the Image with the provided ID
156
+ // GetImage gets the Image with the provided ID.
123
157
func (c * Client ) GetImage (ctx context.Context , imageID string ) (* Image , error ) {
124
158
return doGETRequest [Image ](
125
159
ctx ,
@@ -128,7 +162,7 @@ func (c *Client) GetImage(ctx context.Context, imageID string) (*Image, error) {
128
162
)
129
163
}
130
164
131
- // CreateImage creates an Image
165
+ // CreateImage creates an Image.
132
166
func (c * Client ) CreateImage (ctx context.Context , opts ImageCreateOptions ) (* Image , error ) {
133
167
return doPOSTRequest [Image ](
134
168
ctx ,
@@ -138,7 +172,7 @@ func (c *Client) CreateImage(ctx context.Context, opts ImageCreateOptions) (*Ima
138
172
)
139
173
}
140
174
141
- // UpdateImage updates the Image with the specified id
175
+ // UpdateImage updates the Image with the specified id.
142
176
func (c * Client ) UpdateImage (ctx context.Context , imageID string , opts ImageUpdateOptions ) (* Image , error ) {
143
177
return doPUTRequest [Image ](
144
178
ctx ,
@@ -148,7 +182,17 @@ func (c *Client) UpdateImage(ctx context.Context, imageID string, opts ImageUpda
148
182
)
149
183
}
150
184
151
- // DeleteImage deletes the Image with the specified id
185
+ // ReplicateImage replicates an image to a given set of regions.
186
+ func (c * Client ) ReplicateImage (ctx context.Context , imageID string , opts ImageReplicateOptions ) (* Image , error ) {
187
+ return doPOSTRequest [Image ](
188
+ ctx ,
189
+ c ,
190
+ formatAPIPath ("images/%s/regions" , imageID ),
191
+ opts ,
192
+ )
193
+ }
194
+
195
+ // DeleteImage deletes the Image with the specified id.
152
196
func (c * Client ) DeleteImage (ctx context.Context , imageID string ) error {
153
197
return doDELETERequest (
154
198
ctx ,
@@ -157,7 +201,7 @@ func (c *Client) DeleteImage(ctx context.Context, imageID string) error {
157
201
)
158
202
}
159
203
160
- // CreateImageUpload creates an Image and an upload URL
204
+ // CreateImageUpload creates an Image and an upload URL.
161
205
func (c * Client ) CreateImageUpload (ctx context.Context , opts ImageCreateUploadOptions ) (* Image , string , error ) {
162
206
result , err := doPOSTRequest [ImageCreateUploadResponse ](
163
207
ctx ,
@@ -172,7 +216,7 @@ func (c *Client) CreateImageUpload(ctx context.Context, opts ImageCreateUploadOp
172
216
return result .Image , result .UploadTo , nil
173
217
}
174
218
175
- // UploadImageToURL uploads the given image to the given upload URL
219
+ // UploadImageToURL uploads the given image to the given upload URL.
176
220
func (c * Client ) UploadImageToURL (ctx context.Context , uploadURL string , image io.Reader ) error {
177
221
// Linode-specific headers do not need to be sent to this endpoint
178
222
req := resty .New ().SetDebug (c .resty .Debug ).R ().
@@ -187,13 +231,14 @@ func (c *Client) UploadImageToURL(ctx context.Context, uploadURL string, image i
187
231
return err
188
232
}
189
233
190
- // UploadImage creates and uploads an image
234
+ // UploadImage creates and uploads an image.
191
235
func (c * Client ) UploadImage (ctx context.Context , opts ImageUploadOptions ) (* Image , error ) {
192
236
image , uploadURL , err := c .CreateImageUpload (ctx , ImageCreateUploadOptions {
193
237
Label : opts .Label ,
194
238
Region : opts .Region ,
195
239
Description : opts .Description ,
196
240
CloudInit : opts .CloudInit ,
241
+ Tags : opts .Tags ,
197
242
})
198
243
if err != nil {
199
244
return nil , err
0 commit comments