From 522c3478fb030ce497be3ef2bef6c129d86a3c8a Mon Sep 17 00:00:00 2001 From: jason yang Date: Thu, 23 Mar 2023 02:44:59 +0000 Subject: [PATCH] use tablewriter to format the output Signed-off-by: jason yang --- .gitattributes | 1 + CHANGELOG.md | 3 ++ CONTRIBUTORS.md | 1 + go.mod | 1 + go.sum | 2 ++ internal/app/wwctl/container/list/main.go | 14 ++++---- internal/app/wwctl/helper/printhelper.go | 27 ++++++++++++++++ internal/app/wwctl/node/list/main.go | 11 +++++-- internal/app/wwctl/profile/list/main.go | 12 +++++-- internal/pkg/api/container/container.go | 17 ++++++---- internal/pkg/api/node/list.go | 39 ++++++++++------------- internal/pkg/api/profile/list.go | 20 ++++++------ overlays/host/dnsmasq.d/ww4-hosts.conf.ww | 30 +++++++++++++++++ userdocs/contents/dnsmasq.rst | 17 ++++++++++ 14 files changed, 144 insertions(+), 51 deletions(-) create mode 100644 .gitattributes create mode 100644 internal/app/wwctl/helper/printhelper.go create mode 100644 overlays/host/dnsmasq.d/ww4-hosts.conf.ww create mode 100644 userdocs/contents/dnsmasq.rst diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..a19ade07 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +CHANGELOG.md merge=union diff --git a/CHANGELOG.md b/CHANGELOG.md index d1017537..7d9a46d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,11 +14,14 @@ 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 wwinit overlay. - 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 ### Changed - The primary hostname and warewulf server fqdn are now the canonical name in `/etc/hosts` +- Added experimental dnsmasq support. ## [4.4.0] 2023-01-18 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 51b37bcf..45ee2d7d 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -25,3 +25,4 @@ * Jonathon Anderson @anderbubble * Brian Phan * Jeffrey Frey @jtfrey +* Xu Yang(Jason Yang) @JasonYangShadow diff --git a/go.mod b/go.mod index b9997019..05bf0a16 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/google/uuid v1.1.2 github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.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/umoci v0.4.6 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 415618da..63f92078 100644 --- a/go.sum +++ b/go.sum @@ -517,6 +517,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/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.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-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= diff --git a/internal/app/wwctl/container/list/main.go b/internal/app/wwctl/container/list/main.go index 56b468d7..b949f349 100644 --- a/internal/app/wwctl/container/list/main.go +++ b/internal/app/wwctl/container/list/main.go @@ -1,9 +1,10 @@ package list import ( - "fmt" + "strconv" "time" + "github.com/hpcng/warewulf/internal/app/wwctl/helper" "github.com/hpcng/warewulf/internal/pkg/api/container" "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" @@ -11,24 +12,25 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) (err error) { - containerInfo, err := container.ContainerList() if err != nil { wwlog.Error("%s", err) 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++ { createTime := time.Unix(int64(containerInfo[i].CreateDate), 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].NodeCount, + strconv.FormatUint(uint64(containerInfo[i].NodeCount), 10), containerInfo[i].KernelVersion, createTime.Format(time.RFC822), modTime.Format(time.RFC822), - util.ByteToString(int64(containerInfo[i].Size))) + util.ByteToString(int64(containerInfo[i].Size)), + }) } + ph.Render() return } diff --git a/internal/app/wwctl/helper/printhelper.go b/internal/app/wwctl/helper/printhelper.go new file mode 100644 index 00000000..2361ebd8 --- /dev/null +++ b/internal/app/wwctl/helper/printhelper.go @@ -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, + } +} diff --git a/internal/app/wwctl/node/list/main.go b/internal/app/wwctl/node/list/main.go index 0bbad793..2b626a70 100644 --- a/internal/app/wwctl/node/list/main.go +++ b/internal/app/wwctl/node/list/main.go @@ -1,8 +1,9 @@ package list import ( - "fmt" + "strings" + "github.com/hpcng/warewulf/internal/app/wwctl/helper" apinode "github.com/hpcng/warewulf/internal/pkg/api/node" "github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1" "github.com/spf13/cobra" @@ -23,8 +24,12 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) { req.Type = wwapiv1.GetNodeList_Long } nodeInfo, err := apinode.NodeList(&req) - for _, str := range nodeInfo.Output { - fmt.Printf("%s\n", str) + if len(nodeInfo.Output) > 0 { + ph := helper.NewPrintHelper(strings.Split(nodeInfo.Output[0], "=")) + for _, val := range nodeInfo.Output[1:] { + ph.Append(strings.Split(val, "=")) + } + ph.Render() } return } diff --git a/internal/app/wwctl/profile/list/main.go b/internal/app/wwctl/profile/list/main.go index 516da680..34791034 100644 --- a/internal/app/wwctl/profile/list/main.go +++ b/internal/app/wwctl/profile/list/main.go @@ -1,8 +1,9 @@ package list import ( - "fmt" + "strings" + "github.com/hpcng/warewulf/internal/app/wwctl/helper" apiprofile "github.com/hpcng/warewulf/internal/pkg/api/profile" "github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1" @@ -18,8 +19,13 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) { if err != nil { 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 } diff --git a/internal/pkg/api/container/container.go b/internal/pkg/api/container/container.go index fdf720fd..5ae4347a 100644 --- a/internal/pkg/api/container/container.go +++ b/internal/pkg/api/container/container.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path" + "path/filepath" "strconv" "strings" @@ -18,7 +19,6 @@ import ( ) func ContainerBuild(cbp *wwapiv1.ContainerBuildParameter) (err error) { - if cbp == nil { return fmt.Errorf("ContainerBuildParameter is nil") } @@ -60,7 +60,7 @@ func ContainerBuild(cbp *wwapiv1.ContainerBuildParameter) (err error) { return } - //TODO: Don't loop through profiles, instead have a nodeDB function that goes directly to the map + // TODO: Don't loop through profiles, instead have a nodeDB function that goes directly to the map profiles, _ := nodeDB.FindAllProfiles() for _, profile := range profiles { wwlog.Debug("Looking for profile default: %s", profile.Id.Get()) @@ -85,7 +85,6 @@ func ContainerBuild(cbp *wwapiv1.ContainerBuildParameter) (err error) { } func ContainerDelete(cdp *wwapiv1.ContainerDeleteParameter) (err error) { - if cdp == nil { return fmt.Errorf("ContainerDeleteParameter is nil") } @@ -132,7 +131,6 @@ ARG_LOOP: } func ContainerImport(cip *wwapiv1.ContainerImportParameter) (containerName string, err error) { - if cip == nil { err = fmt.Errorf("NodeAddParameter is nil") return @@ -176,6 +174,14 @@ func ContainerImport(cip *wwapiv1.ContainerImportParameter) (containerName strin // TODO: mhink - return was missing here. Was that deliberate? } + if util.IsFile(cip.Source) && !filepath.IsAbs(cip.Source) { + cip.Source, err = filepath.Abs(cip.Source) + if err != nil { + err = fmt.Errorf("when resolving absolute path of %s, err: %v", cip.Source, err) + wwlog.Error(err.Error()) + return + } + } err = container.ImportDocker(cip.Source, cip.Name, sCtx) if err != nil { err = fmt.Errorf("could not import image: %s", err.Error()) @@ -221,7 +227,7 @@ func ContainerImport(cip *wwapiv1.ContainerImportParameter) (containerName strin return } - //TODO: Don't loop through profiles, instead have a nodeDB function that goes directly to the map + // TODO: Don't loop through profiles, instead have a nodeDB function that goes directly to the map profiles, _ := nodeDB.FindAllProfiles() for _, profile := range profiles { wwlog.Debug("Looking for profile default: %s", profile.Id.Get()) @@ -332,7 +338,6 @@ func ContainerList() (containerInfo []*wwapiv1.ContainerInfo, err error) { } func ContainerShow(csp *wwapiv1.ContainerShowParameter) (response *wwapiv1.ContainerShowResponse, err error) { - containerName := csp.ContainerName if !container.ValidName(containerName) { diff --git a/internal/pkg/api/node/list.go b/internal/pkg/api/node/list.go index 330aa7b9..5001638e 100644 --- a/internal/pkg/api/node/list.go +++ b/internal/pkg/api/node/list.go @@ -29,8 +29,7 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro sort.Strings(nodeGet.Nodes) if nodeGet.Type == wwapiv1.GetNodeList_Simple { nodeList.Output = append(nodeList.Output, - fmt.Sprintf("%-22s %-26s %s", "NODE NAME", "PROFILES", "NETWORK")) - nodeList.Output = append(nodeList.Output, (strings.Repeat("=", 80))) + fmt.Sprintf("%s=%s=%s", "NODE NAME", "PROFILES", "NETWORK")) for _, n := range node.FilterByName(nodes, nodeGet.Nodes) { var netNames []string for k := range n.NetDevs { @@ -38,33 +37,31 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro } sort.Strings(netNames) 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 { nodeList.Output = append(nodeList.Output, - fmt.Sprintf("%-22s %-8s %-18s %-15s %-15s %-15s", "NODE NAME", "NAME", "HWADDR", "IPADDR", "GATEWAY", "DEVICE"), - strings.Repeat("=", 90)) + fmt.Sprintf("%s=%s=%s=%s=%s=%s", "NODE NAME", "NAME", "HWADDR", "IPADDR", "GATEWAY", "DEVICE")) for _, n := range node.FilterByName(nodes, nodeGet.Nodes) { if len(n.NetDevs) > 0 { for name := range n.NetDevs { 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].Ipaddr.Print(), n.NetDevs[name].Gateway.Print(), n.NetDevs[name].Device.Print())) } } 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 { nodeList.Output = append(nodeList.Output, - fmt.Sprintf("%-22s %-16s %-10s %-20s %-14s", "NODE NAME", "IPMI IPADDR", "IPMI PORT", "IPMI USERNAME", "IPMI INTERFACE"), - strings.Repeat("=", 98)) + fmt.Sprintf("%s=%s=%s=%s=%s", "NODE NAME", "IPMI IPADDR", "IPMI PORT", "IPMI USERNAME", "IPMI INTERFACE")) for _, n := range node.FilterByName(nodes, nodeGet.Nodes) { 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.Port.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 { nodeList.Output = append(nodeList.Output, - fmt.Sprintf("%-22s %-16s %-16s %s", "NODE NAME", "KERNEL OVERRIDE", "CONTAINER", "OVERLAYS (S/R)"), - strings.Repeat("=", 85)) + fmt.Sprintf("%s=%s=%s=%s", "NODE NAME", "KERNEL OVERRIDE", "CONTAINER", "OVERLAYS (S/R)")) for _, n := range node.FilterByName(nodes, nodeGet.Nodes) { 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.ContainerName.Print(), n.SystemOverlay.Print()+"/"+n.RuntimeOverlay.Print())) } } else if nodeGet.Type == wwapiv1.GetNodeList_All { + nodeList.Output = append(nodeList.Output, + fmt.Sprintf("%s=%s=%s=%s", "NODE", "FIELD", "PROFILE", "VALUE")) for _, n := range node.FilterByName(nodes, nodeGet.Nodes) { - nodeList.Output = append(nodeList.Output, - fmt.Sprintf("%-20s %-18s %-12s %s", "NODE", "FIELD", "PROFILE", "VALUE"), strings.Repeat("=", 85)) nType := reflect.TypeOf(n) nVal := reflect.ValueOf(n) nConfType := reflect.TypeOf(node.NodeConf{}) @@ -101,12 +97,12 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro fieldSource = entr.Source() fieldVal = entr.Print() 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{}) { entrMap := nVal.Field(i).Interface().(map[string]*node.Entry) for key, val := range entrMap { 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{}) { 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 if netConfField.Tag.Get("lopt") != "" { 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{}) { 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() fieldVal = val.Print() 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() fieldVal = entr.Print() 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{}) { for key, val := range nestInfoVal.Elem().Field(j).Interface().(map[string]*node.Entry) { fieldName = fieldName + ":" + key fieldSource = val.Source() fieldVal = val.Print() 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 } diff --git a/internal/pkg/api/profile/list.go b/internal/pkg/api/profile/list.go index 3044b3b6..a06a4c42 100644 --- a/internal/pkg/api/profile/list.go +++ b/internal/pkg/api/profile/list.go @@ -4,7 +4,6 @@ import ( "fmt" "reflect" "sort" - "strings" "github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1" "github.com/hpcng/warewulf/internal/pkg/node" @@ -34,7 +33,7 @@ func ProfileList(ShowOpt *wwapiv1.GetProfileList) (profileList wwapiv1.ProfileLi if ShowOpt.ShowAll { for _, p := range profiles { 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) nVal := reflect.ValueOf(p) nConfType := reflect.TypeOf(node.NodeConf{}) @@ -51,12 +50,12 @@ func ProfileList(ShowOpt *wwapiv1.GetProfileList) (profileList wwapiv1.ProfileLi fieldSource = entr.Source() fieldVal = entr.Print() 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{}) { entrMap := nVal.Field(i).Interface().(map[string]*node.Entry) for key, val := range entrMap { 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{}) { 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 if netConfField.Tag.Get("lopt") != "" { 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{}) { 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() fieldVal = val.Print() 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() fieldVal = entr.Print() 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{}) { for key, val := range nestInfoVal.Elem().Field(j).Interface().(map[string]*node.Entry) { fieldName = fieldName + ":" + key fieldSource = val.Source() fieldVal = val.Print() 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 { profileList.Output = append(profileList.Output, - fmt.Sprintf("%-20s %s", "PROFILE NAME", "COMMENT/DESCRIPTION")) - profileList.Output = append(profileList.Output, strings.Repeat("=", 80)) + fmt.Sprintf("%s=%s", "PROFILE NAME", "COMMENT/DESCRIPTION")) for _, profile := range profiles { 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 diff --git a/overlays/host/dnsmasq.d/ww4-hosts.conf.ww b/overlays/host/dnsmasq.d/ww4-hosts.conf.ww new file mode 100644 index 00000000..a9d6d66f --- /dev/null +++ b/overlays/host/dnsmasq.d/ww4-hosts.conf.ww @@ -0,0 +1,30 @@ +# This file was autgenerated by warewulf +# Host: {{.BuildHost}} +# Time: {{.BuildTime}} +# Source {{.BuildSource}} +{{ nobackup }} +# select the x86 hosts which will get the iXPE binary +dhcp-match=set:x86PC,option:client-arch, 7 #EFI x86-64 +dhcp-match=set:x86PC,option:client-arch, 6 #EFI x86-64 +dhcp-match=set:x86PC,option:client-arch, 9 #EFI x86-64 +{{ with (index $.Tftp.IpxeBinaries "00:07" ) }}dhcp-boot=tag:x86PC,"/warewulf/{{ index $.Tftp.IpxeBinaries "00:07" }}"{{ end }} +dhcp-no-override +# iPXE binary will get the following configuration file +dhcp-userclass=set:iPXE,iPXE +dhcp-boot=tag:iPXE,"http://{{$.Ipaddr}}:{{$.Warewulf.Port}}/ipxe/${mac:hexhyp}" +{{- if $.Tftp.Enabled }} +# also act as tftp server +tftp-root={{ $.Tftp.TftpRoot }} +{{- end }} +# define the the range +dhcp-range={{$.Dhcp.RangeStart}},{{$.Dhcp.RangeEnd}},{{$.Netmask}},6h +{{/* Add all the known hosts */}} +{{- range $node := $.AllNodes}} {{/* for each node */}} +{{- range $devname, $netdev := $node.NetDevs}} {{/* for each network device on the node */}} +{{- if $netdev.Ipaddr.Defined}} {{/* if we have an ip address on this network device */}} +{{- if $netdev.Hwaddr.Defined }} +dhcp-host={{$netdev.Hwaddr.Get}},set:warewulf,{{$node.Id.Get}},{{$netdev.Ipaddr.Get}},infinite +{{- end}} {{/* end if Hwaddr */}} +{{- end}} {{/* end if ip */}} +{{- end}} {{/* end for each network device */}} +{{- end}} {{/* end for each node */}} diff --git a/userdocs/contents/dnsmasq.rst b/userdocs/contents/dnsmasq.rst new file mode 100644 index 00000000..e1b97486 --- /dev/null +++ b/userdocs/contents/dnsmasq.rst @@ -0,0 +1,17 @@ +======= +Dnsmasq +======= + +Usage +===== + +As experimental feature its possible to use `dnsmasq` instead of the ISC `dhcpd` server in combination +with a `tFTP` server. The `dnsmasq` service is then acting as `dhcp` and `tftp` server. In order to keep +the file `/etc/dnsmasq.d/ww4-hosts.conf` is created and must be included in the main `dnsmasq.conf` via +the `conf-dir=/etc/dnsmasq.d` option. + +Addionally in the configuration file `warewulf.conf` in the sections `dhcp` and `tftp` the systemd name of +dnsmasq must set for the option `systemd name`. + +After this configuration steps its recommended to rebuild the host overlay with `wwctl overlay build -H` and +the the services should be configured with `wwctl configure -a`.