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
|
package profitbricks
import (
"encoding/json"
"net/http"
)
type Image struct {
Id string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Metadata *DatacenterElementMetadata `json:"metadata,omitempty"`
Properties ImageProperties `json:"properties,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"headers,omitempty"`
}
type ImageProperties struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Location string `json:"location,omitempty"`
Size int `json:"size,omitempty"`
CpuHotPlug bool `json:"cpuHotPlug,omitempty"`
CpuHotUnplug bool `json:"cpuHotUnplug,omitempty"`
RamHotPlug bool `json:"ramHotPlug,omitempty"`
RamHotUnplug bool `json:"ramHotUnplug,omitempty"`
NicHotPlug bool `json:"nicHotPlug,omitempty"`
NicHotUnplug bool `json:"nicHotUnplug,omitempty"`
DiscVirtioHotPlug bool `json:"discVirtioHotPlug,omitempty"`
DiscVirtioHotUnplug bool `json:"discVirtioHotUnplug,omitempty"`
DiscScsiHotPlug bool `json:"discScsiHotPlug,omitempty"`
DiscScsiHotUnplug bool `json:"discScsiHotUnplug,omitempty"`
LicenceType string `json:"licenceType,omitempty"`
ImageType string `json:"imageType,omitempty"`
Public bool `json:"public,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"headers,omitempty"`
}
type Images struct {
Id string `json:"id,omitempty"`
Type_ string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Items []Image `json:"items,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"headers,omitempty"`
}
type Cdroms struct {
Id string `json:"id,omitempty"`
Type_ string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Items []Image `json:"items,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"headers,omitempty"`
}
// ListImages returns an Collection struct
func ListImages() Images {
path := image_col_path()
url := mk_url(path) + `?depth=` + Depth
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Content-Type", FullHeader)
resp := do(req)
return toImages(resp)
}
// GetImage returns an Instance struct where id ==imageid
func GetImage(imageid string) Image {
path := image_path(imageid)
url := mk_url(path) + `?depth=` + Depth
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Content-Type", FullHeader)
resp := do(req)
return toImage(resp)
}
func toImage(resp Resp) Image {
var image Image
json.Unmarshal(resp.Body, &image)
image.Response = string(resp.Body)
image.Headers = &resp.Headers
image.StatusCode = resp.StatusCode
return image
}
func toImages(resp Resp) Images {
var col Images
json.Unmarshal(resp.Body, &col)
col.Response = string(resp.Body)
col.Headers = &resp.Headers
col.StatusCode = resp.StatusCode
return col
}
|