|
@@ -1285,15 +1285,398 @@ func (o ovirt) AddDisk(c echo.Context) error {
|
|
|
return c.JSON(http.StatusOK, resp)
|
|
|
}
|
|
|
func (o ovirt) EditVM(c echo.Context) error {
|
|
|
- resp := _response{
|
|
|
- Origin: "ovirt-EditVM",
|
|
|
+ type VMDescr struct {
|
|
|
+ VMName string `json:"vmname"`
|
|
|
+ VMCpu string `json:"vmCpu"`
|
|
|
+ VMMem string `json:"vmMem"`
|
|
|
+ VMNIC string `json:"vmnic"`
|
|
|
+ VMBW string `json:"vmbw"`
|
|
|
+ VMUUID string `json:"vmuuid"`
|
|
|
+ Invoice string `json:"invoice"`
|
|
|
+ }
|
|
|
+ type EditVMPayment struct {
|
|
|
+ Data struct {
|
|
|
+ Price struct {
|
|
|
+ CPU float64 `json:"cpu"`
|
|
|
+ Mem float64 `json:"mem"`
|
|
|
+ Disk float64 `json:"disk"`
|
|
|
+ Nic float64 `json:"nic"`
|
|
|
+ BW float64 `json:"bw"`
|
|
|
+ SUM float64 `json:"sum"`
|
|
|
+ SUMRaw float64 `json:"SUMRaw"`
|
|
|
+ Period string `json:"period"`
|
|
|
+ } `json:"price"`
|
|
|
+ InvoiceUUID string `json:"invoiceUUID"`
|
|
|
+ } `json:"data"`
|
|
|
+ Message string `json:"message"`
|
|
|
+ Origin string `json:"origin"`
|
|
|
+ Code int `json:"code"`
|
|
|
+ }
|
|
|
+ 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]
|
|
|
+ var vmname, vmuuid, vmdescr, vmcomment, templatename, cpuSock, cpuCore, cpuThread, mem, Disk, nic, period, extraBW string
|
|
|
+ coupon := 0
|
|
|
+ vmname = login(BA).AuthenticatedUser.ID + "-_-" + c.FormValue("VmName")
|
|
|
+ vmdescr = c.FormValue("VmDescr")
|
|
|
+ vmcomment = c.FormValue("VmComment")
|
|
|
+ templatename = c.FormValue("VmTempl")
|
|
|
+ cpuThread = c.FormValue("VmCPU")
|
|
|
+ Disk = c.FormValue("VmDisk")
|
|
|
+ period = c.FormValue("VmPeriod")
|
|
|
+ nic = c.FormValue("VmNIC")
|
|
|
+ extraBW = c.FormValue("extraBW")
|
|
|
+ vmuuid = c.FormValue("VMUUID")
|
|
|
+ // sshKey := c.FormValue("sshKey")
|
|
|
+ // rootpass := c.FormValue("rootpass")
|
|
|
+ coupon, _ = strconv.Atoi(c.FormValue("coupon"))
|
|
|
+ cpuCore = "1"
|
|
|
+ cpuSock = "1"
|
|
|
+ mem = c.FormValue("VmMem")
|
|
|
+ url := OvirtURL + "/ovirt-engine/api/vms"
|
|
|
+ method := "POST"
|
|
|
+ //addvmresponse := AddVMResponse{}O
|
|
|
+ editvm := AddVMRequest{
|
|
|
+ URL: url,
|
|
|
+ JSON: struct {
|
|
|
+ Name string `json:"name"`
|
|
|
+ Description string `json:"description"`
|
|
|
+ Comment string `json:"comment"`
|
|
|
+ Cluster struct {
|
|
|
+ Name string `json:"name"`
|
|
|
+ } `json:"cluster"`
|
|
|
+ Template struct {
|
|
|
+ Name string `json:"name"`
|
|
|
+ } `json:"template"`
|
|
|
+ CPU struct {
|
|
|
+ Topology struct {
|
|
|
+ Sockets string `json:"sockets"`
|
|
|
+ Cores string `json:"cores"`
|
|
|
+ Threads string `json:"threads"`
|
|
|
+ } `json:"topology"`
|
|
|
+ } `json:"cpu"`
|
|
|
+ Memory string `json:"memory"`
|
|
|
+ MemoryPolicy struct {
|
|
|
+ Ballooning string `json:"ballooning"`
|
|
|
+ Guaranteed string `json:"guaranteed"`
|
|
|
+ OverCommit struct {
|
|
|
+ Percent string `json:"percent"`
|
|
|
+ } `json:"over_commit"`
|
|
|
+ } `json:"memory_policy"`
|
|
|
+ }{
|
|
|
+ Name: vmname,
|
|
|
+ Description: vmdescr,
|
|
|
+ Comment: vmcomment,
|
|
|
+ Cluster: struct {
|
|
|
+ Name string `json:"name"`
|
|
|
+ }{Name: "Default"},
|
|
|
+ Template: struct {
|
|
|
+ Name string `json:"name"`
|
|
|
+ }{Name: templatename},
|
|
|
+ CPU: struct {
|
|
|
+ Topology struct {
|
|
|
+ Sockets string `json:"sockets"`
|
|
|
+ Cores string `json:"cores"`
|
|
|
+ Threads string `json:"threads"`
|
|
|
+ } `json:"topology"`
|
|
|
+ }{
|
|
|
+ struct {
|
|
|
+ Sockets string `json:"sockets"`
|
|
|
+ Cores string `json:"cores"`
|
|
|
+ Threads string `json:"threads"`
|
|
|
+ }{
|
|
|
+ Sockets: cpuSock,
|
|
|
+ Cores: cpuCore,
|
|
|
+ Threads: cpuThread,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ Memory: mem,
|
|
|
+ MemoryPolicy: struct {
|
|
|
+ Ballooning string `json:"ballooning"`
|
|
|
+ Guaranteed string `json:"guaranteed"`
|
|
|
+ OverCommit struct {
|
|
|
+ Percent string `json:"percent"`
|
|
|
+ } `json:"over_commit"`
|
|
|
+ }{
|
|
|
+ Ballooning: "true",
|
|
|
+ Guaranteed: mem,
|
|
|
+ OverCommit: struct {
|
|
|
+ Percent string `json:"percent"`
|
|
|
+ }{Percent: "10"},
|
|
|
+ },
|
|
|
+ },
|
|
|
+ Method: method,
|
|
|
+ Headers: nil,
|
|
|
+ }
|
|
|
+ editvm.Headers = append(editvm.Headers, struct {
|
|
|
+ Name string `json:"Name"`
|
|
|
+ Value string `json:"Value"`
|
|
|
+ }{
|
|
|
+ Name: "Accept",
|
|
|
+ Value: "application/json",
|
|
|
+ })
|
|
|
+ editvm.Headers = append(editvm.Headers, struct {
|
|
|
+ Name string `json:"Name"`
|
|
|
+ Value string `json:"Value"`
|
|
|
+ }{
|
|
|
+ Name: "Authorization",
|
|
|
+ Value: BA,
|
|
|
+ })
|
|
|
+ editvm.Headers = append(editvm.Headers, struct {
|
|
|
+ Name string `json:"Name"`
|
|
|
+ Value string `json:"Value"`
|
|
|
+ }{
|
|
|
+ Name: "Content-Type",
|
|
|
+ Value: "application/json",
|
|
|
+ })
|
|
|
+ // uuid, _ := uuidgen("APIGW-Ovirt-addVMTask")
|
|
|
+ //invoiceUUID, _ := uuidgen("APIGW-FakeInvoice")
|
|
|
+ CPUPrice, memPrice, StoragePrice, IPPrice, extraBWPrice, SUM, SUMRaw, invoiceUUID := IaaSEdit(login(BA).AuthenticatedUser.ID, period, cpuThread, mem, Disk, nic, extraBW, false, coupon, vmuuid)
|
|
|
+
|
|
|
+ type JSONDetails struct {
|
|
|
+ Name string `json:"name"`
|
|
|
+ Value string `json:"value"`
|
|
|
+ Type string `json:"type"`
|
|
|
+ }
|
|
|
+ /*_jsonDetail := [8]JSONDetails{}
|
|
|
+ {
|
|
|
+ _jsonDetail[0].Name = "Period"
|
|
|
+ _jsonDetail[0].Value = period
|
|
|
+ _jsonDetail[0].Type = "int"
|
|
|
+ _jsonDetail[1].Name = "cpuThread"
|
|
|
+ _jsonDetail[1].Value = cpuThread
|
|
|
+ _jsonDetail[1].Type = "int"
|
|
|
+ _jsonDetail[2].Name = "mem"
|
|
|
+ _jsonDetail[2].Value = mem
|
|
|
+ _jsonDetail[2].Type = "int"
|
|
|
+ _jsonDetail[3].Name = "Disk"
|
|
|
+ _jsonDetail[3].Value = Disk
|
|
|
+ _jsonDetail[3].Type = "int"
|
|
|
+ _jsonDetail[4].Name = "nic"
|
|
|
+ _jsonDetail[4].Value = nic
|
|
|
+ _jsonDetail[4].Type = "int"
|
|
|
+ _jsonDetail[5].Name = "extraBW"
|
|
|
+ _jsonDetail[5].Value = extraBW
|
|
|
+ _jsonDetail[5].Type = "int"
|
|
|
+ _jsonDetail[6].Name = "coupon"
|
|
|
+ _jsonDetail[6].Value = fmt.Sprintf("%d", coupon)
|
|
|
+ _jsonDetail[6].Type = "int"
|
|
|
+ _jsonDetail[7].Name = "Template"
|
|
|
+ _jsonDetail[7].Value = templatename
|
|
|
+ _jsonDetail[7].Type = "string"
|
|
|
+ }
|
|
|
+ jsonDetail, _ := json.Marshal(_jsonDetail)
|
|
|
+ */
|
|
|
+
|
|
|
+ responseInvoiece := EditVMPayment{
|
|
|
+ Data: struct {
|
|
|
+ Price struct {
|
|
|
+ CPU float64 `json:"cpu"`
|
|
|
+ Mem float64 `json:"mem"`
|
|
|
+ Disk float64 `json:"disk"`
|
|
|
+ Nic float64 `json:"nic"`
|
|
|
+ BW float64 `json:"bw"`
|
|
|
+ SUM float64 `json:"sum"`
|
|
|
+ SUMRaw float64 `json:"SUMRaw"`
|
|
|
+ Period string `json:"period"`
|
|
|
+ } `json:"price"`
|
|
|
+ InvoiceUUID string `json:"invoiceUUID"`
|
|
|
+ }{
|
|
|
+ Price: struct {
|
|
|
+ CPU float64 `json:"cpu"`
|
|
|
+ Mem float64 `json:"mem"`
|
|
|
+ Disk float64 `json:"disk"`
|
|
|
+ Nic float64 `json:"nic"`
|
|
|
+ BW float64 `json:"bw"`
|
|
|
+ SUM float64 `json:"sum"`
|
|
|
+ SUMRaw float64 `json:"SUMRaw"`
|
|
|
+ Period string `json:"period"`
|
|
|
+ }{
|
|
|
+ CPU: CPUPrice,
|
|
|
+ Mem: memPrice,
|
|
|
+ Disk: StoragePrice,
|
|
|
+ Nic: IPPrice,
|
|
|
+ BW: extraBWPrice,
|
|
|
+ SUM: SUM,
|
|
|
+ SUMRaw: SUMRaw,
|
|
|
+ Period: period,
|
|
|
+ },
|
|
|
+ InvoiceUUID: invoiceUUID,
|
|
|
+ },
|
|
|
Message: "Done",
|
|
|
+ Origin: "EditVM",
|
|
|
Code: 1000,
|
|
|
}
|
|
|
- //b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
- //return c.String(http.StatusOK, string(b))
|
|
|
- return c.JSON(http.StatusOK, resp)
|
|
|
+ responseInvoiece_fake := EditVMPayment{
|
|
|
+ Data: struct {
|
|
|
+ Price struct {
|
|
|
+ CPU float64 `json:"cpu"`
|
|
|
+ Mem float64 `json:"mem"`
|
|
|
+ Disk float64 `json:"disk"`
|
|
|
+ Nic float64 `json:"nic"`
|
|
|
+ BW float64 `json:"bw"`
|
|
|
+ SUM float64 `json:"sum"`
|
|
|
+ SUMRaw float64 `json:"SUMRaw"`
|
|
|
+ Period string `json:"period"`
|
|
|
+ } `json:"price"`
|
|
|
+ InvoiceUUID string `json:"invoiceUUID"`
|
|
|
+ }{
|
|
|
+ Price: struct {
|
|
|
+ CPU float64 `json:"cpu"`
|
|
|
+ Mem float64 `json:"mem"`
|
|
|
+ Disk float64 `json:"disk"`
|
|
|
+ Nic float64 `json:"nic"`
|
|
|
+ BW float64 `json:"bw"`
|
|
|
+ SUM float64 `json:"sum"`
|
|
|
+ SUMRaw float64 `json:"SUMRaw"`
|
|
|
+ Period string `json:"period"`
|
|
|
+ }{
|
|
|
+ CPU: 100,
|
|
|
+ Mem: 100,
|
|
|
+ Disk: 100,
|
|
|
+ Nic: 100,
|
|
|
+ BW: 100,
|
|
|
+ SUM: 100,
|
|
|
+ SUMRaw: 100,
|
|
|
+ Period: "12",
|
|
|
+ },
|
|
|
+ InvoiceUUID: "556a5032-09de-4430-b1e1-48a2ef84d62f",
|
|
|
+ },
|
|
|
+ Message: "Done",
|
|
|
+ Origin: "EditVM",
|
|
|
+ Code: 1000,
|
|
|
+ }
|
|
|
+ // if len(invoiceUUID) < 5 {
|
|
|
+ // resp := _response{
|
|
|
+ // Origin: "ovirt-editvm",
|
|
|
+ // Message: "Error on Invoice Calculation",
|
|
|
+ // Code: 1001,
|
|
|
+ // }
|
|
|
+ // b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
+ // return c.String(http.StatusBadRequest, string(b))
|
|
|
+ // }
|
|
|
+ fmt.Println("EditVM: ", editvm)
|
|
|
+ fmt.Print(responseInvoiece)
|
|
|
+ return c.JSON(http.StatusOK, responseInvoiece_fake)
|
|
|
+ // return c.JSON(http.StatusOK, fakeResponse)
|
|
|
+ // __createVM, _ := json.MarshalIndent(editvm, "", " ")
|
|
|
+ // Add VM Task
|
|
|
+ // addTask(uuid, string(__createVM), "", "APIGW", "VM Creation for "+claims["name"].(string), invoiceUUID, "0", "0")
|
|
|
+
|
|
|
+ /*
|
|
|
+
|
|
|
+ {
|
|
|
+ db, err := sql.Open("mysql", MySQLUSER+":"+MySQLPASS+"@tcp(127.0.0.1:3306)/zicloud")
|
|
|
+ if err != nil {
|
|
|
+ resp := _response{
|
|
|
+ Origin: "ovirt-Editvm",
|
|
|
+ Message: "Error on connecting db for save add vm result",
|
|
|
+ Code: 1001,
|
|
|
+ }
|
|
|
+ b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
+ return c.String(http.StatusBadRequest, string(b))
|
|
|
+ }
|
|
|
+ defer db.Close()
|
|
|
+ insert, err := db.Query("INSERT INTO service_profile VALUES ( '" + invoiceUUID + "'," +
|
|
|
+ "'" + claims["IPAUid"].(string) + "'," +
|
|
|
+ "'" + "VM" + "'," +
|
|
|
+ "'" + "" + "'," +
|
|
|
+ "'" + login(BA).AuthenticatedUser.ID + "'," +
|
|
|
+ "NOW()" + "," +
|
|
|
+ "NOW() ," +
|
|
|
+ "-1" + "," +
|
|
|
+ "'" + vmname + "'," +
|
|
|
+ "'" + string(jsonDetail) + "'," +
|
|
|
+ "'" + invoiceUUID + "' )")
|
|
|
+ defer insert.Close()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error in EditVM: ", err.Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // Start Task
|
|
|
+ {
|
|
|
+
|
|
|
+ url := OvirtURL + "/ovirt-engine/api/vms/" + invoiceUUID + "/start"
|
|
|
+ method := "POST"
|
|
|
+ nicAddress := "172.20.15.251"
|
|
|
+ nicMask := "255.255.255.0"
|
|
|
+ nicGW := "172.20.15.1"
|
|
|
+ __json := fmt.Sprintf(`
|
|
|
+ {
|
|
|
+ "async":"true",
|
|
|
+ "use_cloud_init": "true",
|
|
|
+ "vm": {
|
|
|
+ "initialization": {
|
|
|
+ "authorized_ssh_keys": "%s",
|
|
|
+ "host_name": "Sassan.local",
|
|
|
+ "user_name": "root",
|
|
|
+ "root_password": "%s",
|
|
|
+ "nic_configurations": {
|
|
|
+ "nic_configuration": [
|
|
|
+ {
|
|
|
+ "name": "eth0",
|
|
|
+ "on_boot": "true",
|
|
|
+ "boot_protocol": "static",
|
|
|
+ "ip": {
|
|
|
+ "address": "%s",
|
|
|
+ "netmask": "%s",
|
|
|
+ "gateway": "%s"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ "dns_servers": "172.20.11.11"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ `, sshKey, rootpass, nicAddress, nicMask, nicGW)
|
|
|
+ sha256 := sha256.Sum256([]byte(invoiceUUID))
|
|
|
+ var hashChannel = make(chan []byte, 1)
|
|
|
+ hashChannel <- sha256[:]
|
|
|
+ ___json := encrypt(<-hashChannel, __json)
|
|
|
+ startVM := addVMTask{
|
|
|
+ URL: url,
|
|
|
+ JSON: ___json,
|
|
|
+ Method: method,
|
|
|
+ Headers: nil,
|
|
|
+ }
|
|
|
+ startVM.Headers = append(startVM.Headers, TaskHeader{Name: "Version", Value: "4"})
|
|
|
+ startVM.Headers = append(startVM.Headers, TaskHeader{Name: "Accept", Value: "application/json"})
|
|
|
+ startVM.Headers = append(startVM.Headers, TaskHeader{Name: "Content-Type", Value: "application/json"})
|
|
|
+ startVM.Headers = append(startVM.Headers, TaskHeader{Name: "Authorization", Value: BA})
|
|
|
+
|
|
|
+ uuid, _ := uuidgen("APIGW-Ovirt-CloudInit")
|
|
|
+ __startVM, _ := json.MarshalIndent(startVM, "", " ")
|
|
|
+ //fmt.Println("StartVMHeaders: ", string(__startVMHeaders))
|
|
|
+ addTask(uuid, string(__startVM), "", "APIGW", "VM Initialization", invoiceUUID, "1", "0")
|
|
|
+
|
|
|
+ }
|
|
|
+ //resp := _response{
|
|
|
+ // Origin: "ovirt-addvm",
|
|
|
+ // Message: resposeInvoice
|
|
|
+ // Code: 1000,
|
|
|
+ //}
|
|
|
+ return c.JSON(http.StatusOK, responseInvoiece)
|
|
|
+ */
|
|
|
}
|
|
|
+
|
|
|
+//func (o ovirt) EditVM(c echo.Context) error {
|
|
|
+// resp := _response{
|
|
|
+// Origin: "ovirt-EditVM",
|
|
|
+// Message: "Done",
|
|
|
+// Code: 1000,
|
|
|
+// }
|
|
|
+// //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 {
|
|
|
resp := _response{
|
|
|
Origin: "ovirt-ResetPassword",
|
|
@@ -1580,10 +1963,32 @@ func vmStatistics(BA string, VMUUID string) (string, float64, float64, error) {
|
|
|
res, err := client.Do(req)
|
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
|
defer res.Body.Close()
|
|
|
- diskattachments := DiskAttachments{}
|
|
|
+ diskattachments := DiskAttachments{
|
|
|
+ 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\""
|
|
|
+ }{},
|
|
|
+ }
|
|
|
_err := json.Unmarshal(body, &diskattachments)
|
|
|
if _err != nil {
|
|
|
fmt.Println("Error in vmStatistics 1: ", _err)
|
|
|
+ fmt.Println("Error: ", string(body))
|
|
|
+ return "", -1, -1, errors.New("unexpected Error")
|
|
|
}
|
|
|
for _, v := range diskattachments.DiskAttachment {
|
|
|
url := OvirtURL + "/ovirt-engine/api/disks/" + v.Disk.ID
|
|
@@ -1653,6 +2058,8 @@ func vmStatistics(BA string, VMUUID string) (string, float64, float64, error) {
|
|
|
_err := json.Unmarshal(body, &disk)
|
|
|
if _err != nil {
|
|
|
fmt.Println("Error in vmStatistics 2 : ", _err)
|
|
|
+ fmt.Println("Error: ", string(body))
|
|
|
+
|
|
|
}
|
|
|
defer res.Body.Close()
|
|
|
_disk = append(_disk, disk.ProvisionedSize)
|
|
@@ -1677,7 +2084,7 @@ func vmStatistics(BA string, VMUUID string) (string, float64, float64, error) {
|
|
|
|
|
|
res, err := client.Do(req)
|
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
|
- fmt.Println("Code: ", res.StatusCode)
|
|
|
+ // fmt.Println("Code: ", res.StatusCode, " VMUUID:", VMUUID)
|
|
|
if err != nil || res.StatusCode == 404 {
|
|
|
return "", -1, -1, errors.New("unexpected Error")
|
|
|
}
|
|
@@ -1687,6 +2094,9 @@ func vmStatistics(BA string, VMUUID string) (string, float64, float64, error) {
|
|
|
_err := json.Unmarshal(body, &_vmstatistics)
|
|
|
if _err != nil {
|
|
|
fmt.Println("Error in vmStatistics 3: ", _err)
|
|
|
+ fmt.Println("Error: ", string(body))
|
|
|
+
|
|
|
+ return "", -1, -1, errors.New("unexpected Error")
|
|
|
}
|
|
|
cpuUUID := _vmstatistics.Statistic[4].ID
|
|
|
memUsedUUID := _vmstatistics.Statistic[1].ID
|
|
@@ -1727,12 +2137,14 @@ func vmStatistics(BA string, VMUUID string) (string, float64, float64, error) {
|
|
|
req.Header.Add("Authorization", BA)
|
|
|
|
|
|
res, err := client.Do(req)
|
|
|
- defer res.Body.Close()
|
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
|
+ defer res.Body.Close()
|
|
|
cpuUsage := ItemUsage{}
|
|
|
_err := json.Unmarshal(body, &cpuUsage)
|
|
|
if _err != nil {
|
|
|
fmt.Println("Error in vmStatistics 4 ", _err)
|
|
|
+ fmt.Println("Error: ", string(body))
|
|
|
+
|
|
|
}
|
|
|
cpu = fmt.Sprintf("%f", cpuUsage.Values.Value[0].Datum)
|
|
|
}
|
|
@@ -1752,12 +2164,14 @@ func vmStatistics(BA string, VMUUID string) (string, float64, float64, error) {
|
|
|
req.Header.Add("Authorization", BA)
|
|
|
|
|
|
res, err := client.Do(req)
|
|
|
- defer res.Body.Close()
|
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
|
+ defer res.Body.Close()
|
|
|
memUsage := ItemUsage{}
|
|
|
_err := json.Unmarshal(body, &memUsage)
|
|
|
if _err != nil {
|
|
|
fmt.Println("Error in vmStatistics 5: ", _err)
|
|
|
+ fmt.Println("Error: ", string(body))
|
|
|
+
|
|
|
}
|
|
|
memUsed = fmt.Sprintf("%f", memUsage.Values.Value[0].Datum)
|
|
|
}
|
|
@@ -1777,12 +2191,16 @@ func vmStatistics(BA string, VMUUID string) (string, float64, float64, error) {
|
|
|
req.Header.Add("Authorization", BA)
|
|
|
|
|
|
res, err := client.Do(req)
|
|
|
- defer res.Body.Close()
|
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
|
+ defer res.Body.Close()
|
|
|
memUsage := ItemUsage{}
|
|
|
_err := json.Unmarshal(body, &memUsage)
|
|
|
if _err != nil {
|
|
|
fmt.Println("Error in vmStatistics 6: ", _err)
|
|
|
+ fmt.Println("Error: ", string(body))
|
|
|
+
|
|
|
+ return "", -1, -1, errors.New("unexpected Error")
|
|
|
+
|
|
|
}
|
|
|
memTotal = fmt.Sprintf("%f", memUsage.Values.Value[0].Datum)
|
|
|
}
|
|
@@ -2037,6 +2455,7 @@ func (o ovirt) vmDetails(c echo.Context) error {
|
|
|
NIC string `json:"NIC"`
|
|
|
Traffic string `json:"Traffic"`
|
|
|
Status string `json:"Status"`
|
|
|
+ Period string `json:"Period"`
|
|
|
Name string `json:"Name"`
|
|
|
Template string `json:"Template"`
|
|
|
} `json:"message"`
|
|
@@ -2051,6 +2470,7 @@ func (o ovirt) vmDetails(c echo.Context) error {
|
|
|
NIC string `json:"NIC"`
|
|
|
Traffic string `json:"Traffic"`
|
|
|
Status string `json:"Status"`
|
|
|
+ Period string `json:"Period"`
|
|
|
Name string `json:"Name"`
|
|
|
Template string `json:"Template"`
|
|
|
}{
|
|
@@ -2060,6 +2480,7 @@ func (o ovirt) vmDetails(c echo.Context) error {
|
|
|
NIC: fmt.Sprintf("%d", nic),
|
|
|
Traffic: vmJsonDetails[5].Value,
|
|
|
Status: _vmstatus.Status,
|
|
|
+ Period: "3",
|
|
|
// v.Name[len(login(BA).AuthenticatedUser.ID)+3:]
|
|
|
Name: _vmstatus.Name[len(login(BA).AuthenticatedUser.ID)+3:],
|
|
|
Template: vmJsonDetails[7].Value,
|
|
@@ -2454,7 +2875,23 @@ func (o ovirt) VNC(c echo.Context) error {
|
|
|
res, err := client.Do(req)
|
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
|
defer res.Body.Close()
|
|
|
- _graphicConsoleList := graphicConsoleList{}
|
|
|
+ _graphicConsoleList := graphicConsoleList{
|
|
|
+ GraphicsConsole: []struct {
|
|
|
+ Protocol string "json:\"protocol\""
|
|
|
+ VM struct {
|
|
|
+ Href string "json:\"href\""
|
|
|
+ ID string "json:\"id\""
|
|
|
+ } "json:\"vm\""
|
|
|
+ Actions struct {
|
|
|
+ Link []struct {
|
|
|
+ Href string "json:\"href\""
|
|
|
+ Rel string "json:\"rel\""
|
|
|
+ } "json:\"link\""
|
|
|
+ } "json:\"actions\""
|
|
|
+ Href string "json:\"href\""
|
|
|
+ ID string "json:\"id\""
|
|
|
+ }{},
|
|
|
+ }
|
|
|
err = json.Unmarshal(body, &_graphicConsoleList)
|
|
|
urlvncfile := OvirtURL + "/ovirt-engine/api/vms/" + vmuuid + "/graphicsconsoles/" + _graphicConsoleList.GraphicsConsole[0].ID + "/remoteviewerconnectionfile"
|
|
|
client2 := &http.Client{}
|
|
@@ -2493,7 +2930,7 @@ func (o ovirt) VNC(c echo.Context) error {
|
|
|
|
|
|
resp := _response{
|
|
|
Origin: "ovirt-VNC",
|
|
|
- Message: "http://zi-cloud.ir:" + fmt.Sprintf("%d", lport) + "/vnc.html?autoconnect=true&password=" + strings.Split(password, "=")[1],
|
|
|
+ Message: "https://vnc.zi-cloud.ir:" + fmt.Sprintf("%d", lport) + "/vnc.html?autoconnect=true&show_dot=true&password=" + strings.Split(password, "=")[1],
|
|
|
Code: 1000,
|
|
|
}
|
|
|
return c.JSON(http.StatusOK, resp)
|
|
@@ -2742,8 +3179,8 @@ func (o ovirt) vmHistory(c echo.Context) error {
|
|
|
req.Header.Add("Authorization", BA)
|
|
|
|
|
|
res, err := client.Do(req)
|
|
|
- defer res.Body.Close()
|
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
|
+ defer res.Body.Close()
|
|
|
_VMStatistics := VMStatistics{}
|
|
|
err = json.Unmarshal(body, &_VMStatistics)
|
|
|
_VMStatisticsResponse := VMStatisticsResponse{
|