Skip to content

Commit f6323c8

Browse files
committed
Changed endpoint and check for WaitForDisk
1 parent 2ea0893 commit f6323c8

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

internal/proxmox/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type ProxmoxConfig struct {
1717
CriticalPool string `envconfig:"PROXMOX_CRITICAL_POOL"`
1818
Realm string `envconfig:"REALM"`
1919
NodesStr string `envconfig:"PROXMOX_NODES"`
20+
StorageID string `envconfig:"STORAGE_ID" default:"local-lvm"`
2021
Nodes []string // Parsed from NodesStr
2122
APIToken string // Computed from TokenID and TokenSecret
2223
}
@@ -152,3 +153,8 @@ type ClusterResourceUsageResponse struct {
152153
Nodes []NodeResourceUsage `json:"nodes"`
153154
Errors []string `json:"errors,omitempty"`
154155
}
156+
157+
type PendingDiskResponse struct {
158+
Used int64 `json:"used"`
159+
Size int64 `json:"size"`
160+
}

internal/proxmox/vms.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,28 @@ func (s *ProxmoxService) WaitForDisk(node string, vmid int, maxWait time.Duratio
207207
if configResp.HardDisk != "" {
208208
pendingReq := tools.ProxmoxAPIRequest{
209209
Method: "GET",
210-
Endpoint: fmt.Sprintf("/nodes/%s/qemu/%d/pending", node, vmid),
210+
Endpoint: fmt.Sprintf("/nodes/%s/storage/%s/content?vmid=%d", node, s.Config.StorageID, vmid),
211211
}
212212

213-
pendingResponse, err := s.RequestHelper.MakeRequest(pendingReq)
214-
log.Printf("Pending response for VMID %d on node %s: %s", vmid, node, string(pendingResponse))
215-
if err != nil && strings.Contains(err.Error(), "does not exist") {
216-
log.Printf("Disk for VMID %d on node %s not ready yet: %v", vmid, node, err)
217-
continue // Disk not synced yet
213+
var diskResponse []PendingDiskResponse
214+
err := s.RequestHelper.MakeRequestAndUnmarshal(pendingReq, &diskResponse)
215+
if err != nil || len(diskResponse) == 0 {
216+
log.Printf("Error retrieving pending disk info for VMID %d on node %s: %v", vmid, node, err)
217+
continue
218+
}
219+
220+
// Iterate through all disks, if all have valid Used and Size (not 0) consider available
221+
allAvailable := true
222+
for _, disk := range diskResponse {
223+
if disk.Used == 0 || disk.Size == 0 {
224+
allAvailable = false
225+
break
226+
}
218227
}
219228

220-
return nil // Disk is available
229+
if allAvailable {
230+
return nil // Disk is available
231+
}
221232
}
222233
}
223234

0 commit comments

Comments
 (0)