|
@@ -4,6 +4,7 @@ import (
|
|
|
"crypto/sha256"
|
|
|
"database/sql"
|
|
|
"encoding/json"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"github.com/dgrijalva/jwt-go"
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
@@ -318,11 +319,13 @@ 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"`
|
|
|
+ CPU float64 `json:"cpu"`
|
|
|
+ Mem float64 `json:"mem"`
|
|
|
+ Disk float64 `json:"disk"`
|
|
|
+ Nic float64 `json:"nic"`
|
|
|
+ BW float64 `json:"bw"`
|
|
|
+ SUM float64 `json:"sum"`
|
|
|
+ Period string `json:"period"`
|
|
|
} `json:"price"`
|
|
|
InvoiceUUID string `json:"invoiceUUID"`
|
|
|
} `json:"data"`
|
|
@@ -338,8 +341,8 @@ 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, Disk, nic, period string
|
|
|
- vmname = c.FormValue("VmName")
|
|
|
+ var vmname, vmdescr, vmcomment, templatename, cpuSock, cpuCore, cpuThread, mem, Disk, nic, period, extraBW string
|
|
|
+ vmname = login(BA).AuthenticatedUser.ID + "_" + c.FormValue("VmName")
|
|
|
vmdescr = c.FormValue("VmDescr")
|
|
|
vmcomment = c.FormValue("VmComment")
|
|
|
templatename = c.FormValue("VmTempl")
|
|
@@ -347,6 +350,7 @@ func (o ovirt) addvm(c echo.Context) error {
|
|
|
Disk = c.FormValue("VmDisk")
|
|
|
period = c.FormValue("VmPeriod")
|
|
|
nic = c.FormValue("VmNIC")
|
|
|
+ extraBW = c.FormValue("extraBW")
|
|
|
sshKey := c.FormValue("sshKey")
|
|
|
rootpass := c.FormValue("rootpass")
|
|
|
cpuCore = "1"
|
|
@@ -506,29 +510,36 @@ func (o ovirt) addvm(c echo.Context) error {
|
|
|
Value: "application/json",
|
|
|
})
|
|
|
uuid, _ := uuidgen("APIGW-Ovirt-addVMTask")
|
|
|
- invoiceUUID, _ := uuidgen("APIGW-FakeInvoice")
|
|
|
+ //invoiceUUID, _ := uuidgen("APIGW-FakeInvoice")
|
|
|
+ CPUPrice, memPrice, StoragePrice, IPPrice, extraBWPrice, SUM, invoiceUUID := IaaSCreate(login(BA).AuthenticatedUser.ID, period, cpuThread, mem, Disk, nic, extraBW)
|
|
|
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"`
|
|
|
+ CPU float64 `json:"cpu"`
|
|
|
+ Mem float64 `json:"mem"`
|
|
|
+ Disk float64 `json:"disk"`
|
|
|
+ Nic float64 `json:"nic"`
|
|
|
+ BW float64 `json:"bw"`
|
|
|
+ SUM float64 `json:"sum"`
|
|
|
+ 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 float64 `json:"cpu"`
|
|
|
+ Mem float64 `json:"mem"`
|
|
|
+ Disk float64 `json:"disk"`
|
|
|
+ Nic float64 `json:"nic"`
|
|
|
+ BW float64 `json:"bw"`
|
|
|
+ SUM float64 `json:"sum"`
|
|
|
+ Period string `json:"period"`
|
|
|
}{
|
|
|
- CPU: cpuThread,
|
|
|
- Mem: mem,
|
|
|
- Disk: Disk,
|
|
|
- Nic: nic,
|
|
|
+ CPU: CPUPrice,
|
|
|
+ Mem: memPrice,
|
|
|
+ Disk: StoragePrice,
|
|
|
+ Nic: IPPrice,
|
|
|
+ BW: extraBWPrice,
|
|
|
+ SUM: SUM,
|
|
|
Period: period,
|
|
|
},
|
|
|
InvoiceUUID: invoiceUUID,
|
|
@@ -537,6 +548,16 @@ func (o ovirt) addvm(c echo.Context) error {
|
|
|
Origin: "AddVM",
|
|
|
Code: 1000,
|
|
|
}
|
|
|
+ if len(invoiceUUID) < 5 {
|
|
|
+ resp := _response{
|
|
|
+ Origin: "ovirt-addvm",
|
|
|
+ Message: "Error on Invoice Calculation",
|
|
|
+ Code: 1001,
|
|
|
+ }
|
|
|
+ b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
+ return c.String(http.StatusBadRequest, string(b))
|
|
|
+ }
|
|
|
+ //fmt.Println("Invoice: ",invoiceUUID)
|
|
|
__createVM, _ := json.MarshalIndent(newvm, "", " ")
|
|
|
// Add VM Task
|
|
|
addTask(uuid, string(__createVM), "", "APIGW", "VM Creation for "+claims["name"].(string), invoiceUUID, "0", "0")
|
|
@@ -560,7 +581,7 @@ func (o ovirt) addvm(c echo.Context) error {
|
|
|
"'" + login(BA).AuthenticatedUser.ID + "'," +
|
|
|
"NOW()" + "," +
|
|
|
"NOW() ," +
|
|
|
- "false" + "," +
|
|
|
+ "-1" + "," +
|
|
|
"'" + vmname + "'," +
|
|
|
"'" + invoiceUUID + "' )")
|
|
|
defer insert.Close()
|
|
@@ -635,6 +656,212 @@ func (o ovirt) addvm(c echo.Context) error {
|
|
|
return c.JSON(http.StatusOK, responseInvoiece)
|
|
|
}
|
|
|
func (o ovirt) listVM(c echo.Context) error {
|
|
|
+ type listVMs struct {
|
|
|
+ VM []struct {
|
|
|
+ Fqdn string `json:"fqdn,omitempty"`
|
|
|
+ GuestOperatingSystem struct {
|
|
|
+ Architecture string `json:"architecture"`
|
|
|
+ Codename string `json:"codename"`
|
|
|
+ Distribution string `json:"distribution"`
|
|
|
+ Family string `json:"family"`
|
|
|
+ Kernel struct {
|
|
|
+ Version struct {
|
|
|
+ Build string `json:"build"`
|
|
|
+ FullVersion string `json:"full_version"`
|
|
|
+ Major string `json:"major"`
|
|
|
+ Minor string `json:"minor"`
|
|
|
+ Revision string `json:"revision"`
|
|
|
+ } `json:"version"`
|
|
|
+ } `json:"kernel"`
|
|
|
+ Version struct {
|
|
|
+ FullVersion string `json:"full_version"`
|
|
|
+ Major string `json:"major"`
|
|
|
+ } `json:"version"`
|
|
|
+ } `json:"guest_operating_system,omitempty"`
|
|
|
+ GuestTimeZone struct {
|
|
|
+ Name string `json:"name"`
|
|
|
+ UtcOffset string `json:"utc_offset"`
|
|
|
+ } `json:"guest_time_zone,omitempty"`
|
|
|
+ NextRunConfigurationExists string `json:"next_run_configuration_exists"`
|
|
|
+ NumaTuneMode string `json:"numa_tune_mode"`
|
|
|
+ RunOnce string `json:"run_once,omitempty"`
|
|
|
+ StartTime int64 `json:"start_time,omitempty"`
|
|
|
+ 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 {
|
|
|
+ Address string `json:"address"`
|
|
|
+ AllowOverride string `json:"allow_override"`
|
|
|
+ Certificate struct {
|
|
|
+ Content string `json:"content"`
|
|
|
+ Organization string `json:"organization"`
|
|
|
+ Subject string `json:"subject"`
|
|
|
+ } `json:"certificate"`
|
|
|
+ CopyPasteEnabled string `json:"copy_paste_enabled"`
|
|
|
+ DisconnectAction string `json:"disconnect_action"`
|
|
|
+ FileTransferEnabled string `json:"file_transfer_enabled"`
|
|
|
+ Monitors string `json:"monitors"`
|
|
|
+ Port string `json:"port"`
|
|
|
+ SecurePort string `json:"secure_port"`
|
|
|
+ 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 {
|
|
|
+ Guaranteed string `json:"guaranteed"`
|
|
|
+ Max string `json:"max"`
|
|
|
+ } `json:"memory_policy"`
|
|
|
+ MigrationDowntime string `json:"migration_downtime"`
|
|
|
+ MultiQueuesEnabled string `json:"multi_queues_enabled"`
|
|
|
+ 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"`
|
|
|
+ StopReason string `json:"stop_reason,omitempty"`
|
|
|
+ } `json:"vm"`
|
|
|
+ }
|
|
|
+ type listVMResponse struct {
|
|
|
+ Data []struct {
|
|
|
+ Fqdn string `json:"fqdn"`
|
|
|
+ StartTime int64 `json:"start_time"`
|
|
|
+ Status string `json:"status"`
|
|
|
+ Name string `json:"name"`
|
|
|
+ Description string `json:"description"`
|
|
|
+ Comment string `json:"comment"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ CPU struct {
|
|
|
+ Topology struct {
|
|
|
+ Cores string `json:"cores"`
|
|
|
+ Sockets string `json:"sockets"`
|
|
|
+ Threads string `json:"threads"`
|
|
|
+ } `json:"topology"`
|
|
|
+ } `json:"cpu"`
|
|
|
+ Memory string `json:"memory"`
|
|
|
+ CreationTime int64 `json:"creation_time"`
|
|
|
+ Disk []struct {
|
|
|
+ Name string `json:"Name"`
|
|
|
+ TotalSize string `json:"TotalSize"`
|
|
|
+ ActualSize string `json:"ActualSize"`
|
|
|
+ } `json:"Disk"`
|
|
|
+ NIC []struct {
|
|
|
+ Mac string `json:"mac"`
|
|
|
+ IPv4 string `json:"IPv4"`
|
|
|
+ IPv6 string `json:"IPv6"`
|
|
|
+ ReportedDevices struct {
|
|
|
+ Mac string `json:"mac"`
|
|
|
+ IPv4 string `json:"IPv4"`
|
|
|
+ IPv6 string `json:"IPv6"`
|
|
|
+ } `json:"reported_devices"`
|
|
|
+ } `json:"NIC"`
|
|
|
+ } `json:"vm"`
|
|
|
+ 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))))
|
|
@@ -659,13 +886,80 @@ func (o ovirt) listVM(c echo.Context) error {
|
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
|
//fmt.Printf("%s",body)
|
|
|
//b, _ := json.MarshalIndent(body, "", " ")
|
|
|
- resp := _response{
|
|
|
- Origin: "ovirt-listvms",
|
|
|
- Message: string(body),
|
|
|
+ _VMLists := listVMs{}
|
|
|
+ err = json.Unmarshal(body, &_VMLists)
|
|
|
+ _listVMResponse := listVMResponse{
|
|
|
+ Data: nil,
|
|
|
+ Message: "Done",
|
|
|
+ Origin: "ListVMs",
|
|
|
Code: 1000,
|
|
|
}
|
|
|
+ _Data := _listVMResponse.Data
|
|
|
+ y := struct {
|
|
|
+ Fqdn string `json:"fqdn"`
|
|
|
+ StartTime int64 `json:"start_time"`
|
|
|
+ Status string `json:"status"`
|
|
|
+ Name string `json:"name"`
|
|
|
+ Description string `json:"description"`
|
|
|
+ Comment string `json:"comment"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ CPU struct {
|
|
|
+ Topology struct {
|
|
|
+ Cores string `json:"cores"`
|
|
|
+ Sockets string `json:"sockets"`
|
|
|
+ Threads string `json:"threads"`
|
|
|
+ } `json:"topology"`
|
|
|
+ } `json:"cpu"`
|
|
|
+ Memory string `json:"memory"`
|
|
|
+ CreationTime int64 `json:"creation_time"`
|
|
|
+ Disk []struct {
|
|
|
+ Name string `json:"Name"`
|
|
|
+ TotalSize string `json:"TotalSize"`
|
|
|
+ ActualSize string `json:"ActualSize"`
|
|
|
+ } `json:"Disk"`
|
|
|
+ NIC []struct {
|
|
|
+ Mac string `json:"mac"`
|
|
|
+ IPv4 string `json:"IPv4"`
|
|
|
+ IPv6 string `json:"IPv6"`
|
|
|
+ ReportedDevices struct {
|
|
|
+ Mac string `json:"mac"`
|
|
|
+ IPv4 string `json:"IPv4"`
|
|
|
+ IPv6 string `json:"IPv6"`
|
|
|
+ } `json:"reported_devices"`
|
|
|
+ } `json:"NIC"`
|
|
|
+ }{}
|
|
|
+ for _, v := range _VMLists.VM {
|
|
|
+ y.ID = v.ID
|
|
|
+ y.Fqdn = v.Fqdn
|
|
|
+ y.StartTime = v.StartTime
|
|
|
+ y.Status = v.Status
|
|
|
+ y.Name = v.Name
|
|
|
+ y.Description = v.Description
|
|
|
+ y.Comment = v.Comment
|
|
|
+ y.CPU.Topology.Cores = v.CPU.Topology.Cores
|
|
|
+ y.CPU.Topology.Sockets = v.CPU.Topology.Sockets
|
|
|
+ y.CPU.Topology.Threads = v.CPU.Topology.Threads
|
|
|
+ y.Memory = v.Memory
|
|
|
+ y.CreationTime = v.CreationTime
|
|
|
+ y.NIC = listNIC(v.ID)
|
|
|
+ y.Disk = listDisks(v.ID)
|
|
|
+
|
|
|
+ _Data = append(_Data, y)
|
|
|
+ }
|
|
|
+ _listVMResponse.Data = _Data
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ //return CPUPrice, memPrice, StoragePrice, IPPrice, extraBWPrice
|
|
|
+ resp := _response{
|
|
|
+ Origin: "ovirt-listvms",
|
|
|
+ Message: "Error in Parsing listVMs",
|
|
|
+ Code: 1001,
|
|
|
+ }
|
|
|
+ return c.JSON(http.StatusInternalServerError, resp)
|
|
|
+ }
|
|
|
+ //fmt.Printf("%s", body)
|
|
|
//b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
- return c.JSON(http.StatusOK, resp)
|
|
|
+ return c.JSON(http.StatusOK, _listVMResponse)
|
|
|
//return c.String(http.StatusOK, string(b))
|
|
|
}
|
|
|
func (o ovirt) StartVM(c echo.Context) error {
|
|
@@ -1155,7 +1449,7 @@ func VMInitialization(relatedUuid string, apiCall string, uuid string) {
|
|
|
toggleTask(uuid, 0)
|
|
|
}
|
|
|
}
|
|
|
-func vmStatistics(BA string, VMUUID string) (string, float64, float64) {
|
|
|
+func vmStatistics(BA string, VMUUID string) (string, float64, float64, error) {
|
|
|
//ram,cpu,storage
|
|
|
var _disk []string
|
|
|
{
|
|
@@ -1189,7 +1483,7 @@ func vmStatistics(BA string, VMUUID string) (string, float64, float64) {
|
|
|
req, err := http.NewRequest(method, url, nil)
|
|
|
|
|
|
if err != nil {
|
|
|
- return "", -1, -1
|
|
|
+ return "", -1, -1, errors.New("unexpected Error")
|
|
|
}
|
|
|
req.Header.Add("Version", "4")
|
|
|
req.Header.Add("Accept", "application/json")
|
|
@@ -1287,7 +1581,7 @@ func vmStatistics(BA string, VMUUID string) (string, float64, float64) {
|
|
|
req, err := http.NewRequest(method, url, nil)
|
|
|
|
|
|
if err != nil {
|
|
|
- return "", -1, -1
|
|
|
+ return "", -1, -1, errors.New("unexpected Error")
|
|
|
}
|
|
|
req.Header.Add("Version", "4")
|
|
|
req.Header.Add("Accept", "application/json")
|
|
@@ -1296,8 +1590,11 @@ func vmStatistics(BA string, VMUUID string) (string, float64, float64) {
|
|
|
res, err := client.Do(req)
|
|
|
defer res.Body.Close()
|
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
|
-
|
|
|
- //fmt.Println("full response: ",string(body))
|
|
|
+ fmt.Println("Code: ", res.StatusCode)
|
|
|
+ if err != nil || res.StatusCode == 404 {
|
|
|
+ return "", -1, -1, errors.New("unexpected Error")
|
|
|
+ }
|
|
|
+ //fmt.Println("full response: ", string(body))
|
|
|
_vmstatistics := VMStatistics{}
|
|
|
_err := json.Unmarshal(body, &_vmstatistics)
|
|
|
if _err != nil {
|
|
@@ -1335,7 +1632,7 @@ func vmStatistics(BA string, VMUUID string) (string, float64, float64) {
|
|
|
req, err := http.NewRequest(method, url, nil)
|
|
|
|
|
|
if err != nil {
|
|
|
- return "", -1, -1
|
|
|
+ return "", -1, -1, errors.New("unexpected Error")
|
|
|
}
|
|
|
req.Header.Add("Version", "4")
|
|
|
req.Header.Add("Accept", "application/json")
|
|
@@ -1360,7 +1657,7 @@ func vmStatistics(BA string, VMUUID string) (string, float64, float64) {
|
|
|
req, err := http.NewRequest(method, url, nil)
|
|
|
|
|
|
if err != nil {
|
|
|
- return "", -1, -1
|
|
|
+ return "", -1, -1, errors.New("unexpected Error")
|
|
|
}
|
|
|
req.Header.Add("Version", "4")
|
|
|
req.Header.Add("Accept", "application/json")
|
|
@@ -1385,7 +1682,7 @@ func vmStatistics(BA string, VMUUID string) (string, float64, float64) {
|
|
|
req, err := http.NewRequest(method, url, nil)
|
|
|
|
|
|
if err != nil {
|
|
|
- return "", -1, -1
|
|
|
+ return "", -1, -1, errors.New("unexpected Error")
|
|
|
}
|
|
|
req.Header.Add("Version", "4")
|
|
|
req.Header.Add("Accept", "application/json")
|
|
@@ -1409,7 +1706,7 @@ func vmStatistics(BA string, VMUUID string) (string, float64, float64) {
|
|
|
mem := _memusage / _memtotal
|
|
|
|
|
|
_cpu, _ := strconv.ParseFloat(cpu, 64)
|
|
|
- return strings.Join(_disk, ", "), _cpu, mem
|
|
|
+ return strings.Join(_disk, ", "), _cpu, mem, nil
|
|
|
|
|
|
}
|
|
|
func (o ovirt) vmDetails(c echo.Context) error {
|
|
@@ -1425,7 +1722,7 @@ func (o ovirt) vmDetails(c echo.Context) error {
|
|
|
uuid := c.FormValue("uuid")
|
|
|
if len(uuid) < 5 {
|
|
|
resp := _response{
|
|
|
- Origin: "AddUser",
|
|
|
+ Origin: "vmDetails",
|
|
|
Message: "Missing UUID",
|
|
|
Code: 1001,
|
|
|
}
|
|
@@ -1594,9 +1891,23 @@ func (o ovirt) vmDetails(c echo.Context) error {
|
|
|
_vmstatus := vmStatus{}
|
|
|
_err := json.Unmarshal(body, &_vmstatus)
|
|
|
if _err != nil {
|
|
|
- fmt.Println("Error in vmDetails : ", _err)
|
|
|
+ resp := _response{
|
|
|
+ Origin: "vmDetails",
|
|
|
+ Message: "Not Found",
|
|
|
+ Code: 1001,
|
|
|
+ }
|
|
|
+ return c.JSON(http.StatusNotFound, resp)
|
|
|
+ }
|
|
|
+ disk, cpu, ram, err := vmStatistics(BA, uuid)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error in vmDetails 2 : ", err)
|
|
|
+ resp := _response{
|
|
|
+ Origin: "vmDetails",
|
|
|
+ Message: "Unexpected Error",
|
|
|
+ Code: 1001,
|
|
|
+ }
|
|
|
+ return c.JSON(http.StatusInternalServerError, resp)
|
|
|
}
|
|
|
- disk, cpu, ram := vmStatistics(BA, uuid)
|
|
|
type AutoGenerated struct {
|
|
|
Message struct {
|
|
|
Disk string `json:"Disk"`
|
|
@@ -1655,3 +1966,309 @@ func (o ovirt) ovirtPayment(c echo.Context) error {
|
|
|
//return c.String(http.StatusOK, string(b))
|
|
|
return c.JSON(http.StatusOK, resp)
|
|
|
}
|
|
|
+func listNIC(VMUUID string) []struct {
|
|
|
+ Mac string `json:"mac"`
|
|
|
+ IPv4 string `json:"IPv4"`
|
|
|
+ IPv6 string `json:"IPv6"`
|
|
|
+ ReportedDevices struct {
|
|
|
+ Mac string `json:"mac"`
|
|
|
+ IPv4 string `json:"IPv4"`
|
|
|
+ IPv6 string `json:"IPv6"`
|
|
|
+ } `json:"reported_devices"`
|
|
|
+} {
|
|
|
+ type NICList struct {
|
|
|
+ NIC []struct {
|
|
|
+ Mac string `json:"mac"`
|
|
|
+ IPv4 string `json:"IPv4"`
|
|
|
+ IPv6 string `json:"IPv6"`
|
|
|
+ ReportedDevices struct {
|
|
|
+ Mac string `json:"mac"`
|
|
|
+ IPv4 string `json:"IPv4"`
|
|
|
+ IPv6 string `json:"IPv6"`
|
|
|
+ } `json:"reported_devices"`
|
|
|
+ } `json:"NIC"`
|
|
|
+ }
|
|
|
+
|
|
|
+ type VMNIC struct {
|
|
|
+ Nic []struct {
|
|
|
+ Interface string `json:"interface"`
|
|
|
+ Linked string `json:"linked"`
|
|
|
+ Mac struct {
|
|
|
+ Address string `json:"address"`
|
|
|
+ } `json:"mac"`
|
|
|
+ Plugged string `json:"plugged"`
|
|
|
+ ReportedDevices struct {
|
|
|
+ ReportedDevice []struct {
|
|
|
+ Ips struct {
|
|
|
+ IP []struct {
|
|
|
+ Address string `json:"address"`
|
|
|
+ Version string `json:"version"`
|
|
|
+ } `json:"ip"`
|
|
|
+ } `json:"ips"`
|
|
|
+ Mac struct {
|
|
|
+ Address string `json:"address"`
|
|
|
+ } `json:"mac"`
|
|
|
+ Type string `json:"type"`
|
|
|
+ Name string `json:"name"`
|
|
|
+ Description string `json:"description"`
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"reported_device"`
|
|
|
+ } `json:"reported_devices"`
|
|
|
+ VnicProfile struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"vnic_profile"`
|
|
|
+ Actions struct {
|
|
|
+ Link []struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ Rel string `json:"rel"`
|
|
|
+ } `json:"link"`
|
|
|
+ } `json:"actions"`
|
|
|
+ Name string `json:"name"`
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ VM struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ } `json:"vm"`
|
|
|
+ Link []struct {
|
|
|
+ Href string `json:"href"`
|
|
|
+ Rel string `json:"rel"`
|
|
|
+ } `json:"link"`
|
|
|
+ } `json:"nic"`
|
|
|
+ }
|
|
|
+ url := "https://ovirt-cl.zi-tel.com/ovirt-engine/api/vms/" + VMUUID + "/nics"
|
|
|
+ method := "GET"
|
|
|
+
|
|
|
+ payload := strings.NewReader(``)
|
|
|
+ client := &http.Client{
|
|
|
+ }
|
|
|
+ req, err := http.NewRequest(method, url, payload)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ req.Header.Add("Version", "4")
|
|
|
+ req.Header.Add("Accept", "application/json")
|
|
|
+ req.Header.Add("Authorization", "Basic YXJnbzhASVBBOjEyMw==")
|
|
|
+
|
|
|
+ res, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ defer res.Body.Close()
|
|
|
+
|
|
|
+ body, err := ioutil.ReadAll(res.Body)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ _VMNIC := VMNIC{}
|
|
|
+ err = json.Unmarshal(body, &_VMNIC)
|
|
|
+ if err != nil {
|
|
|
+ ///TODO: ErrorHandling
|
|
|
+ fmt.Println(err)
|
|
|
+ //return CPUPrice, memPrice, StoragePrice, IPPrice, extraBWPrice
|
|
|
+ }
|
|
|
+ _NICList := NICList{}
|
|
|
+ _Data := _NICList.NIC
|
|
|
+ x := struct {
|
|
|
+ Mac string `json:"mac"`
|
|
|
+ IPv4 string `json:"IPv4"`
|
|
|
+ IPv6 string `json:"IPv6"`
|
|
|
+ ReportedDevices struct {
|
|
|
+ Mac string `json:"mac"`
|
|
|
+ IPv4 string `json:"IPv4"`
|
|
|
+ IPv6 string `json:"IPv6"`
|
|
|
+ } `json:"reported_devices"`
|
|
|
+ }{}
|
|
|
+ for _, i := range _VMNIC.Nic {
|
|
|
+ x.IPv4 = "1.1.1.1"
|
|
|
+ ///TODO:GetAssignedIP
|
|
|
+ x.IPv6 = "Null"
|
|
|
+ x.Mac = i.Mac.Address
|
|
|
+ x.ReportedDevices.Mac = i.ReportedDevices.ReportedDevice[0].Mac.Address
|
|
|
+ x.ReportedDevices.IPv4 = i.ReportedDevices.ReportedDevice[0].Ips.IP[0].Address
|
|
|
+ x.ReportedDevices.IPv6 = i.ReportedDevices.ReportedDevice[0].Ips.IP[1].Address
|
|
|
+ _Data = append(_Data, x)
|
|
|
+ }
|
|
|
+ _NICList.NIC = _Data
|
|
|
+ return _NICList.NIC
|
|
|
+}
|
|
|
+func listDisks(VMUUID string) []struct {
|
|
|
+ Name string `json:"Name"`
|
|
|
+ TotalSize string `json:"TotalSize"`
|
|
|
+ ActualSize string `json:"ActualSize"`
|
|
|
+} {
|
|
|
+
|
|
|
+ type DiskList struct {
|
|
|
+ Disk []struct {
|
|
|
+ Name string `json:"Name"`
|
|
|
+ TotalSize string `json:"TotalSize"`
|
|
|
+ ActualSize string `json:"ActualSize"`
|
|
|
+ } `json:"Disk"`
|
|
|
+ }
|
|
|
+ type ListDisks 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 := "https://ovirt-cl.zi-tel.com/ovirt-engine/api/vms/bcb15dd8-d402-4b2e-99da-94496174ea6b/diskattachments"
|
|
|
+ method := "GET"
|
|
|
+
|
|
|
+ payload := strings.NewReader(``)
|
|
|
+
|
|
|
+ client := &http.Client{
|
|
|
+ }
|
|
|
+ req, err := http.NewRequest(method, url, payload)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ req.Header.Add("Version", "4")
|
|
|
+ req.Header.Add("Accept", "application/json")
|
|
|
+ req.Header.Add("Authorization", "Basic YXJnbzhASVBBOjEyMw==")
|
|
|
+
|
|
|
+ res, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ defer res.Body.Close()
|
|
|
+
|
|
|
+ body, err := ioutil.ReadAll(res.Body)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ _ListDisks := ListDisks{}
|
|
|
+ err = json.Unmarshal(body, &_ListDisks)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ _DiskList := DiskList{}
|
|
|
+ for _, v := range _ListDisks.DiskAttachment {
|
|
|
+ _DiskList.Disk = append(_DiskList.Disk, DiskDetails(v.Disk.ID))
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return _DiskList.Disk
|
|
|
+}
|
|
|
+
|
|
|
+func DiskDetails(id string) struct {
|
|
|
+ Name string `json:"Name"`
|
|
|
+ TotalSize string `json:"TotalSize"`
|
|
|
+ ActualSize string `json:"ActualSize"`
|
|
|
+} {
|
|
|
+ type DiskDetail 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"`
|
|
|
+ }
|
|
|
+ url := "https://ovirt-cl.zi-tel.com/ovirt-engine/api/disks/c9485030-687f-4987-9980-72e762bca829"
|
|
|
+ method := "GET"
|
|
|
+
|
|
|
+ payload := strings.NewReader(``)
|
|
|
+
|
|
|
+ client := &http.Client{
|
|
|
+ }
|
|
|
+ req, err := http.NewRequest(method, url, payload)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ }
|
|
|
+ req.Header.Add("Version", "4")
|
|
|
+ req.Header.Add("Accept", "application/json")
|
|
|
+ req.Header.Add("Authorization", "Basic YXJnbzhASVBBOjEyMw==")
|
|
|
+
|
|
|
+ res, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ }
|
|
|
+ defer res.Body.Close()
|
|
|
+
|
|
|
+ body, err := ioutil.ReadAll(res.Body)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ _DiskDetail := DiskDetail{}
|
|
|
+ err = json.Unmarshal(body, &_DiskDetail)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ Disk := struct {
|
|
|
+ Name string `json:"Name"`
|
|
|
+ TotalSize string `json:"TotalSize"`
|
|
|
+ ActualSize string `json:"ActualSize"`
|
|
|
+ }{
|
|
|
+ Name: _DiskDetail.Alias,
|
|
|
+ TotalSize: _DiskDetail.TotalSize,
|
|
|
+ ActualSize: _DiskDetail.ActualSize,
|
|
|
+ }
|
|
|
+
|
|
|
+ return Disk
|
|
|
+}
|