fix hard coded URL, add proxmox URL to config

This commit is contained in:
Arthur Lu 2025-01-28 00:48:53 +00:00
parent 58cf403d26
commit 3cea9f6bcd
4 changed files with 10 additions and 15 deletions

View File

@ -28,7 +28,7 @@ func Run() {
log.Println("Initialized config from " + *configPath) log.Println("Initialized config from " + *configPath)
token := fmt.Sprintf(`%s@%s!%s`, config.PVE.Token.USER, config.PVE.Token.REALM, config.PVE.Token.ID) 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) client = NewClient(config.PVE.URL, token, config.PVE.Token.Secret)
router := gin.Default() router := gin.Default()

View File

@ -15,7 +15,7 @@ type ProxmoxClient struct {
client *proxmox.Client client *proxmox.Client
} }
func NewClient(token string, secret string) ProxmoxClient { func NewClient(url string, token string, secret string) ProxmoxClient {
HTTPClient := http.Client{ HTTPClient := http.Client{
Transport: &http.Transport{ Transport: &http.Transport{
TLSClientConfig: &tls.Config{ TLSClientConfig: &tls.Config{
@ -24,7 +24,7 @@ func NewClient(token string, secret string) ProxmoxClient {
}, },
} }
client := proxmox.NewClient("https://pve.tronnet.net/api2/json", client := proxmox.NewClient(url,
proxmox.WithHTTPClient(&HTTPClient), proxmox.WithHTTPClient(&HTTPClient),
proxmox.WithAPIToken(token, secret), proxmox.WithAPIToken(token, secret),
) )
@ -78,9 +78,9 @@ func (pve ProxmoxClient) Node(nodeName string) (*Host, error) {
} }
host.Name = node.Name host.Name = node.Name
host.Cores.Total = uint64(node.CPUInfo.CPUs) host.Cores = uint64(node.CPUInfo.CPUs)
host.Memory.Total = uint64(node.Memory.Total) host.Memory = uint64(node.Memory.Total)
host.Swap.Total = uint64(node.Swap.Total) host.Swap = uint64(node.Swap.Total)
host.pvenode = node host.pvenode = node
return &host, err return &host, err

View File

@ -15,9 +15,9 @@ type Cluster struct {
type Host struct { type Host struct {
lock sync.Mutex lock sync.Mutex
Name string Name string
Cores Resource Cores uint64
Memory Resource Memory uint64
Swap Resource Swap uint64
Devices map[string]*Device Devices map[string]*Device
Instances map[uint]*Instance Instances map[uint]*Instance
pvenode *proxmox.Node pvenode *proxmox.Node
@ -47,12 +47,6 @@ type Instance struct {
configHostPCIs map[string]string configHostPCIs map[string]string
} }
type Resource struct {
Reserved uint64
Free uint64
Total uint64
}
type Volume struct { type Volume struct {
Path string Path string
Format string Format string

View File

@ -12,6 +12,7 @@ const MiB = 1024 * 1024
type Config struct { type Config struct {
ListenPort int `json:"listenPort"` ListenPort int `json:"listenPort"`
PVE struct { PVE struct {
URL string `json:"url"`
Token struct { Token struct {
USER string `json:"user"` USER string `json:"user"`
REALM string `json:"realm"` REALM string `json:"realm"`