Merge pull request #748 from JasonYangShadow/issue/690
KERNEL VERSION column is too short
This commit is contained in:
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Added a missing `.ww` extension to the `70-ww4-netname.rules` template in the
|
- Added a missing `.ww` extension to the `70-ww4-netname.rules` template in the
|
||||||
wwinit overlay.
|
wwinit overlay.
|
||||||
- Restrict access to `/warewulf/config` to root only. (#728, #742)
|
- Restrict access to `/warewulf/config` to root only. (#728, #742)
|
||||||
|
- KERNEL VERSION column is too short. #690
|
||||||
- Add support for resolving absolute path automatically. #493
|
- Add support for resolving absolute path automatically. #493
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
@@ -25,3 +25,4 @@
|
|||||||
* Jonathon Anderson <janderson@ciq.co> @anderbubble
|
* Jonathon Anderson <janderson@ciq.co> @anderbubble
|
||||||
* Brian Phan <bphan@ciq.co>
|
* Brian Phan <bphan@ciq.co>
|
||||||
* Jeffrey Frey @jtfrey
|
* Jeffrey Frey @jtfrey
|
||||||
|
* Xu Yang(Jason Yang) <jasonyangshadow@gmail.com> @JasonYangShadow
|
||||||
|
|||||||
1
go.mod
1
go.mod
@@ -13,6 +13,7 @@ require (
|
|||||||
github.com/google/uuid v1.1.2
|
github.com/google/uuid v1.1.2
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.0
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.0
|
||||||
github.com/manifoldco/promptui v0.8.0
|
github.com/manifoldco/promptui v0.8.0
|
||||||
|
github.com/olekukonko/tablewriter v0.0.5
|
||||||
github.com/opencontainers/image-spec v1.0.2-0.20190823105129-775207bd45b6
|
github.com/opencontainers/image-spec v1.0.2-0.20190823105129-775207bd45b6
|
||||||
github.com/opencontainers/umoci v0.4.6
|
github.com/opencontainers/umoci v0.4.6
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -515,6 +515,8 @@ github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/
|
|||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||||
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
|
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
|
||||||
|
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||||
|
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||||
github.com/onsi/ginkgo v0.0.0-20151202141238-7f8ab55aaf3b/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v0.0.0-20151202141238-7f8ab55aaf3b/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
|
|||||||
@@ -1,34 +1,40 @@
|
|||||||
package list
|
package list
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hpcng/warewulf/internal/app/wwctl/helper"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/api/container"
|
"github.com/hpcng/warewulf/internal/pkg/api/container"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
var containerList = container.ContainerList
|
||||||
|
|
||||||
containerInfo, err := container.ContainerList()
|
func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err error) {
|
||||||
|
return func(cmd *cobra.Command, args []string) (err error) {
|
||||||
|
containerInfo, err := containerList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wwlog.Error("%s", err)
|
wwlog.Error("%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("%-16s %-6s %-16s %-20s %-20s %-8s\n", "CONTAINER NAME", "NODES", "KERNEL VERSION", "CREATION TIME", "MODIFICATION TIME", "SIZE")
|
ph := helper.NewPrintHelper([]string{"CONTAINER NAME", "NODES", "KERNEL VERSION", "CREATION TIME", "MODIFICATION TIME", "SIZE"})
|
||||||
for i := 0; i < len(containerInfo); i++ {
|
for i := 0; i < len(containerInfo); i++ {
|
||||||
createTime := time.Unix(int64(containerInfo[i].CreateDate), 0)
|
createTime := time.Unix(int64(containerInfo[i].CreateDate), 0)
|
||||||
modTime := time.Unix(int64(containerInfo[i].ModDate), 0)
|
modTime := time.Unix(int64(containerInfo[i].ModDate), 0)
|
||||||
fmt.Printf("%-16s %-6d %-16s %-20s %-20s %-8s\n",
|
ph.Append([]string{
|
||||||
containerInfo[i].Name,
|
containerInfo[i].Name,
|
||||||
containerInfo[i].NodeCount,
|
strconv.FormatUint(uint64(containerInfo[i].NodeCount), 10),
|
||||||
containerInfo[i].KernelVersion,
|
containerInfo[i].KernelVersion,
|
||||||
createTime.Format(time.RFC822),
|
createTime.Format(time.RFC822),
|
||||||
modTime.Format(time.RFC822),
|
modTime.Format(time.RFC822),
|
||||||
util.ByteToString(int64(containerInfo[i].Size)))
|
util.ByteToString(int64(containerInfo[i].Size)),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
ph.Render()
|
||||||
return
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
100
internal/app/wwctl/container/list/main_test.go
Normal file
100
internal/app/wwctl/container/list/main_test.go
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
package list
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/warewulfd"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_List(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args []string
|
||||||
|
stdout string
|
||||||
|
inDb string
|
||||||
|
mockFunc func()
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "profile list test",
|
||||||
|
args: []string{},
|
||||||
|
stdout: `CONTAINERNAMENODESKERNELVERSIONCREATIONTIMEMODIFICATIONTIMESIZE
|
||||||
|
test1kernel01Jan7000:00UTC01Jan7000:00UTC1B
|
||||||
|
`,
|
||||||
|
inDb: `WW_INTERNAL: 43
|
||||||
|
nodeprofiles:
|
||||||
|
default: {}
|
||||||
|
nodes:
|
||||||
|
n01:
|
||||||
|
profiles:
|
||||||
|
- default
|
||||||
|
`,
|
||||||
|
mockFunc: func() {
|
||||||
|
containerList = func() (containerInfo []*wwapiv1.ContainerInfo, err error) {
|
||||||
|
containerInfo = append(containerInfo, &wwapiv1.ContainerInfo{
|
||||||
|
Name: "test",
|
||||||
|
NodeCount: 1,
|
||||||
|
KernelVersion: "kernel",
|
||||||
|
CreateDate: uint64(time.Unix(0, 0).Unix()),
|
||||||
|
ModDate: uint64(time.Unix(0, 0).Unix()),
|
||||||
|
Size: uint64(1),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
conf_yml := `
|
||||||
|
WW_INTERNAL: 0
|
||||||
|
`
|
||||||
|
|
||||||
|
conf := warewulfconf.New()
|
||||||
|
err := conf.Read([]byte(conf_yml))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
warewulfd.SetNoDaemon()
|
||||||
|
for _, tt := range tests {
|
||||||
|
_, err = node.TestNew([]byte(tt.inDb))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
t.Logf("Running test: %s\n", tt.name)
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
tt.mockFunc()
|
||||||
|
baseCmd := GetCommand()
|
||||||
|
baseCmd.SetArgs(tt.args)
|
||||||
|
baseCmd.SetOut(nil)
|
||||||
|
baseCmd.SetErr(nil)
|
||||||
|
stdoutR, stdoutW, _ := os.Pipe()
|
||||||
|
os.Stdout = stdoutW
|
||||||
|
err = baseCmd.Execute()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Received error when running command, err: %v", err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
stdoutC := make(chan string)
|
||||||
|
go func() {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
_, _ = io.Copy(&buf, stdoutR)
|
||||||
|
stdoutC <- buf.String()
|
||||||
|
}()
|
||||||
|
stdoutW.Close()
|
||||||
|
|
||||||
|
stdout := <-stdoutC
|
||||||
|
stdout = strings.TrimSpace(stdout)
|
||||||
|
stdout = strings.ReplaceAll(stdout, " ", "")
|
||||||
|
assert.NotEmpty(t, stdout, "os.stdout should not be empty")
|
||||||
|
tt.stdout = strings.ReplaceAll(strings.TrimSpace(tt.stdout), " ", "")
|
||||||
|
if stdout != strings.ReplaceAll(strings.TrimSpace(tt.stdout), " ", "") {
|
||||||
|
t.Errorf("Got wrong output, got:\n '%s'\n, but want:\n '%s'\n", stdout, tt.stdout)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,18 +2,18 @@ package list
|
|||||||
|
|
||||||
import "github.com/spf13/cobra"
|
import "github.com/spf13/cobra"
|
||||||
|
|
||||||
var (
|
type variables struct{}
|
||||||
baseCmd = &cobra.Command{
|
|
||||||
|
// GetRootCommand returns the root cobra.Command for the application.
|
||||||
|
func GetCommand() *cobra.Command {
|
||||||
|
vars := variables{}
|
||||||
|
baseCmd := &cobra.Command{
|
||||||
DisableFlagsInUseLine: true,
|
DisableFlagsInUseLine: true,
|
||||||
Use: "list [OPTIONS]",
|
Use: "list [OPTIONS]",
|
||||||
Short: "List imported Warewulf containers",
|
Short: "List imported Warewulf containers",
|
||||||
Long: "This command will show you the containers that are imported into Warewulf.",
|
Long: "This command will show you the containers that are imported into Warewulf.",
|
||||||
RunE: CobraRunE,
|
RunE: CobraRunE(&vars),
|
||||||
Aliases: []string{"ls"},
|
Aliases: []string{"ls"},
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
// GetRootCommand returns the root cobra.Command for the application.
|
|
||||||
func GetCommand() *cobra.Command {
|
|
||||||
return baseCmd
|
return baseCmd
|
||||||
}
|
}
|
||||||
|
|||||||
27
internal/app/wwctl/helper/printhelper.go
Normal file
27
internal/app/wwctl/helper/printhelper.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/olekukonko/tablewriter"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PrintHelper struct {
|
||||||
|
*tablewriter.Table
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPrintHelper(header []string) *PrintHelper {
|
||||||
|
tb := tablewriter.NewWriter(os.Stdout)
|
||||||
|
tb.SetHeader(header)
|
||||||
|
tb.SetAutoWrapText(false)
|
||||||
|
tb.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
|
||||||
|
tb.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||||
|
tb.SetCenterSeparator("")
|
||||||
|
tb.SetColumnSeparator("")
|
||||||
|
tb.SetRowSeparator("")
|
||||||
|
tb.SetHeaderLine(false)
|
||||||
|
tb.SetBorder(false)
|
||||||
|
return &PrintHelper{
|
||||||
|
Table: tb,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,30 +1,37 @@
|
|||||||
package list
|
package list
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/hpcng/warewulf/internal/app/wwctl/helper"
|
||||||
apinode "github.com/hpcng/warewulf/internal/pkg/api/node"
|
apinode "github.com/hpcng/warewulf/internal/pkg/api/node"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
|
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err error) {
|
||||||
|
return func(cmd *cobra.Command, args []string) (err error) {
|
||||||
req := wwapiv1.GetNodeList{
|
req := wwapiv1.GetNodeList{
|
||||||
Nodes: args,
|
Nodes: args,
|
||||||
Type: wwapiv1.GetNodeList_Simple,
|
Type: wwapiv1.GetNodeList_Simple,
|
||||||
}
|
}
|
||||||
if ShowAll {
|
if vars.showAll {
|
||||||
req.Type = wwapiv1.GetNodeList_All
|
req.Type = wwapiv1.GetNodeList_All
|
||||||
} else if ShowIpmi {
|
} else if vars.showIpmi {
|
||||||
req.Type = wwapiv1.GetNodeList_Ipmi
|
req.Type = wwapiv1.GetNodeList_Ipmi
|
||||||
} else if ShowNet {
|
} else if vars.showNet {
|
||||||
req.Type = wwapiv1.GetNodeList_Network
|
req.Type = wwapiv1.GetNodeList_Network
|
||||||
} else if ShowLong {
|
} else if vars.showLong {
|
||||||
req.Type = wwapiv1.GetNodeList_Long
|
req.Type = wwapiv1.GetNodeList_Long
|
||||||
}
|
}
|
||||||
nodeInfo, err := apinode.NodeList(&req)
|
nodeInfo, err := apinode.NodeList(&req)
|
||||||
for _, str := range nodeInfo.Output {
|
if len(nodeInfo.Output) > 0 {
|
||||||
fmt.Printf("%s\n", str)
|
ph := helper.NewPrintHelper(strings.Split(nodeInfo.Output[0], "="))
|
||||||
|
for _, val := range nodeInfo.Output[1:] {
|
||||||
|
ph.Append(strings.Split(val, "="))
|
||||||
|
}
|
||||||
|
ph.Render()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
80
internal/app/wwctl/node/list/main_test.go
Normal file
80
internal/app/wwctl/node/list/main_test.go
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package list
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/warewulfd"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_List(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args []string
|
||||||
|
wantErr bool
|
||||||
|
stdout string
|
||||||
|
inDb string
|
||||||
|
}{
|
||||||
|
{name: "single node list",
|
||||||
|
args: []string{},
|
||||||
|
wantErr: false,
|
||||||
|
stdout: ` NODE NAME PROFILES NETWORK
|
||||||
|
n01 default
|
||||||
|
`,
|
||||||
|
inDb: `WW_INTERNAL: 43
|
||||||
|
nodeprofiles:
|
||||||
|
default: {}
|
||||||
|
nodes:
|
||||||
|
n01:
|
||||||
|
profiles:
|
||||||
|
- default
|
||||||
|
`},
|
||||||
|
}
|
||||||
|
conf_yml := `
|
||||||
|
WW_INTERNAL: 0
|
||||||
|
`
|
||||||
|
conf := warewulfconf.New()
|
||||||
|
err := conf.Read([]byte(conf_yml))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
warewulfd.SetNoDaemon()
|
||||||
|
for _, tt := range tests {
|
||||||
|
_, err = node.TestNew([]byte(tt.inDb))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
t.Logf("Running test: %s\n", tt.name)
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
baseCmd := GetCommand()
|
||||||
|
baseCmd.SetArgs(tt.args)
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
baseCmd.SetOut(buf)
|
||||||
|
baseCmd.SetErr(buf)
|
||||||
|
old := os.Stdout // keep backup of the real stdout
|
||||||
|
r, w, _ := os.Pipe()
|
||||||
|
os.Stdout = w
|
||||||
|
err = baseCmd.Execute()
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("Got unwanted error: %s", err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
outC := make(chan string)
|
||||||
|
go func() {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
_, _ = io.Copy(&buf, r)
|
||||||
|
outC <- buf.String()
|
||||||
|
}()
|
||||||
|
// back to normal state
|
||||||
|
w.Close()
|
||||||
|
os.Stdout = old // restoring the real stdout
|
||||||
|
out := <-outC
|
||||||
|
if out != tt.stdout {
|
||||||
|
t.Errorf("Got wrong output, got:'%s'\nwant:'%s'", out, tt.stdout)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,14 +5,22 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
type variables struct {
|
||||||
baseCmd = &cobra.Command{
|
showNet bool
|
||||||
|
showIpmi bool
|
||||||
|
showAll bool
|
||||||
|
showLong bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetCommand() *cobra.Command {
|
||||||
|
vars := variables{}
|
||||||
|
baseCmd := &cobra.Command{
|
||||||
DisableFlagsInUseLine: true,
|
DisableFlagsInUseLine: true,
|
||||||
Use: "list [OPTIONS] [PATTERN]",
|
Use: "list [OPTIONS] [PATTERN]",
|
||||||
Short: "List nodes",
|
Short: "List nodes",
|
||||||
Long: "This command lists all configured nodes. Optionally, it will list only\n" +
|
Long: "This command lists all configured nodes. Optionally, it will list only\n" +
|
||||||
"nodes matching a glob PATTERN.",
|
"nodes matching a glob PATTERN.",
|
||||||
RunE: CobraRunE,
|
RunE: CobraRunE(&vars),
|
||||||
Aliases: []string{"ls"},
|
Aliases: []string{"ls"},
|
||||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
@@ -28,20 +36,10 @@ var (
|
|||||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ShowNet bool
|
baseCmd.PersistentFlags().BoolVarP(&vars.showNet, "net", "n", false, "Show node network configurations")
|
||||||
ShowIpmi bool
|
baseCmd.PersistentFlags().BoolVarP(&vars.showIpmi, "ipmi", "i", false, "Show node IPMI configurations")
|
||||||
ShowAll bool
|
baseCmd.PersistentFlags().BoolVarP(&vars.showAll, "all", "a", false, "Show all node configurations")
|
||||||
ShowLong bool
|
baseCmd.PersistentFlags().BoolVarP(&vars.showLong, "long", "l", false, "Show long or wide format")
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
baseCmd.PersistentFlags().BoolVarP(&ShowNet, "net", "n", false, "Show node network configurations")
|
|
||||||
baseCmd.PersistentFlags().BoolVarP(&ShowIpmi, "ipmi", "i", false, "Show node IPMI configurations")
|
|
||||||
baseCmd.PersistentFlags().BoolVarP(&ShowAll, "all", "a", false, "Show all node configurations")
|
|
||||||
baseCmd.PersistentFlags().BoolVarP(&ShowLong, "long", "l", false, "Show long or wide format")
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRootCommand returns the root cobra.Command for the application.
|
|
||||||
func GetCommand() *cobra.Command {
|
|
||||||
return baseCmd
|
return baseCmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,33 @@
|
|||||||
package list
|
package list
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/hpcng/warewulf/internal/app/wwctl/helper"
|
||||||
apiprofile "github.com/hpcng/warewulf/internal/pkg/api/profile"
|
apiprofile "github.com/hpcng/warewulf/internal/pkg/api/profile"
|
||||||
|
|
||||||
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
|
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err error) {
|
||||||
|
return func(cmd *cobra.Command, args []string) (err error) {
|
||||||
req := wwapiv1.GetProfileList{
|
req := wwapiv1.GetProfileList{
|
||||||
ShowAll: ShowAll,
|
ShowAll: vars.showAll,
|
||||||
Profiles: args,
|
Profiles: args,
|
||||||
}
|
}
|
||||||
profileInfo, err := apiprofile.ProfileList(&req)
|
profileInfo, err := apiprofile.ProfileList(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, str := range profileInfo.Output {
|
|
||||||
fmt.Printf("%s\n", str)
|
if len(profileInfo.Output) > 0 {
|
||||||
|
ph := helper.NewPrintHelper(strings.Split(profileInfo.Output[0], "="))
|
||||||
|
for _, val := range profileInfo.Output[1:] {
|
||||||
|
ph.Append(strings.Split(val, "="))
|
||||||
|
}
|
||||||
|
ph.Render()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
84
internal/app/wwctl/profile/list/main_test.go
Normal file
84
internal/app/wwctl/profile/list/main_test.go
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
package list
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/warewulfd"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_List(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args []string
|
||||||
|
stdout string
|
||||||
|
inDb string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "profile list test",
|
||||||
|
args: []string{},
|
||||||
|
stdout: `PROFILE NAME COMMENT/DESCRIPTION
|
||||||
|
default --`,
|
||||||
|
inDb: `WW_INTERNAL: 43
|
||||||
|
nodeprofiles:
|
||||||
|
default: {}
|
||||||
|
nodes:
|
||||||
|
n01:
|
||||||
|
profiles:
|
||||||
|
- default
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
conf_yml := `
|
||||||
|
WW_INTERNAL: 0
|
||||||
|
`
|
||||||
|
|
||||||
|
conf := warewulfconf.New()
|
||||||
|
err := conf.Read([]byte(conf_yml))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
warewulfd.SetNoDaemon()
|
||||||
|
for _, tt := range tests {
|
||||||
|
_, err = node.TestNew([]byte(tt.inDb))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
t.Logf("Running test: %s\n", tt.name)
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
baseCmd := GetCommand()
|
||||||
|
baseCmd.SetArgs(tt.args)
|
||||||
|
baseCmd.SetOut(nil)
|
||||||
|
baseCmd.SetErr(nil)
|
||||||
|
stdoutR, stdoutW, _ := os.Pipe()
|
||||||
|
oriout := os.Stdout
|
||||||
|
os.Stdout = stdoutW
|
||||||
|
err = baseCmd.Execute()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Received error when running command, err: %v", err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
stdoutC := make(chan string)
|
||||||
|
go func() {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
_, _ = io.Copy(&buf, stdoutR)
|
||||||
|
stdoutC <- buf.String()
|
||||||
|
}()
|
||||||
|
stdoutW.Close()
|
||||||
|
os.Stdout = oriout
|
||||||
|
|
||||||
|
stdout := <-stdoutC
|
||||||
|
stdout = strings.TrimSpace(stdout)
|
||||||
|
stdout = strings.ReplaceAll(stdout, " ", "")
|
||||||
|
assert.NotEmpty(t, stdout, "os.stdout should not be empty")
|
||||||
|
tt.stdout = strings.ReplaceAll(strings.TrimSpace(tt.stdout), " ", "")
|
||||||
|
if stdout != strings.ReplaceAll(strings.TrimSpace(tt.stdout), " ", "") {
|
||||||
|
t.Errorf("Got wrong output, got:\n '%s'\n, but want:\n '%s'\n", stdout, tt.stdout)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,23 +2,22 @@ package list
|
|||||||
|
|
||||||
import "github.com/spf13/cobra"
|
import "github.com/spf13/cobra"
|
||||||
|
|
||||||
var (
|
type variables struct {
|
||||||
baseCmd = &cobra.Command{
|
showAll bool
|
||||||
DisableFlagsInUseLine: true,
|
|
||||||
Use: "list [OPTIONS] [PROFILE ...]",
|
|
||||||
Short: "List profiles and configurations",
|
|
||||||
Long: "This command will display configurations for PROFILE.",
|
|
||||||
RunE: CobraRunE,
|
|
||||||
Aliases: []string{"ls"},
|
|
||||||
}
|
|
||||||
ShowAll bool
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
baseCmd.PersistentFlags().BoolVarP(&ShowAll, "all", "a", false, "Show all node configurations")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRootCommand returns the root cobra.Command for the application.
|
// GetRootCommand returns the root cobra.Command for the application.
|
||||||
func GetCommand() *cobra.Command {
|
func GetCommand() *cobra.Command {
|
||||||
|
vars := variables{}
|
||||||
|
baseCmd := &cobra.Command{
|
||||||
|
DisableFlagsInUseLine: true,
|
||||||
|
Use: "list [OPTIONS] [PROFILE ...]",
|
||||||
|
Short: "List profiles and configurations",
|
||||||
|
Long: "This command will display configurations for PROFILE.",
|
||||||
|
RunE: CobraRunE(&vars),
|
||||||
|
Aliases: []string{"ls"},
|
||||||
|
}
|
||||||
|
baseCmd.PersistentFlags().BoolVarP(&vars.showAll, "all", "a", false, "Show all node configurations")
|
||||||
|
|
||||||
return baseCmd
|
return baseCmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,7 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
|
|||||||
sort.Strings(nodeGet.Nodes)
|
sort.Strings(nodeGet.Nodes)
|
||||||
if nodeGet.Type == wwapiv1.GetNodeList_Simple {
|
if nodeGet.Type == wwapiv1.GetNodeList_Simple {
|
||||||
nodeList.Output = append(nodeList.Output,
|
nodeList.Output = append(nodeList.Output,
|
||||||
fmt.Sprintf("%-22s %-26s %s", "NODE NAME", "PROFILES", "NETWORK"))
|
fmt.Sprintf("%s=%s=%s", "NODE NAME", "PROFILES", "NETWORK"))
|
||||||
nodeList.Output = append(nodeList.Output, (strings.Repeat("=", 80)))
|
|
||||||
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
|
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
|
||||||
var netNames []string
|
var netNames []string
|
||||||
for k := range n.NetDevs {
|
for k := range n.NetDevs {
|
||||||
@@ -38,33 +37,31 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
|
|||||||
}
|
}
|
||||||
sort.Strings(netNames)
|
sort.Strings(netNames)
|
||||||
nodeList.Output = append(nodeList.Output,
|
nodeList.Output = append(nodeList.Output,
|
||||||
fmt.Sprintf("%-22s %-26s %s", n.Id.Print(), n.Profiles.Print(), strings.Join(netNames, ", ")))
|
fmt.Sprintf("%s=%s=%s", n.Id.Print(), n.Profiles.Print(), strings.Join(netNames, ", ")))
|
||||||
}
|
}
|
||||||
} else if nodeGet.Type == wwapiv1.GetNodeList_Network {
|
} else if nodeGet.Type == wwapiv1.GetNodeList_Network {
|
||||||
nodeList.Output = append(nodeList.Output,
|
nodeList.Output = append(nodeList.Output,
|
||||||
fmt.Sprintf("%-22s %-8s %-18s %-15s %-15s %-15s", "NODE NAME", "NAME", "HWADDR", "IPADDR", "GATEWAY", "DEVICE"),
|
fmt.Sprintf("%s=%s=%s=%s=%s=%s", "NODE NAME", "NAME", "HWADDR", "IPADDR", "GATEWAY", "DEVICE"))
|
||||||
strings.Repeat("=", 90))
|
|
||||||
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
|
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
|
||||||
if len(n.NetDevs) > 0 {
|
if len(n.NetDevs) > 0 {
|
||||||
for name := range n.NetDevs {
|
for name := range n.NetDevs {
|
||||||
nodeList.Output = append(nodeList.Output,
|
nodeList.Output = append(nodeList.Output,
|
||||||
fmt.Sprintf("%-22s %-8s %-18s %-15s %-15s %-15s", n.Id.Print(), name,
|
fmt.Sprintf("%s=%s=%s=%s=%s=%s", n.Id.Print(), name,
|
||||||
n.NetDevs[name].Hwaddr.Print(),
|
n.NetDevs[name].Hwaddr.Print(),
|
||||||
n.NetDevs[name].Ipaddr.Print(),
|
n.NetDevs[name].Ipaddr.Print(),
|
||||||
n.NetDevs[name].Gateway.Print(),
|
n.NetDevs[name].Gateway.Print(),
|
||||||
n.NetDevs[name].Device.Print()))
|
n.NetDevs[name].Device.Print()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%-22s %-6s %-18s %-15s %-15s", n.Id.Print(), "--", "--", "--", "--")
|
fmt.Printf("%s=%s=%s=%s=%s=%s", n.Id.Print(), "--", "--", "--", "--", "--")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if nodeGet.Type == wwapiv1.GetNodeList_Ipmi {
|
} else if nodeGet.Type == wwapiv1.GetNodeList_Ipmi {
|
||||||
nodeList.Output = append(nodeList.Output,
|
nodeList.Output = append(nodeList.Output,
|
||||||
fmt.Sprintf("%-22s %-16s %-10s %-20s %-14s", "NODE NAME", "IPMI IPADDR", "IPMI PORT", "IPMI USERNAME", "IPMI INTERFACE"),
|
fmt.Sprintf("%s=%s=%s=%s=%s", "NODE NAME", "IPMI IPADDR", "IPMI PORT", "IPMI USERNAME", "IPMI INTERFACE"))
|
||||||
strings.Repeat("=", 98))
|
|
||||||
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
|
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
|
||||||
nodeList.Output = append(nodeList.Output,
|
nodeList.Output = append(nodeList.Output,
|
||||||
fmt.Sprintf("%-22s %-16s %-10s %-20s %-14s", n.Id.Print(),
|
fmt.Sprintf("%s=%s=%s=%s=%s", n.Id.Print(),
|
||||||
n.Ipmi.Ipaddr.Print(),
|
n.Ipmi.Ipaddr.Print(),
|
||||||
n.Ipmi.Port.Print(),
|
n.Ipmi.Port.Print(),
|
||||||
n.Ipmi.UserName.Print(),
|
n.Ipmi.UserName.Print(),
|
||||||
@@ -72,19 +69,18 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
|
|||||||
}
|
}
|
||||||
} else if nodeGet.Type == wwapiv1.GetNodeList_Long {
|
} else if nodeGet.Type == wwapiv1.GetNodeList_Long {
|
||||||
nodeList.Output = append(nodeList.Output,
|
nodeList.Output = append(nodeList.Output,
|
||||||
fmt.Sprintf("%-22s %-16s %-16s %s", "NODE NAME", "KERNEL OVERRIDE", "CONTAINER", "OVERLAYS (S/R)"),
|
fmt.Sprintf("%s=%s=%s=%s", "NODE NAME", "KERNEL OVERRIDE", "CONTAINER", "OVERLAYS (S/R)"))
|
||||||
strings.Repeat("=", 85))
|
|
||||||
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
|
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
|
||||||
nodeList.Output = append(nodeList.Output,
|
nodeList.Output = append(nodeList.Output,
|
||||||
fmt.Sprintf("%-22s %-16s %-16s %s", n.Id.Print(),
|
fmt.Sprintf("%s=%s=%s=%s", n.Id.Print(),
|
||||||
n.Kernel.Override.Print(),
|
n.Kernel.Override.Print(),
|
||||||
n.ContainerName.Print(),
|
n.ContainerName.Print(),
|
||||||
n.SystemOverlay.Print()+"/"+n.RuntimeOverlay.Print()))
|
n.SystemOverlay.Print()+"/"+n.RuntimeOverlay.Print()))
|
||||||
}
|
}
|
||||||
} else if nodeGet.Type == wwapiv1.GetNodeList_All {
|
} else if nodeGet.Type == wwapiv1.GetNodeList_All {
|
||||||
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
|
|
||||||
nodeList.Output = append(nodeList.Output,
|
nodeList.Output = append(nodeList.Output,
|
||||||
fmt.Sprintf("%-20s %-18s %-12s %s", "NODE", "FIELD", "PROFILE", "VALUE"), strings.Repeat("=", 85))
|
fmt.Sprintf("%s=%s=%s=%s", "NODE", "FIELD", "PROFILE", "VALUE"))
|
||||||
|
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
|
||||||
nType := reflect.TypeOf(n)
|
nType := reflect.TypeOf(n)
|
||||||
nVal := reflect.ValueOf(n)
|
nVal := reflect.ValueOf(n)
|
||||||
nConfType := reflect.TypeOf(node.NodeConf{})
|
nConfType := reflect.TypeOf(node.NodeConf{})
|
||||||
@@ -101,12 +97,12 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
|
|||||||
fieldSource = entr.Source()
|
fieldSource = entr.Source()
|
||||||
fieldVal = entr.Print()
|
fieldVal = entr.Print()
|
||||||
nodeList.Output = append(nodeList.Output,
|
nodeList.Output = append(nodeList.Output,
|
||||||
fmt.Sprintf("%-20s %-18s %-12s %s", n.Id.Print(), fieldName, fieldSource, fieldVal))
|
fmt.Sprintf("%s=%s=%s=%s", n.Id.Print(), fieldName, fieldSource, fieldVal))
|
||||||
} else if nType.Field(i).Type == reflect.TypeOf(map[string]*node.Entry{}) {
|
} else if nType.Field(i).Type == reflect.TypeOf(map[string]*node.Entry{}) {
|
||||||
entrMap := nVal.Field(i).Interface().(map[string]*node.Entry)
|
entrMap := nVal.Field(i).Interface().(map[string]*node.Entry)
|
||||||
for key, val := range entrMap {
|
for key, val := range entrMap {
|
||||||
nodeList.Output = append(nodeList.Output,
|
nodeList.Output = append(nodeList.Output,
|
||||||
fmt.Sprintf("%-20s %-18s %-12s %s", n.Id.Print(), key, val.Source(), val.Print()))
|
fmt.Sprintf("%s=%s=%s=%s", n.Id.Print(), key, val.Source(), val.Print()))
|
||||||
}
|
}
|
||||||
} else if nType.Field(i).Type == reflect.TypeOf(map[string]*node.NetDevEntry{}) {
|
} else if nType.Field(i).Type == reflect.TypeOf(map[string]*node.NetDevEntry{}) {
|
||||||
netDevs := nVal.Field(i).Interface().(map[string]*node.NetDevEntry)
|
netDevs := nVal.Field(i).Interface().(map[string]*node.NetDevEntry)
|
||||||
@@ -132,7 +128,7 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
|
|||||||
// only print fields with lopt
|
// only print fields with lopt
|
||||||
if netConfField.Tag.Get("lopt") != "" {
|
if netConfField.Tag.Get("lopt") != "" {
|
||||||
nodeList.Output = append(nodeList.Output,
|
nodeList.Output = append(nodeList.Output,
|
||||||
fmt.Sprintf("%-20s %-18s %-12s %s", n.Id.Print(), fieldName, fieldSource, fieldVal))
|
fmt.Sprintf("%s=%s=%s=%s", n.Id.Print(), fieldName, fieldSource, fieldVal))
|
||||||
}
|
}
|
||||||
} else if netInfoType.Field(j).Type == reflect.TypeOf(map[string]*node.Entry{}) {
|
} else if netInfoType.Field(j).Type == reflect.TypeOf(map[string]*node.Entry{}) {
|
||||||
for key, val := range netInfoVal.Field(j).Interface().(map[string]*node.Entry) {
|
for key, val := range netInfoVal.Field(j).Interface().(map[string]*node.Entry) {
|
||||||
@@ -140,7 +136,7 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
|
|||||||
fieldSource = val.Source()
|
fieldSource = val.Source()
|
||||||
fieldVal = val.Print()
|
fieldVal = val.Print()
|
||||||
nodeList.Output = append(nodeList.Output,
|
nodeList.Output = append(nodeList.Output,
|
||||||
fmt.Sprintf("%-20s %-18s %-12s %s", n.Id.Print(), keyfieldName, fieldSource, fieldVal))
|
fmt.Sprintf("%s=%s=%s=%s", n.Id.Print(), keyfieldName, fieldSource, fieldVal))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,14 +158,14 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
|
|||||||
fieldSource = entr.Source()
|
fieldSource = entr.Source()
|
||||||
fieldVal = entr.Print()
|
fieldVal = entr.Print()
|
||||||
nodeList.Output = append(nodeList.Output,
|
nodeList.Output = append(nodeList.Output,
|
||||||
fmt.Sprintf("%-20s %-18s %-12s %s", n.Id.Print(), fieldName, fieldSource, fieldVal))
|
fmt.Sprintf("%s=%s=%s=%s", n.Id.Print(), fieldName, fieldSource, fieldVal))
|
||||||
} else if nestInfoType.Elem().Field(j).Type == reflect.TypeOf(map[string]*node.Entry{}) {
|
} else if nestInfoType.Elem().Field(j).Type == reflect.TypeOf(map[string]*node.Entry{}) {
|
||||||
for key, val := range nestInfoVal.Elem().Field(j).Interface().(map[string]*node.Entry) {
|
for key, val := range nestInfoVal.Elem().Field(j).Interface().(map[string]*node.Entry) {
|
||||||
fieldName = fieldName + ":" + key
|
fieldName = fieldName + ":" + key
|
||||||
fieldSource = val.Source()
|
fieldSource = val.Source()
|
||||||
fieldVal = val.Print()
|
fieldVal = val.Print()
|
||||||
nodeList.Output = append(nodeList.Output,
|
nodeList.Output = append(nodeList.Output,
|
||||||
fmt.Sprintf("%-20s %-18s %-12s %s", n.Id.Print(), fieldName, fieldSource, fieldVal))
|
fmt.Sprintf("%s=%s=%s=%s", n.Id.Print(), fieldName, fieldSource, fieldVal))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,7 +173,6 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
|
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||||
@@ -34,7 +33,7 @@ func ProfileList(ShowOpt *wwapiv1.GetProfileList) (profileList wwapiv1.ProfileLi
|
|||||||
if ShowOpt.ShowAll {
|
if ShowOpt.ShowAll {
|
||||||
for _, p := range profiles {
|
for _, p := range profiles {
|
||||||
profileList.Output = append(profileList.Output,
|
profileList.Output = append(profileList.Output,
|
||||||
fmt.Sprintf("%-20s %-18s %-12s %s", "PROFILE", "FIELD", "PROFILE", "VALUE"), strings.Repeat("=", 85))
|
fmt.Sprintf("%s=%s=%s=%s", "PROFILE", "FIELD", "PROFILE", "VALUE"))
|
||||||
nType := reflect.TypeOf(p)
|
nType := reflect.TypeOf(p)
|
||||||
nVal := reflect.ValueOf(p)
|
nVal := reflect.ValueOf(p)
|
||||||
nConfType := reflect.TypeOf(node.NodeConf{})
|
nConfType := reflect.TypeOf(node.NodeConf{})
|
||||||
@@ -51,12 +50,12 @@ func ProfileList(ShowOpt *wwapiv1.GetProfileList) (profileList wwapiv1.ProfileLi
|
|||||||
fieldSource = entr.Source()
|
fieldSource = entr.Source()
|
||||||
fieldVal = entr.Print()
|
fieldVal = entr.Print()
|
||||||
profileList.Output = append(profileList.Output,
|
profileList.Output = append(profileList.Output,
|
||||||
fmt.Sprintf("%-20s %-18s %-12s %s", p.Id.Print(), fieldName, fieldSource, fieldVal))
|
fmt.Sprintf("%s=%s=%s=%s", p.Id.Print(), fieldName, fieldSource, fieldVal))
|
||||||
} else if nType.Field(i).Type == reflect.TypeOf(map[string]*node.Entry{}) {
|
} else if nType.Field(i).Type == reflect.TypeOf(map[string]*node.Entry{}) {
|
||||||
entrMap := nVal.Field(i).Interface().(map[string]*node.Entry)
|
entrMap := nVal.Field(i).Interface().(map[string]*node.Entry)
|
||||||
for key, val := range entrMap {
|
for key, val := range entrMap {
|
||||||
profileList.Output = append(profileList.Output,
|
profileList.Output = append(profileList.Output,
|
||||||
fmt.Sprintf("%-20s %-18s %-12s %s", p.Id.Print(), key, val.Source(), val.Print()))
|
fmt.Sprintf("%s=%s=%s=%s", p.Id.Print(), key, val.Source(), val.Print()))
|
||||||
}
|
}
|
||||||
} else if nType.Field(i).Type == reflect.TypeOf(map[string]*node.NetDevEntry{}) {
|
} else if nType.Field(i).Type == reflect.TypeOf(map[string]*node.NetDevEntry{}) {
|
||||||
netDevs := nVal.Field(i).Interface().(map[string]*node.NetDevEntry)
|
netDevs := nVal.Field(i).Interface().(map[string]*node.NetDevEntry)
|
||||||
@@ -82,7 +81,7 @@ func ProfileList(ShowOpt *wwapiv1.GetProfileList) (profileList wwapiv1.ProfileLi
|
|||||||
// only print fields with lopt
|
// only print fields with lopt
|
||||||
if netConfField.Tag.Get("lopt") != "" {
|
if netConfField.Tag.Get("lopt") != "" {
|
||||||
profileList.Output = append(profileList.Output,
|
profileList.Output = append(profileList.Output,
|
||||||
fmt.Sprintf("%-20s %-18s %-12s %s", p.Id.Print(), fieldName, fieldSource, fieldVal))
|
fmt.Sprintf("%s=%s=%s=%s", p.Id.Print(), fieldName, fieldSource, fieldVal))
|
||||||
}
|
}
|
||||||
} else if netInfoType.Field(j).Type == reflect.TypeOf(map[string]*node.Entry{}) {
|
} else if netInfoType.Field(j).Type == reflect.TypeOf(map[string]*node.Entry{}) {
|
||||||
for key, val := range netInfoVal.Field(j).Interface().(map[string]*node.Entry) {
|
for key, val := range netInfoVal.Field(j).Interface().(map[string]*node.Entry) {
|
||||||
@@ -90,7 +89,7 @@ func ProfileList(ShowOpt *wwapiv1.GetProfileList) (profileList wwapiv1.ProfileLi
|
|||||||
fieldSource = val.Source()
|
fieldSource = val.Source()
|
||||||
fieldVal = val.Print()
|
fieldVal = val.Print()
|
||||||
profileList.Output = append(profileList.Output,
|
profileList.Output = append(profileList.Output,
|
||||||
fmt.Sprintf("%-20s %-18s %-12s %s", p.Id.Print(), keyfieldName, fieldSource, fieldVal))
|
fmt.Sprintf("%s=%s=%s=%s", p.Id.Print(), keyfieldName, fieldSource, fieldVal))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,14 +111,14 @@ func ProfileList(ShowOpt *wwapiv1.GetProfileList) (profileList wwapiv1.ProfileLi
|
|||||||
fieldSource = entr.Source()
|
fieldSource = entr.Source()
|
||||||
fieldVal = entr.Print()
|
fieldVal = entr.Print()
|
||||||
profileList.Output = append(profileList.Output,
|
profileList.Output = append(profileList.Output,
|
||||||
fmt.Sprintf("%-20s %-18s %-12s %s", p.Id.Print(), fieldName, fieldSource, fieldVal))
|
fmt.Sprintf("%s=%s=%s=%s", p.Id.Print(), fieldName, fieldSource, fieldVal))
|
||||||
} else if nestInfoType.Elem().Field(j).Type == reflect.TypeOf(map[string]*node.Entry{}) {
|
} else if nestInfoType.Elem().Field(j).Type == reflect.TypeOf(map[string]*node.Entry{}) {
|
||||||
for key, val := range nestInfoVal.Elem().Field(j).Interface().(map[string]*node.Entry) {
|
for key, val := range nestInfoVal.Elem().Field(j).Interface().(map[string]*node.Entry) {
|
||||||
fieldName = fieldName + ":" + key
|
fieldName = fieldName + ":" + key
|
||||||
fieldSource = val.Source()
|
fieldSource = val.Source()
|
||||||
fieldVal = val.Print()
|
fieldVal = val.Print()
|
||||||
profileList.Output = append(profileList.Output,
|
profileList.Output = append(profileList.Output,
|
||||||
fmt.Sprintf("%-20s %-18s %-12s %s", p.Id.Print(), fieldName, fieldSource, fieldVal))
|
fmt.Sprintf("%s=%s=%s=%s", p.Id.Print(), fieldName, fieldSource, fieldVal))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,12 +127,11 @@ func ProfileList(ShowOpt *wwapiv1.GetProfileList) (profileList wwapiv1.ProfileLi
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
profileList.Output = append(profileList.Output,
|
profileList.Output = append(profileList.Output,
|
||||||
fmt.Sprintf("%-20s %s", "PROFILE NAME", "COMMENT/DESCRIPTION"))
|
fmt.Sprintf("%s=%s", "PROFILE NAME", "COMMENT/DESCRIPTION"))
|
||||||
profileList.Output = append(profileList.Output, strings.Repeat("=", 80))
|
|
||||||
|
|
||||||
for _, profile := range profiles {
|
for _, profile := range profiles {
|
||||||
profileList.Output = append(profileList.Output,
|
profileList.Output = append(profileList.Output,
|
||||||
fmt.Sprintf("%-20s %s", profile.Id.Print(), profile.Comment.Print()))
|
fmt.Sprintf("%s=%s", profile.Id.Print(), profile.Comment.Print()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user