implement populate model hosts/instances/volumes/nets/devices

This commit is contained in:
2025-02-11 07:11:05 +00:00
parent bd1ea3e3e5
commit 5029ff4d2a
6 changed files with 551 additions and 162 deletions

View File

@@ -5,10 +5,8 @@ import (
"flag"
"fmt"
"log"
"net/http"
"strconv"
"time"
"github.com/gin-gonic/gin"
"github.com/luthermonson/go-proxmox"
)
@@ -28,25 +26,36 @@ func Run() {
token := fmt.Sprintf(`%s@%s!%s`, config.PVE.Token.USER, config.PVE.Token.REALM, config.PVE.Token.ID)
client = NewClient(token, config.PVE.Token.Secret)
router := gin.Default()
//router := gin.Default()
router.GET("/version", func(c *gin.Context) {
PVEVersion, err := client.Version()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
} else {
c.JSON(http.StatusOK, gin.H{"api-version": APIVersion, "pve-version": PVEVersion})
}
})
start := time.Now()
cluster := Cluster{}
cluster.Init(client)
cluster.Rebuild()
elapsed := time.Since(start)
router.GET("/nodes/:node", func(c *gin.Context) {
Node, err := client.Node(c.Param("node"))
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
} else {
c.JSON(http.StatusOK, gin.H{"node": Node})
}
})
fmt.Println(cluster)
fmt.Println(elapsed)
router.Run("0.0.0.0:" + strconv.Itoa(config.ListenPort))
/*
router.GET("/version", func(c *gin.Context) {
PVEVersion, err := client.Version()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
} else {
c.JSON(http.StatusOK, gin.H{"api-version": APIVersion, "pve-version": PVEVersion})
}
})
router.GET("/nodes/:node", func(c *gin.Context) {
Node, err := client.Node(c.Param("node"))
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
} else {
c.JSON(http.StatusOK, gin.H{"node": Node})
}
})
router.Run("0.0.0.0:" + strconv.Itoa(config.ListenPort))
*/
}