-
Notifications
You must be signed in to change notification settings - Fork 1
/
zone.go.orig
66 lines (59 loc) · 1.83 KB
/
zone.go.orig
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
package main
import (
"fmt"
// "github.com/OpenNebula/goca"
"github.com/OpenNebula/one/src/oca/go/src/goca"
"log"
"strconv"
)
const (
endpoint = "http://localhost:2633/RPC2"
user = "oneadmin"
pass = "opennebula"
)
func main() {
conf := goca.NewConfig(user,pass,endpoint)
client := goca.NewDefaultClient(conf)
id := 0
controller := goca.NewController(client)
// Retrieve zone info
zone, err := controller.Zone(id).Info(false)
if err != nil {
log.Fatalf("Zone id %d: %s", id, err)
}
for _, server := range zone.ServerPool {
fmt.Println(server)
var HOST,_ = controller.Host(server.ID).Info(false)
fmt.Println(HOST.Name)
conf.Endpoint = server.Endpoint
client = goca.NewDefaultClient(conf)
controller.Client = client
// Fetch the raft status of the server behind the endpoint
status, err := controller.Zones().ServerRaftStatus()
if err != nil {
log.Fatalf("Server raft status endpoint %s: %s", server.Endpoint, err)
}
// Display the Raft state of the server: Leader, Follower, Candidate, Error
state, err := status.State()
if err != nil {
log.Fatalf("Server raft state %d: %s", status.StateRaw, err)
}
fmt.Printf("server: %s, state: %s commit_index: %s log_index: %s\n", server.Name, state.String(),strconv.Itoa(status.Commit),strconv.Itoa(status.LogIndex))
fmt.Printf(strconv.Itoa(HOST.Share.FreeDisk))
}
// Get short informations of the VMs
vms, err := controller.VMs().Info()
if err != nil {
log.Fatal(err)
}
for i := 0; i < len(vms.VMs); i++ {
// This Info method, per VM instance, give us detailed informations on the instance
// Check xsd files to see the difference
vm, err := controller.VM(vms.VMs[i].ID).Info(false)
if err != nil {
log.Fatal(err)
}
//Do some others stuffs on vm
fmt.Printf("%+v\n", vm.HistoryRecords)
}
}