diff --git a/src/oca/go/src/goca/host.go b/src/oca/go/src/goca/host.go index 1deff4502b..48fb5bafd2 100644 --- a/src/oca/go/src/goca/host.go +++ b/src/oca/go/src/goca/host.go @@ -113,12 +113,19 @@ func (hc *HostsController) Create(name, im, vm string, clusterID int) (int, erro // Monitoring Returns the Hosts monitoring records // num: Retrieve monitor records in the last num seconds. // 0 just the last record, -1 all records -func (hc *HostsController) Monitoring(num int) (string, error) { +func (hc *HostsController) Monitoring(num int) (*host.PoolMonitoring, error) { monitorData, err := hc.c.Client.Call("one.hostpool.monitoring", num) if err != nil { - return "", err + return nil, err } - return monitorData.Body(), nil + + hostsMon := &host.PoolMonitoring{} + err = xml.Unmarshal([]byte(monitorData.Body()), &hostsMon) + if err != nil { + return nil, err + } + + return hostsMon, nil } // Delete deletes the given host from the pool @@ -151,10 +158,17 @@ func (hc *HostController) Rename(newName string) error { } // Monitoring returns the host monitoring records. -func (hc *HostController) Monitoring() (string, error) { +func (hc *HostController) Monitoring() (*host.Monitoring, error) { monitorData, err := hc.c.Client.Call("one.host.monitoring", hc.ID) if err != nil { - return "", err + return nil, err } - return monitorData.Body(), nil + + hostMon := &host.Monitoring{} + err = xml.Unmarshal([]byte(monitorData.Body()), &hostMon) + if err != nil { + return nil, err + } + + return hostMon, nil } diff --git a/src/oca/go/src/goca/schemas/host/host.go b/src/oca/go/src/goca/schemas/host/host.go index e129d9b055..bf29c48bc8 100644 --- a/src/oca/go/src/goca/schemas/host/host.go +++ b/src/oca/go/src/goca/schemas/host/host.go @@ -29,6 +29,12 @@ type Pool struct { Hosts []Host `xml:"HOST"` } +// PoolMonitoring contains the monitoring records of the hosts +type PoolMonitoring struct { + XMLName xml.Name `xml:"MONITORING_DATA"` + Records []dyn.Template `xml:"MONITORING"` +} + // Host represents an OpenNebula Host type Host struct { XMLName xml.Name `xml:"HOST"` @@ -41,12 +47,14 @@ type Host struct { Cluster string `xml:"CLUSTER,omitempty"` Share Share `xml:"HOST_SHARE,omitempty"` VMs shared.EntitiesID `xml:"VMS,omitempty"` - MonitoringInfos Monitoring `xml:"MONITORING,omitempty"` + MonitoringInfos dyn.Template `xml:"MONITORING,omitempty"` Template Template `xml:"TEMPLATE,omitempty"` } +// Monitoring contains the monitoring records of a host type Monitoring struct { - dyn.Template + XMLName xml.Name `xml:"MONITORING_DATA"` + Records []dyn.Template `xml:"MONITORING"` } type Share struct { diff --git a/src/oca/go/src/goca/schemas/vm/vm.go b/src/oca/go/src/goca/schemas/vm/vm.go index 58c7212d95..8635fae176 100644 --- a/src/oca/go/src/goca/schemas/vm/vm.go +++ b/src/oca/go/src/goca/schemas/vm/vm.go @@ -30,6 +30,12 @@ type Pool struct { VMs []VM `xml:"VM"` } +// PoolMonitoring contains the monitoring records of the VMs +type PoolMonitoring struct { + XMLName xml.Name `xml:"MONITORING_DATA"` + VMs []dyn.Template `xml:"MONITORING"` +} + // VM represents an OpenNebula Virtual Machine type VM struct { XMLName xml.Name `xml:"VM"` @@ -49,7 +55,7 @@ type VM struct { STime int `xml:"STIME,omitempty"` ETime int `xml:"ETIME,omitempty"` DeployID string `xml:"DEPLOY_ID,omitempty"` - MonitoringInfos Monitoring `xml:"MONITORING,omitempty"` + MonitoringInfos dyn.Template `xml:"MONITORING,omitempty"` Template Template `xml:"TEMPLATE,omitempty"` UserTemplate UserTemplate `xml:"USER_TEMPLATE,omitempty"` HistoryRecords []HistoryRecord `xml:"HISTORY_RECORDS>HISTORY,omitempty"` @@ -59,9 +65,10 @@ type VM struct { LockInfos *shared.Lock `xml:"LOCK"` } -// Monitoring is a dynamic VM part containing metrics +// Monitoring contains the monitoring records of a VM type Monitoring struct { - dyn.Template + XMLName xml.Name `xml:"MONITORING_DATA"` + Records []dyn.Template `xml:"MONITORING"` } // History records diff --git a/src/oca/go/src/goca/vm.go b/src/oca/go/src/goca/vm.go index 8a6666a7d8..84f7ac8d5f 100644 --- a/src/oca/go/src/goca/vm.go +++ b/src/oca/go/src/goca/vm.go @@ -197,12 +197,19 @@ func (vc *VMController) Info(decrypt bool) (*vm.VM, error) { // >= 0: UID User's Resources // num: Retrieve monitor records in the last num seconds. // 0 just the last record, -1 all records -func (vc *VMsController) Monitoring(filter, num int) (string, error) { +func (vc *VMsController) Monitoring(filter, num int) (*vm.PoolMonitoring, error) { monitorData, err := vc.c.Client.Call("one.vmpool.monitoring", filter, num) if err != nil { - return "", err + return nil, err } - return monitorData.Body(), nil + + vmsMon := &vm.PoolMonitoring{} + err = xml.Unmarshal([]byte(monitorData.Body()), &vmsMon) + if err != nil { + return nil, err + } + + return vmsMon, nil } // Accounting returns the virtual machine history records @@ -285,12 +292,19 @@ func (vc *VMController) UpdateConf(tpl string) error { } // Monitoring Returns the virtual machine monitoring records -func (vc *VMController) Monitoring() (string, error) { +func (vc *VMController) Monitoring() (*vm.Monitoring, error) { monitorData, err := vc.c.Client.Call("one.vm.monitoring", vc.ID) if err != nil { - return "", err + return nil, err } - return monitorData.Body(), nil + + vmMon := &vm.Monitoring{} + err = xml.Unmarshal([]byte(monitorData.Body()), &vmMon) + if err != nil { + return nil, err + } + + return vmMon, nil } // Chown changes the owner/group of a VM. If uid or gid is -1 it will not