forked from mindjiver/gopherstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.go
More file actions
99 lines (87 loc) · 3 KB
/
template.go
File metadata and controls
99 lines (87 loc) · 3 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
package gopherstack
import (
"net/url"
)
// Creates a Template of a Virtual Machine by it's ID
func (c CloudstackClient) CreateTemplate(displaytext string, name string, volumeid string, ostypeid string) (CreateTemplateResponse, error) {
var resp CreateTemplateResponse
params := url.Values{}
params.Set("displaytext", displaytext)
params.Set("name", name)
params.Set("ostypeid", ostypeid)
params.Set("volumeid", volumeid)
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 []interface{} `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"`
}