Skip to content
Merged

Misc #1003

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/commoncmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,15 @@ func HiddenFlagObjectSelector(flags *pflag.FlagSet, p *string) {
FlagObjectSelector(flags, p)
flags.MarkHidden("selector")
}

func FlagSCSIHBA(flags *pflag.FlagSet, p *string) {
flags.StringVar(p, "hba", "", "Specify a hba to scan for new block devices. Example: 5001438002432430 or iqn.1993-08.org.debian:01:659b4bbd68bd.")
}

func FlagSCSITarget(flags *pflag.FlagSet, p *string) {
flags.StringVar(p, "target", "", "Specify a target to scan for new block devices. Example: 5000097358185088 or iqn.clementine.tgt1.")
}

func FlagSCSILUN(flags *pflag.FlagSet, p *string) {
flags.StringVar(p, "lun", "", "Specify a logical unit number to scan for new block devices. Example: 1.")
}
21 changes: 21 additions & 0 deletions core/datarecv/keymeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ func ParseKeyMetaRelObj(line string, i any) (KeyMeta, error) {
return ParseKeyMetaRel(line, o.Path().Namespace)
}

// ParseKeyMetaRelWithFallback parses a key reference in the format "from <path> key <key>"
// and falls back to the legacy format "<path>" with a default key name for backward compatibility.
func ParseKeyMetaRelWithFallback(line, namespace, defaultKey string) (KeyMeta, error) {
// Try new format first
km, err := ParseKeyMetaRel(line, namespace)
if err == nil {
return km, nil
}

// Fall back to legacy format: just the path, using defaultKey
path, err := naming.ParsePath(line)
if err != nil {
return KeyMeta{}, err
}
return KeyMeta{
Path: path,
From: namespace,
Key: defaultKey,
}, nil
}

func ParseKeyMetaRel(line, namespace string) (KeyMeta, error) {
var (
km KeyMeta
Expand Down
7 changes: 7 additions & 0 deletions core/object/node.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package object

import (
"context"
"fmt"

"github.com/google/uuid"
Expand All @@ -9,6 +10,7 @@ import (
"github.com/opensvc/om3/v3/core/xconfig"
"github.com/opensvc/om3/v3/util/funcopt"
"github.com/opensvc/om3/v3/util/plog"
"github.com/opensvc/om3/v3/util/scsi"
)

type (
Expand Down Expand Up @@ -71,3 +73,8 @@ func (t *Node) SetVolatile(v bool) {
func (t Node) IsVolatile() bool {
return t.volatile
}

// ScanSCSI scans the SCSI hosts in search of new disks
func (t Node) ScanSCSI(ctx context.Context, hba, target, lun string) error {
return scsi.ScanSCSIHosts(hba, target, lun)
}
6 changes: 4 additions & 2 deletions core/object/text/kw/node/array.password,optional
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
The password to use to log in, expressed as a datastore reference:
The password to use to log in, expressed as a datastore reference.

from <namespace>/<kind>/<name> key <name>
Value format:
- New format: `from <namespace>/<kind>/<name> key <key name>`
- Legacy format: `<namespace>/<kind>/<name>` (uses default key "password")

Array passwords are usually stored in sec datastores like `system/sec/<array name>`.
6 changes: 4 additions & 2 deletions core/object/text/kw/node/array.password,required
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
The password to use to log in, expressed as a datastore reference:
The password to use to log in, expressed as a datastore reference.

from <namespace>/<kind>/<name> key <name>
Value format:
- New format: `from <namespace>/<kind>/<name> key <key name>`
- Legacy format: `<namespace>/<kind>/<name>` (uses default key "password")

Array passwords are usually stored in sec datastores like `system/sec/<array name>`.
4 changes: 4 additions & 0 deletions core/object/text/kw/node/hb.relay.password
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
A datastore key reference to a password used to authenticate with the relay API.

Value format:
- New format: `from <namespace>/<kind>/<name> key <key name>`
- Legacy format: `<namespace>/<kind>/<name>` (uses default key "password")
47 changes: 40 additions & 7 deletions core/om/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,8 @@ func newCmdNodeCapabilitiesList() *cobra.Command {
func newCmdNodeCapabilitiesScan() *cobra.Command {
var options commands.CmdNodeCapabilitiesScan
cmd := &cobra.Command{
Use: "scan",
Short: "scan the node capabilities",
Aliases: []string{"sca", "sc"},
Use: "scan",
Short: "scan the node capabilities",
Long: `Scan the node for capabilities.

Capabilities are normally scanned at daemon startup and when the installed
Expand All @@ -522,6 +521,27 @@ installed software to be discovered without restarting the daemon.`,
return cmd
}

func newCmdNodeSCSIScan() *cobra.Command {
var options commands.CmdNodeSCSIScan
cmd := &cobra.Command{
Use: "scan",
Short: "scan the scsi hosts in search of new disks",
Long: `Scan the scsi hosts in search of new disks.

This command scans SCSI hosts for new block devices. You can specify specific HBA, target, and LUN to scan.`,
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
commoncmd.FlagNodeSelector(flags, &options.NodeSelector)
commoncmd.FlagSCSIHBA(flags, &options.HBA)
commoncmd.FlagSCSITarget(flags, &options.Target)
commoncmd.FlagSCSILUN(flags, &options.LUN)
return cmd
}

func newCmdNodeChecks() *cobra.Command {
var options commands.CmdNodeChecks
cmd := &cobra.Command{
Expand Down Expand Up @@ -922,9 +942,9 @@ func newCmdNodeDrain() *cobra.Command {
func newCmdNodeDrivers() *cobra.Command {
var options commands.CmdNodeDrivers
cmd := &cobra.Command{
GroupID: commoncmd.GroupIDQuery,
Use: "drivers",
Short: "list builtin drivers",
Aliases: []string{"driver", "drive", "driv", "drv", "dr"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
Expand Down Expand Up @@ -1111,7 +1131,7 @@ func newCmdNodeList() *cobra.Command {
return cmd
}

func newCmdNodePRKey() *cobra.Command {
func newCmdNodeSCSIPRKey() *cobra.Command {
var options commands.CmdNodePRKey
cmd := &cobra.Command{
Use: "prkey",
Expand Down Expand Up @@ -3274,7 +3294,7 @@ func newCmdNodePrintSchedule() *cobra.Command {
cmd := newCmdNodeScheduleList()
cmd.Hidden = true
cmd.Use = "schedule"
cmd.Aliases = []string{"schedul", "schedu", "sched", "sche", "sch", "sc"}
cmd.Aliases = []string{"sched"}
return cmd
}

Expand Down Expand Up @@ -3390,7 +3410,7 @@ func newCmdObjectPrintSchedule(kind string) *cobra.Command {
cmd := newCmdObjectScheduleList(kind)
cmd.Hidden = true
cmd.Use = "schedule"
cmd.Aliases = []string{"schedul", "schedu", "sched", "sche", "sch", "sc"}
cmd.Aliases = []string{"sched"}
return cmd
}

Expand Down Expand Up @@ -3564,6 +3584,19 @@ func newCmdDataStoreRename(kind string) *cobra.Command {
return cmd
}

func newCmdNodePRKey() *cobra.Command {
cmd := newCmdNodeSCSIPRKey()
cmd.Hidden = true
return cmd
}

func newCmdNodeScanscsi() *cobra.Command {
cmd := newCmdNodeSCSIScan()
cmd.Use = "scanscsi"
cmd.Hidden = true
return cmd
}

func newCmdObjectGen(kind string) *cobra.Command {
return &cobra.Command{
Use: "gen",
Expand Down
113 changes: 72 additions & 41 deletions core/om/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,84 +11,101 @@ import (
var (
cmdNode = commoncmd.NewCmdNode()
cmdNodeCapabilities = &cobra.Command{
GroupID: commoncmd.GroupIDSubsystems,
Use: "capabilities",
Short: "scan and list what the node is capable of",
Aliases: []string{"capa", "caps", "cap"},
}
cmdNodeCollector = &cobra.Command{
GroupID: commoncmd.GroupIDSubsystems,
Use: "collector",
Short: "node collector data management commands",
Aliases: []string{"coll"},
}
cmdNodeCollectorTag = &cobra.Command{
Use: "tag",
Short: "collector tags management commands",
GroupID: commoncmd.GroupIDSubsystems,
Use: "tag",
Short: "collector tags management commands",
}
cmdNodeCompliance = &cobra.Command{
GroupID: commoncmd.GroupIDSubsystems,
Use: "compliance",
Short: "node configuration manager commands",
Aliases: []string{"comp"},
}
cmdNodeComplianceAttach = &cobra.Command{
Use: "attach",
Short: "attach modulesets and rulesets to the node",
Aliases: []string{"atta", "att", "at"},
}
cmdNodeComplianceDetach = &cobra.Command{
Use: "detach",
Short: "detach modulesets and rulesets from the node",
Aliases: []string{"deta", "det", "de"},
}
cmdNodeComplianceList = &cobra.Command{
Use: "list",
Short: "list modules, modulesets and rulesets available",
Aliases: []string{"lis", "li", "ls", "l"},
}
cmdNodeComplianceShow = &cobra.Command{
Use: "show",
Short: "show modules, modulesets, rulesets, modules, attachments",
Aliases: []string{"sho", "sh", "s"},
}
cmdNodeConfig = &cobra.Command{
GroupID: commoncmd.GroupIDSubsystems,
Use: "config",
Short: "configuration commands",
Aliases: []string{"conf", "c", "cf", "cfg"},
}
cmdNodePrint = &cobra.Command{
Use: "print",
Hidden: true,
Aliases: []string{"prin", "pri", "pr"},
}
cmdNodePush = &cobra.Command{
Use: "push",
Short: "push node discover information to the collector",
cmdNodeSCSI = &cobra.Command{
GroupID: commoncmd.GroupIDSubsystems,
Use: "scsi",
Short: "scsi commands",
}
cmdNodeRelay = &cobra.Command{
Use: "relay",
Short: "relay subsystem commands",
GroupID: commoncmd.GroupIDSubsystems,
Use: "relay",
Short: "relay commands",
}
cmdNodeScan = &cobra.Command{
Use: "scan",
Hidden: true,
}
cmdNodeSchedule = &cobra.Command{
Use: "schedule",
Short: "node scheduler commands",
GroupID: commoncmd.GroupIDSubsystems,
Use: "schedule",
Short: "scheduler commands",
}
cmdNodeSSH = &cobra.Command{
Use: "ssh",
Short: "ssh subsystem commands",
GroupID: commoncmd.GroupIDSubsystems,
Use: "ssh",
Short: "ssh commands",
}

// Backward compat

cmdNodeEdit = newCmdNodeEdit()
cmdNodeValidate = newCmdNodeValidate()

cmdNodeUpdateSSH = &cobra.Command{
Use: "ssh",
Hidden: true,
}
cmdNodePrint = &cobra.Command{
Use: "print",
Hidden: true,
Aliases: []string{"prin", "pri", "pr"},
}
cmdNodePush = &cobra.Command{
Use: "push",
Short: "push node discover information to the collector",
}
cmdNodeUpdate = &cobra.Command{
Use: "update",
Hidden: true,
}
cmdNodeUpdateSSH = &cobra.Command{
Use: "ssh",
Hidden: true,
cmdNodeComplianceAttach = &cobra.Command{
Use: "attach",
Short: "attach modulesets and rulesets to the node",
Aliases: []string{"atta", "att", "at"},
}
cmdNodeComplianceDetach = &cobra.Command{
Use: "detach",
Short: "detach modulesets and rulesets from the node",
Aliases: []string{"deta", "det", "de"},
}
cmdNodeComplianceList = &cobra.Command{
Use: "list",
Short: "list modules, modulesets and rulesets available",
Aliases: []string{"lis", "li", "ls", "l"},
}
cmdNodeComplianceShow = &cobra.Command{
Use: "show",
Short: "show modules, modulesets, rulesets, modules, attachments",
Aliases: []string{"sho", "sh", "s"},
}
cmdNodeEdit = newCmdNodeEdit()
cmdNodeValidate = newCmdNodeValidate()
)

// getCmdNodeWithVersion returns cmdNode with --version (for backward compatibility with b2.1)
Expand All @@ -108,6 +125,14 @@ func getCmdNodeWithVersion() *cobra.Command {
func init() {
// Add backward compatibility for --version flag
cmdNode = getCmdNodeWithVersion()
cmdNode.AddGroup(
// commoncmd.NewGroupOrchestratedActions(),
// commoncmd.NewGroupQuery(),
commoncmd.NewGroupSubsystems(),
)
cmdNodeCollector.AddGroup(
commoncmd.NewGroupSubsystems(),
)

root.AddCommand(cmdNode)
cmdNode.AddCommand(cmdNodeCapabilities)
Expand Down Expand Up @@ -163,6 +188,7 @@ func init() {
cmdNodePush,
cmdNodeRelay,
cmdNodeScan,
cmdNodeSCSI,
cmdNodeSchedule,
cmdNodeSSH,
cmdNodeUpdate,
Expand All @@ -184,6 +210,7 @@ func init() {
newCmdNodeEvents(),
newCmdNodeEval(),
newCmdNodeRegister(),
newCmdNodeScanscsi(),
newCmdNodeSet(),
newCmdNodeStonith(),
newCmdNodeSysreport(),
Expand Down Expand Up @@ -216,6 +243,10 @@ func init() {
cmdNodeScan.AddCommand(
newCmdNodeScanCapabilities(),
)
cmdNodeSCSI.AddCommand(
newCmdNodeSCSIScan(),
newCmdNodeSCSIPRKey(),
)
cmdNodeSchedule.AddCommand(
newCmdNodeScheduleList(),
)
Expand Down
File renamed without changes.
Loading
Loading