|
@@ -315,6 +315,21 @@ func (o ovirt) vmStatus(uuid string) string {
|
|
|
return _vmstatus.Status
|
|
|
}
|
|
|
func (o ovirt) addvm(c echo.Context) error {
|
|
|
+ type AddVMPayment struct {
|
|
|
+ Data struct {
|
|
|
+ Price struct {
|
|
|
+ CPU string `json:"cpu"`
|
|
|
+ Mem string `json:"mem"`
|
|
|
+ Disk string `json:"disk"`
|
|
|
+ Nic string `json:"nic"`
|
|
|
+ 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))))
|
|
@@ -323,12 +338,15 @@ func (o ovirt) addvm(c echo.Context) error {
|
|
|
token := decrypt(<-hashChannel_, claims["IPAToken"].(string))
|
|
|
_BA := strings.Split(token, ";")
|
|
|
BA := _BA[len(_BA)-2]
|
|
|
- var vmname, vmdescr, vmcomment, templatename, cpuSock, cpuCore, cpuThread, mem string
|
|
|
+ var vmname, vmdescr, vmcomment, templatename, cpuSock, cpuCore, cpuThread, mem, Disk, nic, period string
|
|
|
vmname = 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")
|
|
|
sshKey := c.FormValue("sshKey")
|
|
|
rootpass := c.FormValue("rootpass")
|
|
|
cpuCore = "1"
|
|
@@ -489,6 +507,36 @@ func (o ovirt) addvm(c echo.Context) error {
|
|
|
})
|
|
|
uuid, _ := uuidgen("APIGW-Ovirt-addVMTask")
|
|
|
invoiceUUID, _ := uuidgen("APIGW-FakeInvoice")
|
|
|
+ responseInvoiece:=AddVMPayment{
|
|
|
+ Data: struct {
|
|
|
+ Price struct {
|
|
|
+ CPU string `json:"cpu"`
|
|
|
+ Mem string `json:"mem"`
|
|
|
+ Disk string `json:"disk"`
|
|
|
+ Nic string `json:"nic"`
|
|
|
+ Period string `json:"period"`
|
|
|
+ } `json:"price"`
|
|
|
+ InvoiceUUID string `json:"invoiceUUID"`
|
|
|
+ }{
|
|
|
+ Price: struct {
|
|
|
+ CPU string `json:"cpu"`
|
|
|
+ Mem string `json:"mem"`
|
|
|
+ Disk string `json:"disk"`
|
|
|
+ Nic string `json:"nic"`
|
|
|
+ Period string `json:"period"`
|
|
|
+ }{
|
|
|
+ CPU: cpuThread,
|
|
|
+ Mem: mem,
|
|
|
+ Disk: Disk,
|
|
|
+ Nic: nic,
|
|
|
+ Period: period,
|
|
|
+ },
|
|
|
+ InvoiceUUID: invoiceUUID,
|
|
|
+ },
|
|
|
+ Message: "Done",
|
|
|
+ Origin: "AddVM",
|
|
|
+ Code: 1000,
|
|
|
+ }
|
|
|
__createVM, _ := json.MarshalIndent(newvm, "", " ")
|
|
|
// Add VM Task
|
|
|
addTask(uuid, string(__createVM), "", "APIGW", "VM Creation for "+claims["name"].(string), invoiceUUID, "0", "0")
|
|
@@ -579,12 +627,12 @@ func (o ovirt) addvm(c echo.Context) error {
|
|
|
//fmt.Println("StartVMHeaders: ", string(__startVMHeaders))
|
|
|
addTask(uuid, string(__startVM), "", "APIGW", "VM Initialization", invoiceUUID, "1", "0")
|
|
|
}
|
|
|
- resp := _response{
|
|
|
- Origin: "ovirt-addvm",
|
|
|
- Message: invoiceUUID,
|
|
|
- Code: 1000,
|
|
|
- }
|
|
|
- return c.JSON(http.StatusOK, resp)
|
|
|
+ //resp := _response{
|
|
|
+ // Origin: "ovirt-addvm",
|
|
|
+ // Message: resposeInvoice
|
|
|
+ // Code: 1000,
|
|
|
+ //}
|
|
|
+ return c.JSON(http.StatusOK, responseInvoiece)
|
|
|
}
|
|
|
func (o ovirt) listVM(c echo.Context) error {
|
|
|
user := c.Get("user").(*jwt.Token)
|
|
@@ -712,7 +760,7 @@ func (o ovirt) StopVM(c echo.Context) error {
|
|
|
addTask(uuid, string(__startVM), "", "APIGW", "VM Start", vmuuid, "1", "1")
|
|
|
|
|
|
resp := _response{
|
|
|
- Origin: "ovirt-StartVM",
|
|
|
+ Origin: "ovirt-StopVM",
|
|
|
Message: "Done",
|
|
|
Code: 1000,
|
|
|
}
|
|
@@ -762,7 +810,7 @@ func (o ovirt) RebootVM(c echo.Context) error {
|
|
|
addTask(uuid, string(__startVM), "", "APIGW", "VM Start", vmuuid, "1", "1")
|
|
|
|
|
|
resp := _response{
|
|
|
- Origin: "ovirt-StartVM",
|
|
|
+ Origin: "ovirt-RebootVM",
|
|
|
Message: "Done",
|
|
|
Code: 1000,
|
|
|
}
|
|
@@ -811,7 +859,7 @@ func (o ovirt) PowerOffVM(c echo.Context) error {
|
|
|
addTask(uuid, string(__startVM), "", "APIGW", "VM Start", vmuuid, "1", "1")
|
|
|
|
|
|
resp := _response{
|
|
|
- Origin: "ovirt-StartVM",
|
|
|
+ Origin: "ovirt-PowerOffVM",
|
|
|
Message: "Done",
|
|
|
Code: 1000,
|
|
|
}
|
|
@@ -1033,7 +1081,7 @@ func createVM(invoice_uuid string, apiJson string, uuid string) {
|
|
|
method := _createVM.Method
|
|
|
__json := _createVM.JSON
|
|
|
client := &http.Client{}
|
|
|
- _json, _ :=json.Marshal(__json)
|
|
|
+ _json, _ := json.Marshal(__json)
|
|
|
payload := strings.NewReader(string(_json))
|
|
|
//payload := __json
|
|
|
req, err := http.NewRequest(method, url, payload)
|
|
@@ -1089,7 +1137,7 @@ func createVM(invoice_uuid string, apiJson string, uuid string) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-func VMInitialization (relatedUuid string, apiCall string, uuid string) {
|
|
|
+func VMInitialization(relatedUuid string, apiCall string, uuid string) {
|
|
|
iaas := &ovirt{}
|
|
|
status := iaas.vmStatus(relatedUuid)
|
|
|
//fmt.Println("VM :", relatedUuid, " is now: ", status)
|
|
@@ -1598,7 +1646,7 @@ func (o ovirt) vmDetails(c echo.Context) error {
|
|
|
//return _vmstatus.Status, _vmstatus.Name, disk, cpu, ram
|
|
|
}
|
|
|
func (o ovirt) ovirtPayment(c echo.Context) error {
|
|
|
- invoiceUuid :=c.FormValue("invoiceUuid")
|
|
|
+ invoiceUuid := c.FormValue("invoiceUuid")
|
|
|
db, err := sql.Open("mysql", MySQLUSER+":"+MySQLPASS+"@tcp(127.0.0.1:3306)/zicloud")
|
|
|
if err != nil {
|
|
|
}
|
|
@@ -1615,4 +1663,4 @@ func (o ovirt) ovirtPayment(c echo.Context) error {
|
|
|
//b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
//return c.String(http.StatusOK, string(b))
|
|
|
return c.JSON(http.StatusOK, resp)
|
|
|
-}
|
|
|
+}
|