-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathVirtualMachineMethods.go
More file actions
56 lines (51 loc) · 1.18 KB
/
VirtualMachineMethods.go
File metadata and controls
56 lines (51 loc) · 1.18 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
package cloudstack
import "fmt"
func (c *Client) GetVirtualMachine(id string) (*VirtualMachine, error) {
p := NewListVirtualMachinesParameter()
p.Id.Set(id)
rs, err := c.ListVirtualMachines(p)
if err != nil {
return nil, err
}
if len(rs) != 1 {
return nil, fmt.Errorf("Expected just 1 item, %d items are returned", len(rs))
}
return rs[0], nil
}
func (r *VirtualMachine) Refresh() (err error) {
newr, err := r.client.GetVirtualMachine(r.Id.String())
if newr != nil {
*r = *newr
} else {
newr = new(VirtualMachine)
newr.setClient(r.client)
*r = *newr
}
*r = *newr
return err
}
func (r *VirtualMachine) Update(args map[string]interface{}) (err error) {
p := NewUpdateVirtualMachineParameter(r.Id.String())
newr, err := r.client.UpdateVirtualMachine(p)
if newr != nil {
*r = *newr
} else {
newr = new(VirtualMachine)
newr.setClient(r.client)
*r = *newr
}
return err
}
func (r *VirtualMachine) Delete() (err error) {
p := NewDestroyVirtualMachineParameter(r.Id.String())
p.Expunge.Set(true)
newr, err := r.client.DestroyVirtualMachine(p)
if newr != nil {
*r = *newr
} else {
newr = new(VirtualMachine)
newr.setClient(r.client)
*r = *newr
}
return err
}