forked from xenserver/go-xenserver-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vbd.go
60 lines (51 loc) · 1.12 KB
/
vbd.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
package client
import (
"github.com/nilshell/xmlrpc"
)
type VBD XenAPIObject
func (self *VBD) GetRecord() (record map[string]interface{}, err error) {
record = make(map[string]interface{})
result := APIResult{}
err = self.Client.APICall(&result, "VBD.get_record", self.Ref)
if err != nil {
return record, err
}
for k, v := range result.Value.(xmlrpc.Struct) {
record[k] = v
}
return record, nil
}
func (self *VBD) GetVDI() (vdi *VDI, err error) {
vbd_rec, err := self.GetRecord()
if err != nil {
return nil, err
}
vdi = new(VDI)
vdi.Ref = vbd_rec["VDI"].(string)
vdi.Client = self.Client
return vdi, nil
}
func (self *VBD) Eject() (err error) {
result := APIResult{}
err = self.Client.APICall(&result, "VBD.eject", self.Ref)
if err != nil {
return err
}
return nil
}
func (self *VBD) Unplug() (err error) {
result := APIResult{}
err = self.Client.APICall(&result, "VBD.unplug", self.Ref)
if err != nil {
return err
}
return nil
}
func (self *VBD) Destroy() (err error) {
result := APIResult{}
err = self.Client.APICall(&result, "VBD.destroy", self.Ref)
if err != nil {
return err
}
return nil
}