diff --git a/Makefile b/Makefile index 8dc3acba..de81edb9 100644 --- a/Makefile +++ b/Makefile @@ -48,10 +48,7 @@ files: all install -d -m 0755 /etc/warewulf/ install -d -m 0755 /etc/warewulf/ipxe install -d -m 0755 /var/lib/tftpboot/warewulf/ipxe/ - install -m 0640 etc/dhcpd.conf /etc/dhcp/dhcpd.conf - install -m 0644 etc/nodes.conf /etc/warewulf/nodes.conf - install -m 0644 etc/warewulf.conf /etc/warewulf/warewulf.conf - install -m 0644 etc/ipxe/default.ipxe /etc/warewulf/ipxe/default.ipxe + cp -r etc* /etc/warewulf/ cp -r tftpboot/* /var/lib/tftpboot/warewulf/ipxe/ restorecon -r /var/lib/tftpboot/warewulf cp -r overlays /var/warewulf/ diff --git a/etc/dhcp/default-dhcpd.conf b/etc/dhcp/default-dhcpd.conf index 17ae45f9..d9991aca 100644 --- a/etc/dhcp/default-dhcpd.conf +++ b/etc/dhcp/default-dhcpd.conf @@ -33,8 +33,8 @@ if exists user-class and option user-class = "iPXE" { } } -subnet {{.Ipaddr}} netmask {{.Netmask}} { - range {{.RangeStart}} {{.RangeEnd}}; +subnet {{$.Network}} netmask {{$.Netmask}} { + range {{$.RangeStart}} {{$.RangeEnd}}; next-server 192.168.1.1; } diff --git a/etc/dhcp/static-dhcpd.conf b/etc/dhcp/static-dhcpd.conf index 5056f064..fb3f18d3 100644 --- a/etc/dhcp/static-dhcpd.conf +++ b/etc/dhcp/static-dhcpd.conf @@ -34,9 +34,9 @@ if exists user-class and option user-class = "iPXE" { } -{{range .Nodes}} -host {{.Fqdn}} { - hardware ethernet {{.NetDevs.eth0.Hwaddr}} - filed-address {{.NetDevs.eth0.Ipaddr}} +{{- range $nodes := .Nodes}} +host {{$.Fqdn}} { + hardware ethernet {{$nodes.NetDevs.eth0.Hwaddr}} + filed-address {{$nodes.NetDevs.eth0.Ipaddr}} } {{end}} diff --git a/go.mod b/go.mod index 0d3971b1..2ca950f4 100644 --- a/go.mod +++ b/go.mod @@ -3,56 +3,57 @@ module github.com/hpcng/warewulf go 1.15 require ( - github.com/BurntSushi/toml v0.3.1 - github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 - github.com/beorn7/perks v1.0.1 - github.com/containerd/containerd v1.3.2 + github.com/BurntSushi/toml v0.3.1 // indirect + github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 // indirect + github.com/beorn7/perks v1.0.1 // indirect + github.com/brotherpowers/ipsubnet v0.0.0-20170914094241-30bc98f0a5b1 + github.com/containerd/containerd v1.3.2 // indirect github.com/containers/image/v5 v5.7.0 - github.com/containers/libtrust v0.0.0-20190913040956-14b96171aa3b - github.com/containers/ocicrypt v1.0.3 - github.com/containers/storage v1.23.6 - github.com/docker/distribution v2.7.1+incompatible - github.com/docker/docker v1.4.2-0.20191219165747-a9416c67da9f - github.com/docker/docker-credential-helpers v0.6.3 - github.com/docker/go-connections v0.4.0 - github.com/docker/go-metrics v0.0.1 - github.com/docker/go-units v0.4.0 - github.com/ghodss/yaml v1.0.0 - github.com/gogo/protobuf v1.3.1 - github.com/golang/protobuf v1.4.2 - github.com/gorilla/mux v1.7.4 - github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a - github.com/fatih/color v1.9.0 + github.com/containers/libtrust v0.0.0-20190913040956-14b96171aa3b // indirect + github.com/containers/ocicrypt v1.0.3 // indirect + github.com/containers/storage v1.23.6 // indirect + github.com/docker/distribution v2.7.1+incompatible // indirect + github.com/docker/docker v1.4.2-0.20191219165747-a9416c67da9f // indirect + github.com/docker/docker-credential-helpers v0.6.3 // indirect + github.com/docker/go-connections v0.4.0 // indirect + github.com/docker/go-metrics v0.0.1 // indirect + github.com/docker/go-units v0.4.0 // indirect + github.com/fatih/color v1.9.0 // indirect + github.com/ghodss/yaml v1.0.0 // indirect + github.com/gogo/protobuf v1.3.1 // indirect + github.com/golang/protobuf v1.4.2 // indirect + github.com/gorilla/mux v1.7.4 // indirect + github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a // indirect github.com/kelseyhightower/envconfig v1.4.0 - github.com/klauspost/compress v1.11.1 - github.com/klauspost/pgzip v1.2.5 - github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a + github.com/klauspost/compress v1.11.1 // indirect + github.com/klauspost/pgzip v1.2.5 // indirect + github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a // indirect github.com/manifoldco/promptui v0.8.0 - github.com/mattn/go-colorable v0.1.6 - github.com/mattn/go-isatty v0.0.12 - github.com/matttproud/golang_protobuf_extensions v1.0.1 - github.com/mtrmac/gpgme v0.1.2 - github.com/opencontainers/go-digest v1.0.0 + github.com/mattn/go-colorable v0.1.6 // indirect + github.com/mattn/go-isatty v0.0.12 // indirect + github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect + github.com/mtrmac/gpgme v0.1.2 // indirect + github.com/opencontainers/go-digest v1.0.0 // indirect 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 - github.com/prometheus/client_golang v1.1.0 - github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 - github.com/prometheus/common v0.6.0 - github.com/prometheus/procfs v0.0.3 - github.com/russross/blackfriday/v2 v2.0.1 - github.com/sirupsen/logrus v1.7.0 + github.com/pkg/errors v0.9.1 // indirect + github.com/prometheus/client_golang v1.1.0 // indirect + github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 // indirect + github.com/prometheus/common v0.6.0 // indirect + github.com/prometheus/procfs v0.0.3 // indirect + github.com/russross/blackfriday/v2 v2.0.1 // indirect + github.com/sirupsen/logrus v1.7.0 // indirect github.com/spf13/cobra v1.1.1 - github.com/ulikunitz/xz v0.5.8 - github.com/vbauerster/mpb/v5 v5.3.0 - go.etcd.io/bbolt v1.3.5 - golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 - golang.org/x/net v0.0.0-20200602114024-627f9648deb9 - golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a - golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 - google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 - google.golang.org/grpc v1.27.0 - google.golang.org/protobuf v1.24.0 - gopkg.in/square/go-jose.v2 v2.3.1 + github.com/ulikunitz/xz v0.5.8 // indirect + github.com/vbauerster/mpb/v5 v5.3.0 // indirect + go.etcd.io/bbolt v1.3.5 // indirect + golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 // indirect + golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect + golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a // indirect + golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 // indirect + google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect + google.golang.org/grpc v1.27.0 // indirect + google.golang.org/protobuf v1.24.0 // indirect + gopkg.in/square/go-jose.v2 v2.3.1 // indirect gopkg.in/yaml.v2 v2.3.0 ) diff --git a/go.sum b/go.sum index 1927134b..e6347ff9 100644 --- a/go.sum +++ b/go.sum @@ -43,6 +43,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= +github.com/brotherpowers/ipsubnet v0.0.0-20170914094241-30bc98f0a5b1 h1:80OMQcGycPqKFFabSaxOagCh7mgspnMl/X3YGmNi+j0= +github.com/brotherpowers/ipsubnet v0.0.0-20170914094241-30bc98f0a5b1/go.mod h1:mm9ZF6W76SwZtJpYzrVmTMuzmIhPX0SIuEosW/OTFd4= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/checkpoint-restore/go-criu/v4 v4.0.2/go.mod h1:xUQBLp4RLc5zJtWY++yjOoMoB5lihDt7fai+75m+rGw= diff --git a/internal/app/wwctl/service/dhcp/main.go b/internal/app/wwctl/service/dhcp/main.go index 2d950561..02dbb841 100644 --- a/internal/app/wwctl/service/dhcp/main.go +++ b/internal/app/wwctl/service/dhcp/main.go @@ -2,6 +2,7 @@ package dhcp import ( "fmt" + "github.com/brotherpowers/ipsubnet" "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" @@ -16,6 +17,7 @@ type dhcpTemplate struct { Ipaddr string RangeStart string RangeEnd string + Network string Netmask string Nodes []node.NodeInfo } @@ -49,9 +51,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error { for _, address := range addrs { if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { if ipnet.IP.String() == controller.Ipaddr { - mask := ipnet.IP.DefaultMask() + m, _ := ipnet.Mask.Size() + sub := ipsubnet.SubnetCalculator(ipnet.IP.String(), m) + d.Ipaddr = ipnet.IP.String() - d.Netmask = fmt.Sprintf("%d.%d.%d.%d", mask[0], mask[1], mask[2], mask[3]) + d.Network = sub.GetNetworkPortion() + d.Netmask = sub.GetSubnetMask() d.RangeStart = controller.Services.Dhcp.RangeStart d.RangeEnd = controller.Services.Dhcp.RangeEnd configured = true