-
Notifications
You must be signed in to change notification settings - Fork 14
/
templates.go
268 lines (235 loc) · 16.7 KB
/
templates.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
package egoscale
import (
"fmt"
)
// Template represents a machine to be deployed
//
// See: http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/latest/templates.html
type Template struct {
Account string `json:"account,omitempty" doc:"the account name to which the template belongs"`
AccountID *UUID `json:"accountid,omitempty" doc:"the account id to which the template belongs"`
Bootable bool `json:"bootable,omitempty" doc:"true if the ISO is bootable, false otherwise"`
Checksum string `json:"checksum,omitempty" doc:"checksum of the template"`
Created string `json:"created,omitempty" doc:"the date this template was created"`
CrossZones bool `json:"crossZones,omitempty" doc:"true if the template is managed across all Zones, false otherwise"`
Details map[string]string `json:"details,omitempty" doc:"additional key/value details tied with template"`
DisplayText string `json:"displaytext,omitempty" doc:"the template display text"`
Format string `json:"format,omitempty" doc:"the format of the template."`
HostID *UUID `json:"hostid,omitempty" doc:"the ID of the secondary storage host for the template"`
HostName string `json:"hostname,omitempty" doc:"the name of the secondary storage host for the template"`
ID *UUID `json:"id,omitempty" doc:"the template ID"`
IsDynamicallyScalable bool `json:"isdynamicallyscalable,omitempty" doc:"true if template contains XS/VMWare tools inorder to support dynamic scaling of VM cpu/memory"`
IsExtractable bool `json:"isextractable,omitempty" doc:"true if the template is extractable, false otherwise"`
IsFeatured bool `json:"isfeatured,omitempty" doc:"true if this template is a featured template, false otherwise"`
IsPublic bool `json:"ispublic,omitempty" doc:"true if this template is a public template, false otherwise"`
IsReady bool `json:"isready,omitempty" doc:"true if the template is ready to be deployed from, false otherwise."`
Name string `json:"name,omitempty" doc:"the template name"`
OsTypeID *UUID `json:"ostypeid,omitempty" doc:"the ID of the OS type for this template."`
OsTypeName string `json:"ostypename,omitempty" doc:"the name of the OS type for this template."`
PasswordEnabled bool `json:"passwordenabled,omitempty" doc:"true if the reset password feature is enabled, false otherwise"`
Removed string `json:"removed,omitempty" doc:"the date this template was removed"`
Size int64 `json:"size,omitempty" doc:"the size of the template"`
SourceTemplateID *UUID `json:"sourcetemplateid,omitempty" doc:"the template ID of the parent template if present"`
SSHKeyEnabled bool `json:"sshkeyenabled,omitempty" doc:"true if template is sshkey enabled, false otherwise"`
Status string `json:"status,omitempty" doc:"the status of the template"`
Tags []ResourceTag `json:"tags,omitempty" doc:"the list of resource tags associated with tempate"`
TemplateDirectory string `json:"templatedirectory,omitempty" doc:"Template directory"`
TemplateTag string `json:"templatetag,omitempty" doc:"the tag of this template"`
TemplateType string `json:"templatetype,omitempty" doc:"the type of the template"`
URL string `json:"url,omitempty" doc:"Original URL of the template where it was downloaded"`
ZoneID *UUID `json:"zoneid,omitempty" doc:"the ID of the zone for this template"`
ZoneName string `json:"zonename,omitempty" doc:"the name of the zone for this template"`
}
// ResourceType returns the type of the resource
func (Template) ResourceType() string {
return "Template"
}
// ListRequest builds the ListTemplates request
func (temp Template) ListRequest() (ListCommand, error) {
req := &ListTemplates{
Name: temp.Name,
ID: temp.ID,
ZoneID: temp.ZoneID,
//TODO Tags
}
if temp.IsFeatured {
req.TemplateFilter = "featured"
}
if temp.Removed != "" {
*req.ShowRemoved = true
}
return req, nil
}
// ListTemplates represents a template query filter
type ListTemplates struct {
TemplateFilter string `json:"templatefilter" doc:"Possible values are \"featured\", \"self\", \"selfexecutable\",\"sharedexecutable\",\"executable\", and \"community\". * featured : templates that have been marked as featured and public. * self : templates that have been registered or created by the calling user. * selfexecutable : same as self, but only returns templates that can be used to deploy a new VM. * sharedexecutable : templates ready to be deployed that have been granted to the calling user by another user. * executable : templates that are owned by the calling user, or public templates, that can be used to deploy a VM. * community : templates that have been marked as public but not featured."`
ID *UUID `json:"id,omitempty" doc:"the template ID"`
Keyword string `json:"keyword,omitempty" doc:"List by keyword"`
Name string `json:"name,omitempty" doc:"the template name"`
Page int `json:"page,omitempty"`
PageSize int `json:"pagesize,omitempty"`
ShowRemoved *bool `json:"showremoved,omitempty" doc:"Show removed templates as well"`
Tags []ResourceTag `json:"tags,omitempty" doc:"List resources by tags (key/value pairs)"`
ZoneID *UUID `json:"zoneid,omitempty" doc:"list templates by zoneid"`
_ bool `name:"listTemplates" description:"List all public, private, and privileged templates."`
}
// ListTemplatesResponse represents a list of templates
type ListTemplatesResponse struct {
Count int `json:"count"`
Template []Template `json:"template"`
}
func (ListTemplates) response() interface{} {
return new(ListTemplatesResponse)
}
func (ListTemplates) each(resp interface{}, callback IterateItemFunc) {
temps, ok := resp.(*ListTemplatesResponse)
if !ok {
callback(nil, fmt.Errorf("wrong type. ListTemplatesResponse expected, got %T", resp))
return
}
for i := range temps.Template {
if !callback(&temps.Template[i], nil) {
break
}
}
}
// SetPage sets the current page
func (ls *ListTemplates) SetPage(page int) {
ls.Page = page
}
// SetPageSize sets the page size
func (ls *ListTemplates) SetPageSize(pageSize int) {
ls.PageSize = pageSize
}
// CreateTemplate (Async) represents a template creation
type CreateTemplate struct {
Bits int `json:"bits,omitempty" doc:"32 or 64 bit"`
Details map[string]string `json:"details,omitempty" doc:"Template details in key/value pairs."`
DisplayText string `json:"displaytext" doc:"the display text of the template. This is usually used for display purposes."`
IsDynamicallyScalable *bool `json:"isdynamicallyscalable,omitempty" doc:"true if template contains XS/VMWare tools inorder to support dynamic scaling of VM cpu/memory"`
IsFeatured *bool `json:"isfeatured,omitempty" doc:"true if this template is a featured template, false otherwise"`
IsPublic *bool `json:"ispublic,omitempty" doc:"true if this template is a public template, false otherwise"`
Name string `json:"name" doc:"the name of the template"`
OsTypeID *UUID `json:"ostypeid" doc:"the ID of the OS Type that best represents the OS of this template."`
PasswordEnabled *bool `json:"passwordenabled,omitempty" doc:"true if the template supports the password reset feature; default is false"`
RequiresHVM *bool `json:"requireshvm,omitempty" doc:"true if the template requres HVM, false otherwise"`
SnapshotID *UUID `json:"snapshotid,omitempty" doc:"the ID of the snapshot the template is being created from. Either this parameter, or volumeId has to be passed in"`
TemplateTag string `json:"templatetag,omitempty" doc:"the tag for this template."`
URL string `json:"url,omitempty" doc:"Optional, only for baremetal hypervisor. The directory name where template stored on CIFS server"`
VirtualMachineID *UUID `json:"virtualmachineid,omitempty" doc:"Optional, VM ID. If this presents, it is going to create a baremetal template for VM this ID refers to. This is only for VM whose hypervisor type is BareMetal"`
VolumeID *UUID `json:"volumeid,omitempty" doc:"the ID of the disk volume the template is being created from. Either this parameter, or snapshotId has to be passed in"`
_ bool `name:"createTemplate" description:"Creates a template of a virtual machine. The virtual machine must be in a STOPPED state. A template created from this command is automatically designated as a private template visible to the account that created it."`
}
func (CreateTemplate) response() interface{} {
return new(AsyncJobResult)
}
func (CreateTemplate) asyncResponse() interface{} {
return new(Template)
}
// CopyTemplate (Async) represents a template copy
type CopyTemplate struct {
DestZoneID *UUID `json:"destzoneid" doc:"ID of the zone the template is being copied to."`
ID *UUID `json:"id" doc:"Template ID."`
SourceZoneID *UUID `json:"sourcezoneid,omitempty" doc:"ID of the zone the template is currently hosted on. If not specified and template is cross-zone, then we will sync this template to region wide image store."`
_ bool `name:"copyTemplate" description:"Copies a template from one zone to another."`
}
func (CopyTemplate) response() interface{} {
return new(AsyncJobResult)
}
func (CopyTemplate) asyncResponse() interface{} {
return new(Template)
}
// UpdateTemplate represents a template change
type UpdateTemplate struct {
Bootable *bool `json:"bootable,omitempty" doc:"true if image is bootable, false otherwise"`
Details map[string]string `json:"details,omitempty" doc:"Details in key/value pairs."`
DisplayText string `json:"displaytext,omitempty" doc:"the display text of the image"`
Format string `json:"format,omitempty" doc:"the format for the image"`
ID *UUID `json:"id" doc:"the ID of the image file"`
IsDynamicallyScalable *bool `json:"isdynamicallyscalable,omitempty" doc:"true if template/ISO contains XS/VMWare tools inorder to support dynamic scaling of VM cpu/memory"`
IsRouting *bool `json:"isrouting,omitempty" doc:"true if the template type is routing i.e., if template is used to deploy router"`
Name string `json:"name,omitempty" doc:"the name of the image file"`
OsTypeID *UUID `json:"ostypeid,omitempty" doc:"the ID of the OS type that best represents the OS of this image."`
PasswordEnabled *bool `json:"passwordenabled,omitempty" doc:"true if the image supports the password reset feature; default is false"`
SortKey int `json:"sortkey,omitempty" doc:"sort key of the template, integer"`
_ bool `name:"updateTemplate" description:"Updates attributes of a template."`
}
func (UpdateTemplate) response() interface{} {
return new(AsyncJobResult)
}
func (UpdateTemplate) asyncResponse() interface{} {
return new(Template)
}
// DeleteTemplate (Async) represents the deletion of a template
type DeleteTemplate struct {
ID *UUID `json:"id" doc:"the ID of the template"`
ZoneID *UUID `json:"zoneid,omitempty" doc:"the ID of zone of the template"`
_ bool `name:"deleteTemplate" description:"Deletes a template from the system. All virtual machines using the deleted template will not be affected."`
}
func (DeleteTemplate) response() interface{} {
return new(AsyncJobResult)
}
func (DeleteTemplate) asyncResponse() interface{} {
return new(booleanResponse)
}
// PrepareTemplate represents a template preparation
type PrepareTemplate struct {
TemplateID *UUID `json:"templateid" doc:"template ID of the template to be prepared in primary storage(s)."`
ZoneID *UUID `json:"zoneid" doc:"zone ID of the template to be prepared in primary storage(s)."`
_ bool `name:"prepareTemplate" description:"load template into primary storage"`
}
func (PrepareTemplate) response() interface{} {
return new(AsyncJobResult)
}
func (PrepareTemplate) asyncResponse() interface{} {
return new(Template)
}
// RegisterTemplate represents a template registration
type RegisterTemplate struct {
Account string `json:"account,omitempty" doc:"an optional accountName. Must be used with domainid."`
Bits int `json:"bits,omitempty" doc:"32 or 64 bits support. 64 by default"`
Checksum string `json:"checksum,omitempty" doc:"the MD5 checksum value of this template"`
Details map[string]string `json:"details,omitempty" doc:"Template details in key/value pairs."`
DisplayText string `json:"displaytext" doc:"the display text of the template. This is usually used for display purposes."`
Format string `json:"format" doc:"the format for the template. Possible values include QCOW2, RAW, and VHD."`
IsDynamicallyScalable *bool `json:"isdynamicallyscalable,omitempty" doc:"true if template contains XS/VMWare tools inorder to support dynamic scaling of VM cpu/memory"`
IsExtractable *bool `json:"isextractable,omitempty" doc:"true if the template or its derivatives are extractable; default is false"`
IsFeatured *bool `json:"isfeatured,omitempty" doc:"true if this template is a featured template, false otherwise"`
IsPublic *bool `json:"ispublic,omitempty" doc:"true if the template is available to all accounts; default is true"`
IsRouting *bool `json:"isrouting,omitempty" doc:"true if the template type is routing i.e., if template is used to deploy router"`
IsSystem *bool `json:"issystem,omitempty" doc:"true if the template type is system i.e., if template is used to deploy system VM"`
Name string `json:"name" doc:"the name of the template"`
OsTypeID *UUID `json:"ostypeid" doc:"the ID of the OS Type that best represents the OS of this template."`
PasswordEnabled *bool `json:"passwordenabled,omitempty" doc:"true if the template supports the password reset feature; default is false"`
RequiresHVM *bool `json:"requireshvm,omitempty" doc:"true if this template requires HVM"`
SSHKeyEnabled *bool `json:"sshkeyenabled,omitempty" doc:"true if the template supports the sshkey upload feature; default is false"`
TemplateTag string `json:"templatetag,omitempty" doc:"the tag for this template."`
URL string `json:"url" doc:"the URL of where the template is hosted. Possible URL include http:// and https://"`
ZoneID *UUID `json:"zoneid" doc:"the ID of the zone the template is to be hosted on"`
_ bool `name:"registerTemplate" description:"Registers an existing template into the CloudStack cloud."`
}
func (RegisterTemplate) response() interface{} {
return new(Template)
}
// OSCategory represents an OS category
type OSCategory struct {
ID string `json:"id,omitempty" doc:"the ID of the OS category"`
Name string `json:"name,omitempty" doc:"the name of the OS category"`
}
// ListOSCategories lists the OS categories
type ListOSCategories struct {
ID *UUID `json:"id,omitempty" doc:"list Os category by id"`
Keyword string `json:"keyword,omitempty" doc:"List by keyword"`
Name string `json:"name,omitempty" doc:"list os category by name"`
Page int `json:"page,omitempty"`
PageSize int `json:"pagesize,omitempty"`
_ bool `name:"listOsCategories" description:"Lists all supported OS categories for this cloud."`
}
// ListOSCategoriesResponse represents a list of OS categories
type ListOSCategoriesResponse struct {
Count int `json:"count"`
OSCategory []OSCategory `json:"oscategory"`
}
func (ListOSCategories) response() interface{} {
return new(ListOSCategoriesResponse)
}