-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm.go
36 lines (28 loc) · 1.32 KB
/
vm.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
package main
import (
"main/cloudstack"
"log"
"fmt"
)
func main() {
// Create a new API client
cs := cloudstack.NewAsyncClient("http://10.15.9.154:8080/client/api", "36YF1nADgAC8cRKpw3edWxsgwZogtsYLZj6zNOYXOBCbXP0EwPEniNo4sM67IUCltinQEclCnwtFub3T-2Rx8g", "1x0_ugn4TFW_VMdGTXPtkB7Lv8_RxxqdTIjGLeKGbQeg86zzwGDUzdJR8PJzvXwoZrcAsqKjZiVoDOHb5unYhA", false)
// Create a new parameter struct
p := cs.VirtualMachine.NewListVirtualMachinesParams()
// Start new virtual machine
r, err := cs.VirtualMachine.ListVirtualMachines(p)
if err != nil {
log.Fatalf("Error listing the virtual machines: %s ", err)
}
for _, vm := range r.VirtualMachines{
cs1 := cloudstack.NewAsyncClient("http://10.15.9.154:8080/client/api", "36YF1nADgAC8cRKpw3edWxsgwZogtsYLZj6zNOYXOBCbXP0EwPEniNo4sM67IUCltinQEclCnwtFub3T-2Rx8g", "1x0_ugn4TFW_VMdGTXPtkB7Lv8_RxxqdTIjGLeKGbQeg86zzwGDUzdJR8PJzvXwoZrcAsqKjZiVoDOHb5unYhA", false)
// Create a new parameter struct
p := cs1.VirtualMachine.NewStartVirtualMachineParams(vm.Id)
// Start new virtual machine
r1, err1 := cs.VirtualMachine.StartVirtualMachine(p)
if err1 != nil {
log.Fatalf("Error creating the new instance: %s", err1)
}
fmt.Printf("UUID or the newly started machine: %s", r1.Id)
}
}