|
@@ -10,6 +10,7 @@ import (
|
|
|
"github.com/labstack/echo"
|
|
|
"io/ioutil"
|
|
|
"net/http"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
@@ -90,6 +91,26 @@ type addVMTask struct {
|
|
|
Value string `json:"Value,omitempty"`
|
|
|
} `json:"headers"`
|
|
|
}
|
|
|
+type VMStatistics struct {
|
|
|
+ Statistic []struct {
|
|
|
+ Kind string `json:"kind"`
|
|
|
+ Type string `json:"type"`
|
|
|
+ Unit string `json:"unit"`
|
|
|
+ Values struct {
|
|
|
+ Value []struct {
|
|
|
+ Datum float64 `json:"datum"`
|
|
|
+ } `json:"value"`
|
|
|
+ } `json:"values"`
|
|
|
+ VM struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"vm,omitempty"`
|
|
|
+ Name string `json:"name"`
|
|
|
+ Description string `json:"description"`
|
|
|
+ Href string `json:"href,omitempty"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"statistic"`
|
|
|
+}
|
|
|
|
|
|
func (o ovirt) vmStatus(uuid string) string {
|
|
|
type vmStatus struct {
|
|
@@ -511,11 +532,12 @@ func (o ovirt) addvm(c echo.Context) error {
|
|
|
if err != nil {
|
|
|
resp := _response{
|
|
|
Origin: "ovirt-addvm",
|
|
|
- Message: "Error on pars AddVMResponse",
|
|
|
+ Message: "Error on pars AddVMResponse: " + err.Error(),
|
|
|
Code: 1001,
|
|
|
}
|
|
|
- b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
- return c.String(http.StatusBadRequest, string(b))
|
|
|
+ //b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
+ return c.JSON(http.StatusBadRequest, resp)
|
|
|
+ //return c.String(http.StatusBadRequest, string(b))
|
|
|
}
|
|
|
{
|
|
|
|
|
@@ -594,8 +616,9 @@ func (o ovirt) addvm(c echo.Context) error {
|
|
|
Message: "Done",
|
|
|
Code: 1000,
|
|
|
}
|
|
|
- b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
- return c.String(http.StatusOK, string(b))
|
|
|
+ //b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
+ return c.JSON(http.StatusOK, resp)
|
|
|
+ //return c.String(http.StatusOK, string(b))
|
|
|
}
|
|
|
func (o ovirt) listVM(c echo.Context) error {
|
|
|
user := c.Get("user").(*jwt.Token)
|
|
@@ -628,8 +651,9 @@ func (o ovirt) listVM(c echo.Context) error {
|
|
|
Message: string(body),
|
|
|
Code: 1000,
|
|
|
}
|
|
|
- b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
- return c.String(http.StatusOK, string(b))
|
|
|
+ //b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
+ return c.JSON(http.StatusOK, resp)
|
|
|
+ //return c.String(http.StatusOK, string(b))
|
|
|
}
|
|
|
|
|
|
func (o ovirt) StartVM(c echo.Context) error {
|
|
@@ -644,7 +668,7 @@ func (o ovirt) StartVM(c echo.Context) error {
|
|
|
BA := _BA[len(_BA)-2]
|
|
|
url := OvirtURL + "/ovirt-engine/api/vms/" + vmuuid + "/start"
|
|
|
method := "POST"
|
|
|
- __json:="{\"async\":\"true\"}"
|
|
|
+ __json := "{\"async\":\"true\"}"
|
|
|
sha256 := sha256.Sum256([]byte(vmuuid))
|
|
|
var hashChannel = make(chan []byte, 1)
|
|
|
hashChannel <- sha256[:]
|
|
@@ -677,8 +701,9 @@ func (o ovirt) StartVM(c echo.Context) error {
|
|
|
Message: "Done",
|
|
|
Code: 1000,
|
|
|
}
|
|
|
- b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
- return c.String(http.StatusOK, string(b))
|
|
|
+ //b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
+ return c.JSON(http.StatusOK, resp)
|
|
|
+ //return c.String(http.StatusOK, string(b))
|
|
|
}
|
|
|
|
|
|
func (o ovirt) StopVM(c echo.Context) error {
|
|
@@ -693,7 +718,7 @@ func (o ovirt) StopVM(c echo.Context) error {
|
|
|
BA := _BA[len(_BA)-2]
|
|
|
url := OvirtURL + "/ovirt-engine/api/vms/" + vmuuid + "/shutdown"
|
|
|
method := "POST"
|
|
|
- __json:="{\"async\":\"true\"}"
|
|
|
+ __json := "{\"async\":\"true\"}"
|
|
|
sha256 := sha256.Sum256([]byte(vmuuid))
|
|
|
var hashChannel = make(chan []byte, 1)
|
|
|
hashChannel <- sha256[:]
|
|
@@ -726,8 +751,9 @@ func (o ovirt) StopVM(c echo.Context) error {
|
|
|
Message: "Done",
|
|
|
Code: 1000,
|
|
|
}
|
|
|
- b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
- return c.String(http.StatusOK, string(b))
|
|
|
+ //b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
+ return c.JSON(http.StatusOK, resp)
|
|
|
+ //return c.String(http.StatusOK, string(b))
|
|
|
}
|
|
|
|
|
|
func (o ovirt) RebootVM(c echo.Context) error {
|
|
@@ -742,7 +768,7 @@ func (o ovirt) RebootVM(c echo.Context) error {
|
|
|
BA := _BA[len(_BA)-2]
|
|
|
url := OvirtURL + "/ovirt-engine/api/vms/" + vmuuid + "/reboot"
|
|
|
method := "POST"
|
|
|
- __json:="{\"async\":\"true\"}"
|
|
|
+ __json := "{\"async\":\"true\"}"
|
|
|
sha256 := sha256.Sum256([]byte(vmuuid))
|
|
|
var hashChannel = make(chan []byte, 1)
|
|
|
hashChannel <- sha256[:]
|
|
@@ -775,8 +801,9 @@ func (o ovirt) RebootVM(c echo.Context) error {
|
|
|
Message: "Done",
|
|
|
Code: 1000,
|
|
|
}
|
|
|
- b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
- return c.String(http.StatusOK, string(b))
|
|
|
+ //b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
+ //return c.String(http.StatusOK, string(b))
|
|
|
+ return c.JSON(http.StatusOK, resp)
|
|
|
}
|
|
|
func (o ovirt) PowerOffVM(c echo.Context) error {
|
|
|
vmuuid := c.FormValue("VmUUID")
|
|
@@ -790,7 +817,7 @@ func (o ovirt) PowerOffVM(c echo.Context) error {
|
|
|
BA := _BA[len(_BA)-2]
|
|
|
url := OvirtURL + "/ovirt-engine/api/vms/" + vmuuid + "/stop"
|
|
|
method := "POST"
|
|
|
- __json:="{\"async\":\"true\"}"
|
|
|
+ __json := "{\"async\":\"true\"}"
|
|
|
sha256 := sha256.Sum256([]byte(vmuuid))
|
|
|
var hashChannel = make(chan []byte, 1)
|
|
|
hashChannel <- sha256[:]
|
|
@@ -823,8 +850,9 @@ func (o ovirt) PowerOffVM(c echo.Context) error {
|
|
|
Message: "Done",
|
|
|
Code: 1000,
|
|
|
}
|
|
|
- b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
- return c.String(http.StatusOK, string(b))
|
|
|
+ //b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
+ //return c.String(http.StatusOK, string(b))
|
|
|
+ return c.JSON(http.StatusOK, resp)
|
|
|
}
|
|
|
|
|
|
func (o ovirt) ResetVM(c echo.Context) error {
|
|
@@ -833,8 +861,9 @@ func (o ovirt) ResetVM(c echo.Context) error {
|
|
|
Message: "not implemented",
|
|
|
Code: 1003,
|
|
|
}
|
|
|
- b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
- return c.String(http.StatusOK, string(b))
|
|
|
+ //b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
+ return c.JSON(http.StatusOK, resp)
|
|
|
+ //return c.String(http.StatusOK, string(b))
|
|
|
|
|
|
}
|
|
|
|
|
@@ -844,9 +873,9 @@ func (o ovirt) AddNIC(c echo.Context) error {
|
|
|
Message: "Done",
|
|
|
Code: 1000,
|
|
|
}
|
|
|
- b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
- return c.String(http.StatusOK, string(b))
|
|
|
-
|
|
|
+ //b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
+ //return c.String(http.StatusOK, string(b))
|
|
|
+ return c.JSON(http.StatusOK, resp)
|
|
|
}
|
|
|
|
|
|
func (o ovirt) AddDisk(c echo.Context) error {
|
|
@@ -855,9 +884,9 @@ func (o ovirt) AddDisk(c echo.Context) error {
|
|
|
Message: "Done",
|
|
|
Code: 1000,
|
|
|
}
|
|
|
- b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
- return c.String(http.StatusOK, string(b))
|
|
|
-
|
|
|
+ //b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
+ //return c.String(http.StatusOK, string(b))
|
|
|
+ return c.JSON(http.StatusOK, resp)
|
|
|
}
|
|
|
|
|
|
func (o ovirt) EditVM(c echo.Context) error {
|
|
@@ -866,9 +895,9 @@ func (o ovirt) EditVM(c echo.Context) error {
|
|
|
Message: "Done",
|
|
|
Code: 1000,
|
|
|
}
|
|
|
- b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
- return c.String(http.StatusOK, string(b))
|
|
|
-
|
|
|
+ //b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
+ //return c.String(http.StatusOK, string(b))
|
|
|
+ return c.JSON(http.StatusOK, resp)
|
|
|
}
|
|
|
|
|
|
func (o ovirt) ResetPassword(c echo.Context) error {
|
|
@@ -877,7 +906,494 @@ func (o ovirt) ResetPassword(c echo.Context) error {
|
|
|
Message: "not implemented",
|
|
|
Code: 1003,
|
|
|
}
|
|
|
- b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
- return c.String(http.StatusOK, string(b))
|
|
|
+ //b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
+ //return c.String(http.StatusOK, string(b))
|
|
|
+ return c.JSON(http.StatusOK, resp)
|
|
|
+}
|
|
|
+
|
|
|
+func vmStatistics(BA string, VMUUID string) (string, float64, float64) {
|
|
|
+ //ram,cpu,storage
|
|
|
+ var _disk []string
|
|
|
+ {
|
|
|
+ type DiskAttachments struct {
|
|
|
+ DiskAttachment []struct {
|
|
|
+ Active string `json:"active"`
|
|
|
+ Bootable string `json:"bootable"`
|
|
|
+ Interface string `json:"interface"`
|
|
|
+ LogicalName string `json:"logical_name"`
|
|
|
+ PassDiscard string `json:"pass_discard"`
|
|
|
+ ReadOnly string `json:"read_only"`
|
|
|
+ UsesScsiReservation string `json:"uses_scsi_reservation"`
|
|
|
+ Disk struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"disk"`
|
|
|
+ VM struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"vm"`
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"disk_attachment"`
|
|
|
+ }
|
|
|
+
|
|
|
+ url := OvirtURL + "/ovirt-engine/api/vms/" + VMUUID + "/diskattachments"
|
|
|
+ //fmt.Println("Url:" ,url)
|
|
|
+ method := "GET"
|
|
|
+
|
|
|
+ client := &http.Client{
|
|
|
+ }
|
|
|
+ req, err := http.NewRequest(method, url, nil)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return "", -1, -1
|
|
|
+ }
|
|
|
+ req.Header.Add("Version", "4")
|
|
|
+ req.Header.Add("Accept", "application/json")
|
|
|
+ req.Header.Add("Authorization", BA)
|
|
|
+
|
|
|
+ res, err := client.Do(req)
|
|
|
+ defer res.Body.Close()
|
|
|
+ body, err := ioutil.ReadAll(res.Body)
|
|
|
+ diskattachments := DiskAttachments{}
|
|
|
+ _err := json.Unmarshal(body, &diskattachments)
|
|
|
+ if _err != nil {
|
|
|
+ fmt.Println("Error: ", _err)
|
|
|
+ }
|
|
|
+ for _, v := range diskattachments.DiskAttachment {
|
|
|
+ url := OvirtURL + "/ovirt-engine/api/disks/" + v.Disk.ID
|
|
|
+ type DiskAttachment struct {
|
|
|
+ ActualSize string `json:"actual_size"`
|
|
|
+ Alias string `json:"alias"`
|
|
|
+ Backup string `json:"backup"`
|
|
|
+ ContentType string `json:"content_type"`
|
|
|
+ Format string `json:"format"`
|
|
|
+ ImageID string `json:"image_id"`
|
|
|
+ PropagateErrors string `json:"propagate_errors"`
|
|
|
+ ProvisionedSize string `json:"provisioned_size"`
|
|
|
+ QcowVersion string `json:"qcow_version"`
|
|
|
+ Shareable string `json:"shareable"`
|
|
|
+ Sparse string `json:"sparse"`
|
|
|
+ Status string `json:"status"`
|
|
|
+ StorageType string `json:"storage_type"`
|
|
|
+ TotalSize string `json:"total_size"`
|
|
|
+ WipeAfterDelete string `json:"wipe_after_delete"`
|
|
|
+ DiskProfile struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"disk_profile"`
|
|
|
+ Quota struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"quota"`
|
|
|
+ StorageDomains struct {
|
|
|
+ StorageDomain []struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"storage_domain"`
|
|
|
+ } `json:"storage_domains"`
|
|
|
+ Actions struct {
|
|
|
+ Link []struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ Rel string `json:"rel"`
|
|
|
+ } `json:"link"`
|
|
|
+ } `json:"actions"`
|
|
|
+ Name string `json:"name"`
|
|
|
+ Description string `json:"description"`
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ Link []struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ Rel string `json:"rel"`
|
|
|
+ } `json:"link"`
|
|
|
+ }
|
|
|
+ //fmt.Println("Url:" ,url)
|
|
|
+ method := "GET"
|
|
|
+
|
|
|
+ client := &http.Client{
|
|
|
+ }
|
|
|
+ req, _ := http.NewRequest(method, url, nil)
|
|
|
+
|
|
|
+ //if err != nil {
|
|
|
+ // return "Null"
|
|
|
+ //}
|
|
|
+ req.Header.Add("Version", "4")
|
|
|
+ req.Header.Add("Accept", "application/json")
|
|
|
+ req.Header.Add("Authorization", BA)
|
|
|
+
|
|
|
+ res, _ := client.Do(req)
|
|
|
+ defer res.Body.Close()
|
|
|
+ body, _ := ioutil.ReadAll(res.Body)
|
|
|
+
|
|
|
+ //fmt.Println("full response: ",string(body))
|
|
|
+ disk := DiskAttachment{}
|
|
|
+ _err := json.Unmarshal(body, &disk)
|
|
|
+ if _err != nil {
|
|
|
+ fmt.Println("Error: ", _err)
|
|
|
+ }
|
|
|
+ _disk = append(_disk, disk.ProvisionedSize)
|
|
|
+
|
|
|
+ //_disk = D_disk + "" + disk.ProvisionedSize+" "
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ url := OvirtURL + "/ovirt-engine/api/vms/" + VMUUID + "/statistics"
|
|
|
+ //fmt.Println("Url:" ,url)
|
|
|
+ method := "GET"
|
|
|
|
|
|
+ client := &http.Client{
|
|
|
+ }
|
|
|
+ req, err := http.NewRequest(method, url, nil)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return "", -1, -1
|
|
|
+ }
|
|
|
+ req.Header.Add("Version", "4")
|
|
|
+ req.Header.Add("Accept", "application/json")
|
|
|
+ req.Header.Add("Authorization", BA)
|
|
|
+
|
|
|
+ res, err := client.Do(req)
|
|
|
+ defer res.Body.Close()
|
|
|
+ body, err := ioutil.ReadAll(res.Body)
|
|
|
+
|
|
|
+ //fmt.Println("full response: ",string(body))
|
|
|
+ _vmstatistics := VMStatistics{}
|
|
|
+ _err := json.Unmarshal(body, &_vmstatistics)
|
|
|
+ if _err != nil {
|
|
|
+ fmt.Println("Error: ", _err)
|
|
|
+ }
|
|
|
+ cpuUUID := _vmstatistics.Statistic[4].ID
|
|
|
+ memUsedUUID := _vmstatistics.Statistic[1].ID
|
|
|
+ memTotalUUID := _vmstatistics.Statistic[0].ID
|
|
|
+ //fmt.Println(memUsedUUID)
|
|
|
+ var cpu, memUsed, memTotal string
|
|
|
+ type ItemUsage struct {
|
|
|
+ Kind string `json:"kind"`
|
|
|
+ Type string `json:"type"`
|
|
|
+ Unit string `json:"unit"`
|
|
|
+ Values struct {
|
|
|
+ Value []struct {
|
|
|
+ Datum float64 `json:"datum"`
|
|
|
+ } `json:"value"`
|
|
|
+ } `json:"values"`
|
|
|
+ VM struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"vm"`
|
|
|
+ Name string `json:"name"`
|
|
|
+ Description string `json:"description"`
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ }
|
|
|
+ {
|
|
|
+ url := OvirtURL + "/ovirt-engine/api/vms/" + VMUUID + "/statistics/" + cpuUUID
|
|
|
+ //fmt.Println("Url:" ,url)
|
|
|
+ method := "GET"
|
|
|
+
|
|
|
+ client := &http.Client{
|
|
|
+ }
|
|
|
+ req, err := http.NewRequest(method, url, nil)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return "", -1, -1
|
|
|
+ }
|
|
|
+ req.Header.Add("Version", "4")
|
|
|
+ req.Header.Add("Accept", "application/json")
|
|
|
+ req.Header.Add("Authorization", BA)
|
|
|
+
|
|
|
+ res, err := client.Do(req)
|
|
|
+ defer res.Body.Close()
|
|
|
+ body, err := ioutil.ReadAll(res.Body)
|
|
|
+ cpuUsage := ItemUsage{}
|
|
|
+ _err := json.Unmarshal(body, &cpuUsage)
|
|
|
+ if _err != nil {
|
|
|
+ fmt.Println("Error: ", _err)
|
|
|
+ }
|
|
|
+ cpu = fmt.Sprintf("%f", cpuUsage.Values.Value[0].Datum)
|
|
|
+ }
|
|
|
+ {
|
|
|
+ url := OvirtURL + "/ovirt-engine/api/vms/" + VMUUID + "/statistics/" + memUsedUUID
|
|
|
+ //fmt.Println("Url:" ,url)
|
|
|
+ method := "GET"
|
|
|
+
|
|
|
+ client := &http.Client{
|
|
|
+ }
|
|
|
+ req, err := http.NewRequest(method, url, nil)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return "", -1, -1
|
|
|
+ }
|
|
|
+ req.Header.Add("Version", "4")
|
|
|
+ req.Header.Add("Accept", "application/json")
|
|
|
+ req.Header.Add("Authorization", BA)
|
|
|
+
|
|
|
+ res, err := client.Do(req)
|
|
|
+ defer res.Body.Close()
|
|
|
+ body, err := ioutil.ReadAll(res.Body)
|
|
|
+ memUsage := ItemUsage{}
|
|
|
+ _err := json.Unmarshal(body, &memUsage)
|
|
|
+ if _err != nil {
|
|
|
+ fmt.Println("Error: ", _err)
|
|
|
+ }
|
|
|
+ memUsed = fmt.Sprintf("%f", memUsage.Values.Value[0].Datum)
|
|
|
+ }
|
|
|
+ {
|
|
|
+ url := OvirtURL + "/ovirt-engine/api/vms/" + VMUUID + "/statistics/" + memTotalUUID
|
|
|
+ //fmt.Println("Url:" ,url)
|
|
|
+ method := "GET"
|
|
|
+
|
|
|
+ client := &http.Client{
|
|
|
+ }
|
|
|
+ req, err := http.NewRequest(method, url, nil)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return "", -1, -1
|
|
|
+ }
|
|
|
+ req.Header.Add("Version", "4")
|
|
|
+ req.Header.Add("Accept", "application/json")
|
|
|
+ req.Header.Add("Authorization", BA)
|
|
|
+
|
|
|
+ res, err := client.Do(req)
|
|
|
+ defer res.Body.Close()
|
|
|
+ body, err := ioutil.ReadAll(res.Body)
|
|
|
+ memUsage := ItemUsage{}
|
|
|
+ _err := json.Unmarshal(body, &memUsage)
|
|
|
+ if _err != nil {
|
|
|
+ fmt.Println("Error: ", _err)
|
|
|
+ }
|
|
|
+ memTotal = fmt.Sprintf("%f", memUsage.Values.Value[0].Datum)
|
|
|
+ }
|
|
|
+ //fmt.Println("CPU:" ,cpu)
|
|
|
+ //fmt.Println("MEM:", memUsed)
|
|
|
+ //fmt.Println("MEM:", memTotal)
|
|
|
+ _memusage, _ := strconv.ParseFloat(memUsed, 32)
|
|
|
+ _memtotal, _ := strconv.ParseFloat(memTotal, 32)
|
|
|
+ mem := _memusage / _memtotal
|
|
|
+
|
|
|
+ _cpu, _ := strconv.ParseFloat(cpu, 64)
|
|
|
+ return strings.Join(_disk,", "), _cpu, mem
|
|
|
+
|
|
|
+}
|
|
|
+func (o ovirt) vmDetails(c echo.Context) error {
|
|
|
+ //name,...,traffic,ip,status
|
|
|
+ user := c.Get("user").(*jwt.Token)
|
|
|
+ claims := user.Claims.(jwt.MapClaims)
|
|
|
+ _sha256 := sha256.Sum256([]byte(string(claims["name"].(string))))
|
|
|
+ var hashChannel_ = make(chan []byte, 1)
|
|
|
+ hashChannel_ <- _sha256[:]
|
|
|
+ token := decrypt(<-hashChannel_, claims["IPAToken"].(string))
|
|
|
+ _BA := strings.Split(token, ";")
|
|
|
+ BA := _BA[len(_BA)-2]
|
|
|
+ uuid := c.FormValue("uuid")
|
|
|
+ if len(uuid) < 5 {
|
|
|
+ resp := _response{
|
|
|
+ Origin: "AddUser",
|
|
|
+ Message: "Missing UUID",
|
|
|
+ Code: 1001,
|
|
|
+ }
|
|
|
+ return c.JSON(http.StatusNotFound, resp)
|
|
|
+ }
|
|
|
+ type vmStatus struct {
|
|
|
+ NextRunConfigurationExists string `json:"next_run_configuration_exists"`
|
|
|
+ NumaTuneMode string `json:"numa_tune_mode"`
|
|
|
+ Status string `json:"status"`
|
|
|
+ StopTime int64 `json:"stop_time"`
|
|
|
+ OriginalTemplate struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"original_template"`
|
|
|
+ Template struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"template"`
|
|
|
+ Actions struct {
|
|
|
+ Link []struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ Rel string `json:"rel"`
|
|
|
+ } `json:"link"`
|
|
|
+ } `json:"actions"`
|
|
|
+ Name string `json:"name"`
|
|
|
+ Description string `json:"description"`
|
|
|
+ Comment string `json:"comment"`
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ Bios struct {
|
|
|
+ BootMenu struct {
|
|
|
+ Enabled string `json:"enabled"`
|
|
|
+ } `json:"boot_menu"`
|
|
|
+ Type string `json:"type"`
|
|
|
+ } `json:"bios"`
|
|
|
+ CPU struct {
|
|
|
+ Architecture string `json:"architecture"`
|
|
|
+ Topology struct {
|
|
|
+ Cores string `json:"cores"`
|
|
|
+ Sockets string `json:"sockets"`
|
|
|
+ Threads string `json:"threads"`
|
|
|
+ } `json:"topology"`
|
|
|
+ } `json:"cpu"`
|
|
|
+ Display struct {
|
|
|
+ AllowOverride string `json:"allow_override"`
|
|
|
+ CopyPasteEnabled string `json:"copy_paste_enabled"`
|
|
|
+ DisconnectAction string `json:"disconnect_action"`
|
|
|
+ FileTransferEnabled string `json:"file_transfer_enabled"`
|
|
|
+ Monitors string `json:"monitors"`
|
|
|
+ SingleQxlPci string `json:"single_qxl_pci"`
|
|
|
+ SmartcardEnabled string `json:"smartcard_enabled"`
|
|
|
+ Type string `json:"type"`
|
|
|
+ } `json:"display"`
|
|
|
+ Initialization struct {
|
|
|
+ AuthorizedSSHKeys string `json:"authorized_ssh_keys"`
|
|
|
+ CloudInitNetworkProtocol string `json:"cloud_init_network_protocol"`
|
|
|
+ CustomScript string `json:"custom_script"`
|
|
|
+ HostName string `json:"host_name"`
|
|
|
+ NicConfigurations struct {
|
|
|
+ } `json:"nic_configurations"`
|
|
|
+ RegenerateSSHKeys string `json:"regenerate_ssh_keys"`
|
|
|
+ UserName string `json:"user_name"`
|
|
|
+ } `json:"initialization"`
|
|
|
+ Io struct {
|
|
|
+ Threads string `json:"threads"`
|
|
|
+ } `json:"io"`
|
|
|
+ Memory string `json:"memory"`
|
|
|
+ Migration struct {
|
|
|
+ AutoConverge string `json:"auto_converge"`
|
|
|
+ Compressed string `json:"compressed"`
|
|
|
+ Encrypted string `json:"encrypted"`
|
|
|
+ } `json:"migration"`
|
|
|
+ Origin string `json:"origin"`
|
|
|
+ Os struct {
|
|
|
+ Boot struct {
|
|
|
+ Devices struct {
|
|
|
+ Device []string `json:"device"`
|
|
|
+ } `json:"devices"`
|
|
|
+ } `json:"boot"`
|
|
|
+ Type string `json:"type"`
|
|
|
+ } `json:"os"`
|
|
|
+ Sso struct {
|
|
|
+ Methods struct {
|
|
|
+ Method []struct {
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"method"`
|
|
|
+ } `json:"methods"`
|
|
|
+ } `json:"sso"`
|
|
|
+ Stateless string `json:"stateless"`
|
|
|
+ Type string `json:"type"`
|
|
|
+ Usb struct {
|
|
|
+ Enabled string `json:"enabled"`
|
|
|
+ } `json:"usb"`
|
|
|
+ Cluster struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"cluster"`
|
|
|
+ Quota struct {
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"quota"`
|
|
|
+ Link []struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ Rel string `json:"rel"`
|
|
|
+ } `json:"link"`
|
|
|
+ CPUShares string `json:"cpu_shares"`
|
|
|
+ CreationTime int64 `json:"creation_time"`
|
|
|
+ DeleteProtected string `json:"delete_protected"`
|
|
|
+ HighAvailability struct {
|
|
|
+ Enabled string `json:"enabled"`
|
|
|
+ Priority string `json:"priority"`
|
|
|
+ } `json:"high_availability"`
|
|
|
+ LargeIcon struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"large_icon"`
|
|
|
+ MemoryPolicy struct {
|
|
|
+ Ballooning string `json:"ballooning"`
|
|
|
+ Guaranteed string `json:"guaranteed"`
|
|
|
+ Max string `json:"max"`
|
|
|
+ } `json:"memory_policy"`
|
|
|
+ MigrationDowntime string `json:"migration_downtime"`
|
|
|
+ MultiQueuesEnabled string `json:"multi_queues_enabled"`
|
|
|
+ PlacementPolicy struct {
|
|
|
+ Affinity string `json:"affinity"`
|
|
|
+ Hosts struct {
|
|
|
+ Host []struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"host"`
|
|
|
+ } `json:"hosts"`
|
|
|
+ } `json:"placement_policy"`
|
|
|
+ SmallIcon struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"small_icon"`
|
|
|
+ StartPaused string `json:"start_paused"`
|
|
|
+ StorageErrorResumeBehaviour string `json:"storage_error_resume_behaviour"`
|
|
|
+ TimeZone struct {
|
|
|
+ Name string `json:"name"`
|
|
|
+ } `json:"time_zone"`
|
|
|
+ CPUProfile struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"cpu_profile"`
|
|
|
+ }
|
|
|
+ //url := "https://ovirt-cl.zi-tel.com/ovirt-engine/api/vms/c1a44128-6c6c-406b-99d8-4a68a99380c9"
|
|
|
+ url := OvirtURL + "/ovirt-engine/api/vms/" + uuid
|
|
|
+ //fmt.Println("Url:" ,url)
|
|
|
+ method := "GET"
|
|
|
+
|
|
|
+ client := &http.Client{
|
|
|
+ }
|
|
|
+ req, _ := http.NewRequest(method, url, nil)
|
|
|
+
|
|
|
+ //if err != nil {
|
|
|
+ // return "Null"
|
|
|
+ //}
|
|
|
+ req.Header.Add("Version", "4")
|
|
|
+ req.Header.Add("Accept", "application/json")
|
|
|
+ req.Header.Add("Authorization", BA)
|
|
|
+
|
|
|
+ res, _ := client.Do(req)
|
|
|
+ defer res.Body.Close()
|
|
|
+ body, _ := ioutil.ReadAll(res.Body)
|
|
|
+
|
|
|
+ //fmt.Println("full response: ",string(body))
|
|
|
+ _vmstatus := vmStatus{}
|
|
|
+ _err := json.Unmarshal(body, &_vmstatus)
|
|
|
+ if _err != nil {
|
|
|
+ fmt.Println("Error: ", _err)
|
|
|
+ }
|
|
|
+ disk, cpu, ram := vmStatistics(BA, uuid)
|
|
|
+ type AutoGenerated struct {
|
|
|
+ Message struct {
|
|
|
+ Disk string `json:"Disk"`
|
|
|
+ Memory string `json:"Memory"`
|
|
|
+ CPU string `json:"CPU"`
|
|
|
+ NetAddress string `json:"NetAddress"`
|
|
|
+ Traffic string `json:"Traffic"`
|
|
|
+ Status string `json:"Status"`
|
|
|
+ Name string `json:"Name"`
|
|
|
+ } `json:"message"`
|
|
|
+ Origin string `json:"origin"`
|
|
|
+ Code int `json:"code"`
|
|
|
+ }
|
|
|
+ resp := AutoGenerated{
|
|
|
+ Message: struct {
|
|
|
+ Disk string `json:"Disk"`
|
|
|
+ Memory string `json:"Memory"`
|
|
|
+ CPU string `json:"CPU"`
|
|
|
+ NetAddress string `json:"NetAddress"`
|
|
|
+ Traffic string `json:"Traffic"`
|
|
|
+ Status string `json:"Status"`
|
|
|
+ Name string `json:"Name"`
|
|
|
+ }{
|
|
|
+ Disk: disk,
|
|
|
+ Memory: fmt.Sprintf("%f", ram),
|
|
|
+ CPU: fmt.Sprintf("%f", cpu),
|
|
|
+ NetAddress: "",
|
|
|
+ Traffic: "",
|
|
|
+ Status: _vmstatus.Status,
|
|
|
+ Name: _vmstatus.Name,
|
|
|
+ },
|
|
|
+ Origin: "vmDetails",
|
|
|
+ Code: 1000,
|
|
|
+ }
|
|
|
+ return c.JSON(http.StatusOK, resp)
|
|
|
+ //return _vmstatus.Status, _vmstatus.Name, disk, cpu, ram
|
|
|
}
|