Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set network interface name with cloud-init set-name #838

Merged
merged 3 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ type NetworkDeviceSpec struct {
// will be connected.
NetworkName string `json:"networkName"`

// DeviceName may be used to explicitly assign a name to the network device
// as it exists in the guest operating system.
// +optional
DeviceName string `json:"deviceName,omitempty"`

// DHCP4 is a flag that indicates whether or not to use DHCP for IPv4
// on this device.
// If true then IPAddrs should not contain any IPv4 addresses.
Expand Down
20 changes: 18 additions & 2 deletions api/v1alpha2/vspheremachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ func Convert_v1alpha2_VSphereMachineSpec_To_v1alpha3_VSphereMachineSpec(in *VSph
if err := autoConvert_v1alpha2_VSphereMachineSpec_To_v1alpha3_VSphereMachineSpec(in, out, s); err != nil {
return err
}

out.Template = in.Template
out.Datacenter = in.Datacenter
if err := autoConvert_v1alpha2_NetworkSpec_To_v1alpha3_NetworkSpec(&in.Network, &out.Network, s); err != nil {
return err
}
out.NumCPUs = in.NumCPUs
out.NumCoresPerSocket = in.NumCoresPerSocket
out.MemoryMiB = in.MemoryMiB
out.DiskGiB = in.DiskGiB
return nil
}

Expand All @@ -82,7 +90,15 @@ func Convert_v1alpha3_VSphereMachineSpec_To_v1alpha2_VSphereMachineSpec(in *infr
if err := autoConvert_v1alpha3_VSphereMachineSpec_To_v1alpha2_VSphereMachineSpec(in, out, s); err != nil {
return err
}

out.Template = in.Template
out.Datacenter = in.Datacenter
if err := autoConvert_v1alpha3_NetworkSpec_To_v1alpha2_NetworkSpec(&in.Network, &out.Network, s); err != nil {
return err
}
out.NumCPUs = in.NumCPUs
out.NumCoresPerSocket = in.NumCoresPerSocket
out.MemoryMiB = in.MemoryMiB
out.DiskGiB = in.DiskGiB
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions api/v1alpha3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ type NetworkDeviceSpec struct {
// will be connected.
NetworkName string `json:"networkName"`

// DeviceName may be used to explicitly assign a name to the network device
// as it exists in the guest operating system.
// +optional
DeviceName string `json:"deviceName,omitempty"`

// DHCP4 is a flag that indicates whether or not to use DHCP for IPv4
// on this device.
// If true then IPAddrs should not contain any IPv4 addresses.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ spec:
description: NetworkDeviceSpec defines the network configuration
for a virtual machine's network device.
properties:
deviceName:
description: DeviceName may be used to explicitly assign
a name to the network device as it exists in the guest
operating system.
type: string
dhcp4:
description: DHCP4 is a flag that indicates whether
or not to use DHCP for IPv4 on this device. If true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ spec:
description: NetworkDeviceSpec defines the network configuration
for a virtual machine's network device.
properties:
deviceName:
description: DeviceName may be used to explicitly assign
a name to the network device as it exists in the guest
operating system.
type: string
dhcp4:
description: DHCP4 is a flag that indicates whether or not
to use DHCP for IPv4 on this device. If true then IPAddrs
Expand Down Expand Up @@ -358,6 +363,11 @@ spec:
description: NetworkDeviceSpec defines the network configuration
for a virtual machine's network device.
properties:
deviceName:
description: DeviceName may be used to explicitly assign
a name to the network device as it exists in the guest
operating system.
type: string
dhcp4:
description: DHCP4 is a flag that indicates whether or not
to use DHCP for IPv4 on this device. If true then IPAddrs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ spec:
description: NetworkDeviceSpec defines the network configuration
for a virtual machine's network device.
properties:
deviceName:
description: DeviceName may be used to explicitly
assign a name to the network device as it exists
in the guest operating system.
type: string
dhcp4:
description: DHCP4 is a flag that indicates whether
or not to use DHCP for IPv4 on this device. If
Expand Down Expand Up @@ -412,6 +417,11 @@ spec:
description: NetworkDeviceSpec defines the network configuration
for a virtual machine's network device.
properties:
deviceName:
description: DeviceName may be used to explicitly
assign a name to the network device as it exists
in the guest operating system.
type: string
dhcp4:
description: DHCP4 is a flag that indicates whether
or not to use DHCP for IPv4 on this device. If
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ spec:
description: NetworkDeviceSpec defines the network configuration
for a virtual machine's network device.
properties:
deviceName:
description: DeviceName may be used to explicitly assign
a name to the network device as it exists in the guest
operating system.
type: string
dhcp4:
description: DHCP4 is a flag that indicates whether or not
to use DHCP for IPv4 on this device. If true then IPAddrs
Expand Down
5 changes: 5 additions & 0 deletions pkg/util/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ network:
id{{ $i }}:
match:
macaddress: "{{ $net.MACAddr }}"
{{- if $net.DeviceName }}
set-name: "{{ $net.DeviceName }}"
{{- else }}
set-name: "eth{{ $i }}"
{{- end }}
wakeonlan: true
dhcp4: {{ $net.DHCP4 }}
dhcp6: {{ $net.DHCP6 }}
Expand Down
42 changes: 42 additions & 0 deletions pkg/util/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,40 @@ network:
id0:
match:
macaddress: "00:00:00:00:00"
set-name: "eth0"
wakeonlan: true
dhcp4: true
dhcp6: false
`,
},
{
name: "dhcp4+deviceName",
machine: &v1alpha3.VSphereVM{
Spec: v1alpha3.VSphereVMSpec{
VirtualMachineCloneSpec: v1alpha3.VirtualMachineCloneSpec{
Network: v1alpha3.NetworkSpec{
Devices: []v1alpha3.NetworkDeviceSpec{
{
NetworkName: "network1",
MACAddr: "00:00:00:00:00",
DHCP4: true,
DeviceName: "ens192",
},
},
},
},
},
},
expected: `
instance-id: "test-vm"
local-hostname: "test-vm"
network:
version: 2
ethernets:
id0:
match:
macaddress: "00:00:00:00:00"
set-name: "ens192"
wakeonlan: true
dhcp4: true
dhcp6: false
Expand Down Expand Up @@ -289,6 +323,7 @@ network:
id0:
match:
macaddress: "00:00:00:00:00"
set-name: "eth0"
wakeonlan: true
dhcp4: false
dhcp6: true
Expand Down Expand Up @@ -321,6 +356,7 @@ network:
id0:
match:
macaddress: "00:00:00:00:00"
set-name: "eth0"
wakeonlan: true
dhcp4: true
dhcp6: true
Expand Down Expand Up @@ -354,6 +390,7 @@ network:
id0:
match:
macaddress: "00:00:00:00:00"
set-name: "eth0"
wakeonlan: true
dhcp4: false
dhcp6: true
Expand Down Expand Up @@ -397,6 +434,7 @@ network:
id0:
match:
macaddress: "00:00:00:00:00"
set-name: "eth0"
wakeonlan: true
dhcp4: false
dhcp6: true
Expand Down Expand Up @@ -448,6 +486,7 @@ network:
id0:
match:
macaddress: "00:00:00:00:00"
set-name: "eth0"
wakeonlan: true
dhcp4: true
dhcp6: false
Expand All @@ -458,6 +497,7 @@ network:
id1:
match:
macaddress: "00:00:00:00:01"
set-name: "eth1"
wakeonlan: true
dhcp4: false
dhcp6: true
Expand Down Expand Up @@ -500,6 +540,7 @@ network:
id0:
match:
macaddress: "00:00:00:00:00"
set-name: "eth0"
wakeonlan: true
dhcp4: false
dhcp6: false
Expand All @@ -514,6 +555,7 @@ network:
id1:
match:
macaddress: "00:00:00:00:01"
set-name: "eth1"
wakeonlan: true
dhcp4: false
dhcp6: true
Expand Down