forked from canonical/lxd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
image.go
300 lines (242 loc) · 8.34 KB
/
image.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
package api
import (
"time"
)
// ImageExportPost represents the fields required to export a LXD image
//
// swagger:model
//
// API extension: images_push_relay
type ImageExportPost struct {
// Target server URL
// Example: https://1.2.3.4:8443
Target string `json:"target" yaml:"target"`
// Image receive secret
// Example: RANDOM-STRING
Secret string `json:"secret" yaml:"secret"`
// Remote server certificate
// Example: X509 PEM certificate
Certificate string `json:"certificate" yaml:"certificate"`
// List of aliases to set on the image
Aliases []ImageAlias `json:"aliases" yaml:"aliases"`
}
// ImagesPost represents the fields available for a new LXD image
//
// swagger:model
type ImagesPost struct {
ImagePut `yaml:",inline"`
// Original filename of the image
// Example: lxd.tar.xz
Filename string `json:"filename" yaml:"filename"`
// Source of the image
Source *ImagesPostSource `json:"source" yaml:"source"`
// Compression algorithm to use when turning an instance into an image
// Example: gzip
//
// API extension: image_compression_algorithm
CompressionAlgorithm string `json:"compression_algorithm" yaml:"compression_algorithm"`
// Aliases to add to the image
// Example: ["my-image"]
//
// API extension: image_create_aliases
Aliases []ImageAlias `json:"aliases" yaml:"aliases"`
}
// ImagesPostSource represents the source of a new LXD image
//
// swagger:model
type ImagesPostSource struct {
ImageSource `yaml:",inline"`
// Transfer mode (push or pull)
// Example: pull
Mode string `json:"mode" yaml:"mode"`
// Type of image source (instance, snapshot, image or url)
// Example: instance
Type string `json:"type" yaml:"type"`
// Source URL (for type "url")
// Example: https://some-server.com/some-directory/
URL string `json:"url" yaml:"url"`
// Instance name (for type "instance" or "snapshot")
// Example: c1/snap0
Name string `json:"name" yaml:"name"`
// Source image fingerprint (for type "image")
// Example: 8ae945c52bb2f2df51c923b04022312f99bbb72c356251f54fa89ea7cf1df1d0
Fingerprint string `json:"fingerprint" yaml:"fingerprint"`
// Source image server secret token (when downloading private images)
// Example: RANDOM-STRING
Secret string `json:"secret" yaml:"secret"`
}
// ImagePut represents the modifiable fields of a LXD image
//
// swagger:model
type ImagePut struct {
// Whether the image should auto-update when a new build is available
// Example: true
AutoUpdate bool `json:"auto_update" yaml:"auto_update"`
// Descriptive properties
// Example: {"os": "Ubuntu", "release": "focal", "variant": "cloud"}
Properties map[string]string `json:"properties" yaml:"properties"`
// Whether the image is available to unauthenticated users
// Example: false
Public bool `json:"public" yaml:"public"`
// When the image becomes obsolete
// Example: 2025-03-23T20:00:00-04:00
//
// API extension: images_expiry
ExpiresAt time.Time `json:"expires_at" yaml:"expires_at"`
// List of profiles to use when creating from this image (if none provided by user)
// Example: ["default"]
//
// API extension: image_profiles
Profiles []string `json:"profiles" yaml:"profiles"`
}
// Image represents a LXD image
//
// swagger:model
type Image struct {
ImagePut `yaml:",inline"`
// List of aliases
Aliases []ImageAlias `json:"aliases" yaml:"aliases"`
// Architecture
// Example: x86_64
Architecture string `json:"architecture" yaml:"architecture"`
// Whether the image is an automatically cached remote image
// Example: true
Cached bool `json:"cached" yaml:"cached"`
// Original filename
// Example: 06b86454720d36b20f94e31c6812e05ec51c1b568cf3a8abd273769d213394bb.rootfs
Filename string `json:"filename" yaml:"filename"`
// Full SHA-256 fingerprint
// Example: 06b86454720d36b20f94e31c6812e05ec51c1b568cf3a8abd273769d213394bb
Fingerprint string `json:"fingerprint" yaml:"fingerprint"`
// Size of the image in bytes
// Example: 272237676
Size int64 `json:"size" yaml:"size"`
// Where the image came from
UpdateSource *ImageSource `json:"update_source,omitempty" yaml:"update_source,omitempty"`
// Type of image (container or virtual-machine)
// Example: container
//
// API extension: image_types
Type string `json:"type" yaml:"type"`
// When the image was originally created
// Example: 2021-03-23T20:00:00-04:00
CreatedAt time.Time `json:"created_at" yaml:"created_at"`
// Last time the image was used
// Example: 2021-03-22T20:39:00.575185384-04:00
LastUsedAt time.Time `json:"last_used_at" yaml:"last_used_at"`
// When the image was added to this LXD server
// Example: 2021-03-24T14:18:15.115036787-04:00
UploadedAt time.Time `json:"uploaded_at" yaml:"uploaded_at"`
}
// Writable converts a full Image struct into a ImagePut struct (filters read-only fields)
func (img *Image) Writable() ImagePut {
return img.ImagePut
}
// ImageAlias represents an alias from the alias list of a LXD image
//
// swagger:model
type ImageAlias struct {
// Name of the alias
// Example: ubuntu-20.04
Name string `json:"name" yaml:"name"`
// Description of the alias
// Example: Our preferred Ubuntu image
Description string `json:"description" yaml:"description"`
}
// ImageSource represents the source of a LXD image
//
// swagger:model
type ImageSource struct {
// Source alias to download from
// Example: bionic
Alias string `json:"alias" yaml:"alias"`
// Source server certificate (if not trusted by system CA)
// Example: X509 PEM certificate
Certificate string `json:"certificate" yaml:"certificate"`
// Source server protocol
// Example: simplestreams
Protocol string `json:"protocol" yaml:"protocol"`
// URL of the source server
// Example: https://images.linuxcontainers.org
Server string `json:"server" yaml:"server"`
// Type of image (container or virtual-machine)
// Example: container
//
// API extension: image_types
ImageType string `json:"image_type" yaml:"image_type"`
}
// ImageAliasesPost represents a new LXD image alias
//
// swagger:model
type ImageAliasesPost struct {
ImageAliasesEntry `yaml:",inline"`
}
// ImageAliasesEntryPost represents the required fields to rename a LXD image alias
//
// swagger:model
type ImageAliasesEntryPost struct {
// Alias name
// Example: ubuntu-20.04
Name string `json:"name" yaml:"name"`
}
// ImageAliasesEntryPut represents the modifiable fields of a LXD image alias
//
// swagger:model
type ImageAliasesEntryPut struct {
// Alias description
// Example: Our preferred Ubuntu image
Description string `json:"description" yaml:"description"`
// Target fingerprint for the alias
// Example: 06b86454720d36b20f94e31c6812e05ec51c1b568cf3a8abd273769d213394bb
Target string `json:"target" yaml:"target"`
}
// ImageAliasesEntry represents a LXD image alias
//
// swagger:model
type ImageAliasesEntry struct {
ImageAliasesEntryPut `yaml:",inline"`
// Alias name
// Example: ubuntu-20.04
Name string `json:"name" yaml:"name"`
// Alias type (container or virtual-machine)
// Example: container
//
// API extension: image_types
Type string `json:"type" yaml:"type"`
}
// ImageMetadata represents LXD image metadata (used in image tarball)
//
// swagger:model
type ImageMetadata struct {
// Architecture name
// Example: x86_64
Architecture string `json:"architecture" yaml:"architecture"`
// Image creation data (as UNIX epoch)
// Example: 1620655439
CreationDate int64 `json:"creation_date" yaml:"creation_date"`
// Image expiry data (as UNIX epoch)
// Example: 1620685757
ExpiryDate int64 `json:"expiry_date" yaml:"expiry_date"`
// Descriptive properties
// Example: {"os": "Ubuntu", "release": "focal", "variant": "cloud"}
Properties map[string]string `json:"properties" yaml:"properties"`
// Template for files in the image
Templates map[string]*ImageMetadataTemplate `json:"templates" yaml:"templates"`
}
// ImageMetadataTemplate represents a template entry in image metadata (used in image tarball)
//
// swagger:model
type ImageMetadataTemplate struct {
// When to trigger the template (create, copy or start)
// Example: create
When []string `json:"when" yaml:"when"`
// Whether to trigger only if the file is missing
// Example: false
CreateOnly bool `json:"create_only" yaml:"create_only"`
// The template itself as a valid pongo2 template
// Example: pongo2-template
Template string `json:"template" yaml:"template"`
// Key/value properties to pass to the template
// Example: {"foo": "bar"}
Properties map[string]string `json:"properties" yaml:"properties"`
}