-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtemplate.go
More file actions
133 lines (119 loc) · 3.83 KB
/
template.go
File metadata and controls
133 lines (119 loc) · 3.83 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
package gopherstack
import (
"net/url"
)
// Creates a Template of a Virtual Machine by it's ID
func (c CloudstackClient) CreateTemplate(options *CreateTemplate) (CreateTemplateResponse, error) {
var resp CreateTemplateResponse
params := url.Values{}
params.Set("displaytext", options.Displaytext)
params.Set("name", options.Name)
params.Set("ostypeid", options.Ostypeid)
if options.Volumeid != "" {
params.Set("volumeid", options.Volumeid)
}
if options.Snapshotid != "" {
params.Set("snapshotid", options.Snapshotid)
}
if options.Isdynamicallyscalable {
params.Set("isdynamicallyscalable", "true")
}
if options.Isextractable {
params.Set("isextractable", "true")
}
if options.Isfeatured {
params.Set("isfeatured", "true")
}
if options.Ispublic {
params.Set("ispublic", "true")
}
if options.Passwordenabled {
params.Set("passwordenabled", "true")
}
response, err := NewRequest(c, "createTemplate", params)
if err != nil {
return resp, err
}
resp = response.(CreateTemplateResponse)
return resp, err
}
// Returns all available templates
func (c CloudstackClient) ListTemplates(name string, filter string) (ListTemplatesResponse, error) {
var resp ListTemplatesResponse
params := url.Values{}
params.Set("name", name)
params.Set("templatefilter", filter)
response, err := NewRequest(c, "listTemplates", params)
if err != nil {
return resp, err
}
resp = response.(ListTemplatesResponse)
return resp, err
}
// Deletes an template by its ID.
func (c CloudstackClient) DeleteTemplate(id string) (DeleteTemplateResponse, error) {
var resp DeleteTemplateResponse
params := url.Values{}
params.Set("id", id)
response, err := NewRequest(c, "deleteTemplate", params)
if err != nil {
return resp, err
}
resp = response.(DeleteTemplateResponse)
return resp, err
}
type CreateTemplateResponse struct {
Createtemplateresponse struct {
ID string `json:"id"`
Jobid string `json:"jobid"`
} `json:"createtemplateresponse"`
}
type DeleteTemplateResponse struct {
Deletetemplateresponse struct {
}
}
type Template struct {
Account string `json:"account"`
Created string `json:"created"`
CrossZones bool `json:"crossZones"`
Displaytext string `json:"displaytext"`
Domain string `json:"domain"`
Domainid string `json:"domainid"`
Format string `json:"format"`
Hypervisor string `json:"hypervisor"`
ID string `json:"id"`
Isextractable bool `json:"isextractable"`
Isfeatured bool `json:"isfeatured"`
Ispublic bool `json:"ispublic"`
Isready bool `json:"isready"`
Name string `json:"name"`
Ostypeid string `json:"ostypeid"`
Ostypename string `json:"ostypename"`
Passwordenabled bool `json:"passwordenabled"`
Size float64 `json:"size"`
Sourcetemplateid string `json:"sourcetemplateid"`
Sshkeyenabled bool `json:"sshkeyenabled"`
Status string `json:"status"`
Tags []Tag `json:"tags"`
Templatetype string `json:"templatetype"`
Zoneid string `json:"zoneid"`
Zonename string `json:"zonename"`
}
type ListTemplatesResponse struct {
Listtemplatesresponse struct {
Count float64 `json:"count"`
Template []Template `json:"template"`
} `json:"listtemplatesresponse"`
}
type CreateTemplate struct {
Displaytext string `json:"displaytext"`
Isdynamicallyscalable bool `json:"isdynamicallyscalable"`
Isextractable bool `json:"isextractable"`
Isfeatured bool `json:"isfeatured"`
Ispublic bool `json:"ispublic"`
Name string `json:"name"`
Ostypeid string `json:"ostypeid"`
Passwordenabled bool `json:"passwordenabled"`
Snapshotid string `json:"snapshotid"`
Volumeid string `json:"volumeid"`
}