feat: implement cmd management for targets, LUNs, and TPGTs (fixes #36)
- Fix target delete URL path mismatch (/targets/ -> /target/) - Implement target create/delete server handlers with proper validation - Add DeleteTarget method with force flag and mutex locking to SCSITargetService - Implement full LU management: create/list/delete through CLI, client, and server - Add TPGT list command to show target portal group tags - Add unit tests for target/LU router handlers and SCSI service Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
13
pkg/api/client/lu_create.go
Normal file
13
pkg/api/client/lu_create.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/gostor/gotgt/pkg/api"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// LuCreate creates a LU in the SCSI Target.
|
||||
func (cli *Client) LuCreate(ctx context.Context, options api.LuCreateRequest) error {
|
||||
resp, err := cli.post(ctx, "/lu/create", nil, options, nil)
|
||||
ensureReaderClosed(resp)
|
||||
return err
|
||||
}
|
||||
13
pkg/api/client/lu_delete.go
Normal file
13
pkg/api/client/lu_delete.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/gostor/gotgt/pkg/api"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// LuRemove removes a LU from a target in the SCSI Target.
|
||||
func (cli *Client) LuRemove(ctx context.Context, options api.LuRemoveOptions) error {
|
||||
resp, err := cli.post(ctx, "/lu/delete", nil, options, nil)
|
||||
ensureReaderClosed(resp)
|
||||
return err
|
||||
}
|
||||
25
pkg/api/client/lu_list.go
Normal file
25
pkg/api/client/lu_list.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
|
||||
"github.com/gostor/gotgt/pkg/api"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// LuList lists LUs for a target in the SCSI Target.
|
||||
func (cli *Client) LuList(ctx context.Context, options api.LuListOptions) ([]api.LuInfo, error) {
|
||||
var lus []api.LuInfo
|
||||
query := url.Values{}
|
||||
if options.TargetName != "" {
|
||||
query.Set("target", options.TargetName)
|
||||
}
|
||||
resp, err := cli.get(ctx, "/lu/list", query, nil)
|
||||
if err != nil {
|
||||
return lus, err
|
||||
}
|
||||
err = json.NewDecoder(resp.body).Decode(&lus)
|
||||
ensureReaderClosed(resp)
|
||||
return lus, err
|
||||
}
|
||||
@@ -29,7 +29,7 @@ func (cli *Client) TargetRemove(ctx context.Context, options api.TargetRemoveOpt
|
||||
if options.Force {
|
||||
query.Set("force", "1")
|
||||
}
|
||||
resp, err := cli.delete(ctx, "/targets/"+options.Name, query, nil)
|
||||
resp, err := cli.delete(ctx, "/target/"+options.Name, query, nil)
|
||||
ensureReaderClosed(resp)
|
||||
return err
|
||||
}
|
||||
|
||||
25
pkg/api/client/tpgt_list.go
Normal file
25
pkg/api/client/tpgt_list.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
|
||||
"github.com/gostor/gotgt/pkg/api"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// TpgtList lists TPGTs for a target in the SCSI Target.
|
||||
func (cli *Client) TpgtList(ctx context.Context, options api.TpgtListOptions) ([]api.TpgtInfo, error) {
|
||||
var tpgts []api.TpgtInfo
|
||||
query := url.Values{}
|
||||
if options.TargetName != "" {
|
||||
query.Set("target", options.TargetName)
|
||||
}
|
||||
resp, err := cli.get(ctx, "/target/tpgt/list", query, nil)
|
||||
if err != nil {
|
||||
return tpgts, err
|
||||
}
|
||||
err = json.NewDecoder(resp.body).Decode(&tpgts)
|
||||
ensureReaderClosed(resp)
|
||||
return tpgts, err
|
||||
}
|
||||
@@ -29,3 +29,36 @@ type TargetListOptions struct {
|
||||
Name string
|
||||
Verbose bool
|
||||
}
|
||||
|
||||
type LuCreateRequest struct {
|
||||
TargetName string `json:"targetName"`
|
||||
DeviceID uint64 `json:"deviceID"`
|
||||
LUN uint64 `json:"lun"`
|
||||
Path string `json:"path"`
|
||||
BlockShift uint `json:"blockShift"`
|
||||
}
|
||||
|
||||
type LuListOptions struct {
|
||||
TargetName string
|
||||
}
|
||||
|
||||
type LuRemoveOptions struct {
|
||||
TargetName string `json:"targetName"`
|
||||
LUN uint64 `json:"lun"`
|
||||
}
|
||||
|
||||
type LuInfo struct {
|
||||
LUN uint64 `json:"lun"`
|
||||
Path string `json:"path"`
|
||||
Online bool `json:"online"`
|
||||
Size uint64 `json:"size"`
|
||||
}
|
||||
|
||||
type TpgtListOptions struct {
|
||||
TargetName string
|
||||
}
|
||||
|
||||
type TpgtInfo struct {
|
||||
TPGT uint16 `json:"tpgt"`
|
||||
Portals []string `json:"portals"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user