From 4c3ea0059dd4dbca784b57f2873de5f44231886f Mon Sep 17 00:00:00 2001 From: Othman Hendy Suseo Date: Mon, 22 Dec 2025 19:50:28 +0000 Subject: [PATCH] fixing iscsi mapping for library --- internal/httpapp/routes.go | 4 + internal/httpapp/vtl_handlers.go | 39 ++++++++ web/templates/iscsi.html | 153 ++++++++++++++++++++++++++----- 3 files changed, 175 insertions(+), 21 deletions(-) diff --git a/internal/httpapp/routes.go b/internal/httpapp/routes.go index f231f6c..06a566b 100644 --- a/internal/httpapp/routes.go +++ b/internal/httpapp/routes.go @@ -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, diff --git a/internal/httpapp/vtl_handlers.go b/internal/httpapp/vtl_handlers.go index 61c678e..713db70 100644 --- a/internal/httpapp/vtl_handlers.go +++ b/internal/httpapp/vtl_handlers.go @@ -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) +} diff --git a/web/templates/iscsi.html b/web/templates/iscsi.html index 9436dfc..551dd3a 100644 --- a/web/templates/iscsi.html +++ b/web/templates/iscsi.html @@ -85,21 +85,43 @@