diff --git a/config/samples/network-template-secret.yaml b/config/samples/network-template-secret.yaml index f8b04c3..0d620a7 100644 --- a/config/samples/network-template-secret.yaml +++ b/config/samples/network-template-secret.yaml @@ -14,6 +14,7 @@ stringData: template: | {{ $netToIface := dict }} {{ $netToIp := dict }} + {{ $netToNetmask := dict }} links: {{- range .BuilderDomain.Interfaces }} - id: {{ .Name }} @@ -29,6 +30,7 @@ stringData: {{- /* Save the network->interface mapping, needed below */ -}} {{- $_ := set $netToIface .NetworkName .Name }} {{- $_ := set $netToIp .NetworkName .IPAddress }} + {{- $_ := set $netToNetmask .NetworkName .NetMask }} {{- end }} networks: {{- range .Networks }} @@ -36,7 +38,7 @@ stringData: type: {{ .Type }} link: {{ index $netToIface .Name }} ip_address: {{ index $netToIp .Name }} - #netmask: "TODO - see if needed when ip has CIDR range" + netmask: {{ index $netToNetmask .Name }} dns_nameservers: {{ .DNSServers }} {{- if .Routes }} routes: diff --git a/docs/api/vino.md b/docs/api/vino.md index 1f48a5c..cb441f7 100644 --- a/docs/api/vino.md +++ b/docs/api/vino.md @@ -287,6 +287,16 @@ string +netMask
+ +string + + + + + + + macAddress
string diff --git a/pkg/api/v1/vino_builder.go b/pkg/api/v1/vino_builder.go index 2aff3e9..49d9871 100644 --- a/pkg/api/v1/vino_builder.go +++ b/pkg/api/v1/vino_builder.go @@ -31,6 +31,7 @@ type Builder struct { type BuilderNetworkInterface struct { IPAddress string `json:"ipAddress,omitempty"` + NetMask string `json:"netMask,omitempty"` MACAddress string `json:"macAddress,omitempty"` NetworkInterface `json:",inline"` } diff --git a/pkg/managers/bmh.go b/pkg/managers/bmh.go index bc0ccc5..7d67dd3 100644 --- a/pkg/managers/bmh.go +++ b/pkg/managers/bmh.go @@ -18,6 +18,7 @@ import ( "bytes" "context" "fmt" + "net" "text/template" "time" @@ -322,10 +323,15 @@ func (r *BMHManager) domainSpecificNetValues( if err != nil { return networkTemplateValues{}, err } + netmask, err := convertNetmask(subnet) + if err != nil { + return networkTemplateValues{}, err + } domainInterfaces = append(domainInterfaces, vinov1.BuilderNetworkInterface{ IPAddress: ipAddress, MACAddress: macAddress, NetworkInterface: iface, + NetMask: netmask, }) r.Logger.Info("Got MAC and IP for the network and node", @@ -507,3 +513,17 @@ func applyRuntimeObject(ctx context.Context, key client.ObjectKey, obj client.Ob } return err } + +func convertNetmask(subnet string) (string, error) { + _, network, err := net.ParseCIDR(subnet) + if err != nil { + return "", err + } + + m := network.Mask + if len(m) != 4 { + return "", fmt.Errorf("Couldn't parse netmask for subnet %s", subnet) + } + + return fmt.Sprintf("%d.%d.%d.%d", m[0], m[1], m[2], m[3]), nil +}