fixing iscsi mapping for library

This commit is contained in:
2025-12-22 19:50:28 +00:00
parent 6a5ead9dbf
commit 4c3ea0059d
3 changed files with 175 additions and 21 deletions

View File

@@ -176,6 +176,10 @@ func (a *App) routes() {
func(w http.ResponseWriter, r *http.Request) { a.handleListVTLMediaChangers(w, r) },
nil, nil, nil, nil,
))
a.mux.HandleFunc("/api/v1/vtl/devices/iscsi", methodHandler(
func(w http.ResponseWriter, r *http.Request) { a.handleListVTLDevicesForISCSI(w, r) },
nil, nil, nil, nil,
))
a.mux.HandleFunc("/api/v1/vtl/changer/status", methodHandler(
func(w http.ResponseWriter, r *http.Request) { a.handleGetVTLMediaChangerStatus(w, r) },
nil, nil, nil, nil,

View File

@@ -285,3 +285,42 @@ func (a *App) handleEjectTape(w http.ResponseWriter, r *http.Request) {
"drive_id": fmt.Sprintf("%d", req.DriveID),
})
}
// handleListVTLDevicesForISCSI returns all tape devices (drives and medium changers) for iSCSI passthrough
func (a *App) handleListVTLDevicesForISCSI(w http.ResponseWriter, r *http.Request) {
devices := []map[string]interface{}{}
// Get drives
drives, err := a.vtlService.ListDrives()
if err == nil {
for _, drive := range drives {
devices = append(devices, map[string]interface{}{
"type": "drive",
"device": drive.Device,
"id": drive.ID,
"library_id": drive.LibraryID,
"vendor": drive.Vendor,
"product": drive.Product,
"description": fmt.Sprintf("Tape Drive %d (Library %d) - %s %s", drive.ID, drive.LibraryID, drive.Vendor, drive.Product),
})
}
}
// Get medium changers
changers, err := a.vtlService.ListMediaChangers()
if err == nil {
for _, changer := range changers {
devices = append(devices, map[string]interface{}{
"type": "changer",
"device": changer.Device,
"id": changer.ID,
"library_id": changer.LibraryID,
"slots": changer.Slots,
"drives": changer.Drives,
"description": fmt.Sprintf("Media Changer (Library %d) - %d slots, %d drives", changer.LibraryID, changer.Slots, changer.Drives),
})
}
}
writeJSON(w, http.StatusOK, devices)
}