Skip to content

Commit a28415d

Browse files
author
Peter Jönsson
committed
Add support for more API calls
* listDiskOfferings * detachIso Added to be able to boot from ISO to kickstart installation from an empty block device.
1 parent 1208a42 commit a28415d

4 files changed

Lines changed: 72 additions & 11 deletions

File tree

client.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ func NewRequest(c CloudStackClient, request string, params url.Values) (interfac
123123
json.Unmarshal(body, &decodedResponse)
124124
return decodedResponse, nil
125125

126+
case "listDiskOfferings":
127+
var decodedResponse ListDiskOfferingsResponse
128+
json.Unmarshal(body, &decodedResponse)
129+
return decodedResponse, nil
130+
131+
case "detachIso":
132+
var decodedResponse DetachIsoResponse
133+
json.Unmarshal(body, &decodedResponse)
134+
return decodedResponse, nil
135+
126136
case "queryAsyncJobResult":
127137
var decodedResponse QueryAsyncJobResultResponse
128138
json.Unmarshal(body, &decodedResponse)

disk.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package gopherstack
2+
3+
import (
4+
"net/url"
5+
)
6+
7+
func (c CloudStackClient) ListDiskOfferings(domainid string, id string, keyword string, name string, page string, pagesize string) (string, error) {
8+
params := url.Values{}
9+
//params.Set("domainid", domainid)
10+
_, err := NewRequest(c, "listDiskOfferings", params)
11+
if err != nil {
12+
return "", err
13+
}
14+
return "", err
15+
}
16+
17+
type DiskOffering struct {
18+
Created string `json:"created"`
19+
Disksize float64 `json:"disksize"`
20+
Displaytext string `json:"displaytext"`
21+
ID string `json:"id"`
22+
Iscustomized bool `json:"iscustomized"`
23+
Name string `json:"name"`
24+
Storagetype string `json:"storagetype"`
25+
}
26+
27+
type ListDiskOfferingsResponse struct {
28+
Listdiskofferingsresponse struct {
29+
Count float64 `json:"count"`
30+
Diskoffering []DiskOffering `json:"diskoffering"`
31+
} `json:"listdiskofferingsresponse"`
32+
}

iso.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ func (c CloudStackClient) AttachIso(isoid string, vmid string) (string, error) {
2121
func (c CloudStackClient) DetachIso(vmid string) (string, error) {
2222
params := url.Values{}
2323
params.Set("virtualmachineid", vmid)
24-
_, err := NewRequest(c, "detachIso", params)
24+
response, err := NewRequest(c, "detachIso", params)
2525
if err != nil {
2626
return "", err
2727
}
28-
//jobid := response.(DetachIsoResponse).DetachIsoresponse.Jobid
29-
return "", err
28+
jobid := response.(DetachIsoResponse).Detachisoresponse.Jobid
29+
return jobid, err
3030
}
3131

3232
func (c CloudStackClient) ListIsos() (string, error) {
@@ -37,3 +37,9 @@ func (c CloudStackClient) ListIsos() (string, error) {
3737
//jobid := response.(ListIsosResponse).Listisosresponse.Jobid
3838
return "", err
3939
}
40+
41+
type DetachIsoResponse struct {
42+
Detachisoresponse struct {
43+
Jobid string `json:"jobid"`
44+
} `json:"detachisoresponse"`
45+
}

virtualmachine.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,19 @@ import (
77
)
88

99
// Deploys a Virtual Machine and returns it's id
10-
func (c CloudStackClient) DeployVirtualMachine(serviceofferingid string, templateid string, zoneid string, networkids []string, keypair string, displayname string, diskoffering string, projectid string, userdata string) (string, string, error) {
10+
func (c CloudStackClient) DeployVirtualMachine(serviceofferingid string, templateid string, zoneid string, account string, diskofferingid string, displayname string, networkids []string, keypair string, projectid string, userdata string) (string, string, error) {
1111
params := url.Values{}
1212
params.Set("serviceofferingid", serviceofferingid)
1313
params.Set("templateid", templateid)
1414
params.Set("zoneid", zoneid)
15+
// params.Set("account", account)
16+
params.Set("diskofferingid", diskofferingid)
17+
params.Set("displayname", displayname)
18+
params.Set("hypervisor", "xenserver")
1519
params.Set("networkids", strings.Join(networkids, ","))
1620
params.Set("keypair", keypair)
17-
params.Set("displayname", displayname)
21+
// parsms.Set("projectid", projectid)
1822
params.Set("userdata", base64.StdEncoding.EncodeToString([]byte(userdata)))
19-
if projectid != "" {
20-
params.Set("projectid", projectid)
21-
}
22-
if diskoffering != "" {
23-
params.Set("diskoffering", diskoffering)
24-
}
2523
response, err := NewRequest(c, "deployVirtualMachine", params)
2624
if err != nil {
2725
return "", "", err
@@ -31,6 +29,21 @@ func (c CloudStackClient) DeployVirtualMachine(serviceofferingid string, templat
3129
return vmid, jobid, nil
3230
}
3331

32+
func (c CloudStackClient) UpdateVirtualMachine(id string, displayname string, group string, haenable string, ostypeid string, userdata string) (string, error) {
33+
params := url.Values{}
34+
params.Set("id", id)
35+
params.Set("displayname", displayname)
36+
// params.Set("group", string)
37+
// params.Set("haenable", haenable)
38+
// params.Set("ostypeid", ostypeid)
39+
params.Set("userdata", base64.StdEncoding.EncodeToString([]byte(userdata)))
40+
_, err := NewRequest(c, "updateVirtualMachine", params)
41+
if err != nil {
42+
return "", err
43+
}
44+
return "", err
45+
}
46+
3447
// Stops a Virtual Machine
3548
func (c CloudStackClient) StopVirtualMachine(id string) (string, error) {
3649
params := url.Values{}

0 commit comments

Comments
 (0)