Add netmask to ip addresses
Change-Id: I067d93360c4384fc0b02234e75c311d105ea7b69
This commit is contained in:
parent
0e709c0d27
commit
7737926909
@ -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:
|
||||
|
@ -287,6 +287,16 @@ string
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<code>netMask</code><br>
|
||||
<em>
|
||||
string
|
||||
</em>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<code>macAddress</code><br>
|
||||
<em>
|
||||
string
|
||||
|
@ -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"`
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user