Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:ff",NAME="eth0"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:fe",NAME="eth1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
aa:bb:cc:dd:ee:ff:ip:192.168.122.82,things,more
aa:bb:cc:dd:ee:fe:ip:192.168.122.83,hello,world
aa:bb:cc:dd:ee:fd:ip:2001:0db8:85a3:0000:0000:8a2e:0370:7334
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<lease>
<family>ipv4</family>
<type>dhcp</type>
<state>granted</state>
<ipv4:dhcp>
<address>192.168.122.82</address>
</ipv4:dhcp>
</lease>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<lease>
<family>ipv4</family>
<type>dhcp</type>
<state>granted</state>
<ipv4:dhcp>
<address>192.168.122.83</address>
</ipv4:dhcp>
</lease>
43 changes: 43 additions & 0 deletions pkg/virt-v2v/customize/scripts/rhel/run/network_config_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
NETWORK_INTERFACES_DIR="${NETWORK_INTERFACES_DIR:-/etc/network/interfaces}"
IFQUERY_CMD="${IFQUERY_CMD:-ifquery}"
SYSTEMD_NETWORK_DIR="${SYSTEMD_NETWORK_DIR:-/run/systemd/network}"
WICKED_DIR="${WICKED_DIR:-/var/lib/wicked}"
UDEV_RULES_FILE="${UDEV_RULES_FILE:-/etc/udev/rules.d/70-persistent-net.rules}"
NETPLAN_DIR="${NETPLAN_DIR:-/}"

Expand Down Expand Up @@ -78,6 +79,47 @@
echo ""
}

# Create udev rules based on the macToIP mapping + SUSE wicked DHCP leases.
# Wicked stores lease files as XML in /var/lib/wicked/ with filenames like
# lease-<interface>-dhcp-ipv4.xml, where the interface name is the second
# dash-delimited field of the filename.
udev_from_wicked() {
# Check if the SUSE wicked dir exist
if [ ! -d "$WICKED_DIR" ]; then

Check failure on line 88 in pkg/virt-v2v/customize/scripts/rhel/run/network_config_util.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=kubev2v_forklift&issues=AZ1CPD-0y7ka4KSVzjco&open=AZ1CPD-0y7ka4KSVzjco&pullRequest=5675
log "Warning: Directory $WICKED_DIR does not exist."
return 0
fi

# Read the mapping file line by line
cat "$V2V_MAP_FILE" | while read -r line;
do
# Extract S_HW and S_IP
extract_mac_ip "$line"

# If S_HW and S_IP were not extracted, skip the line
if [ -z "$S_HW" ] || [ -z "$S_IP" ]; then

Check failure on line 100 in pkg/virt-v2v/customize/scripts/rhel/run/network_config_util.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=kubev2v_forklift&issues=AZ1CPD-0y7ka4KSVzjcp&open=AZ1CPD-0y7ka4KSVzjcp&pullRequest=5675

Check failure on line 100 in pkg/virt-v2v/customize/scripts/rhel/run/network_config_util.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=kubev2v_forklift&issues=AZ1CPD-0y7ka4KSVzjcq&open=AZ1CPD-0y7ka4KSVzjcq&pullRequest=5675
log "Warning: invalid mac to ip line: $line."
continue
fi

# Find the matching wicked connection file
WICKED_FILE=$(grep -El "<address>$S_IP</address>" "$WICKED_DIR"/*)
if [ -z "$WICKED_FILE" ]; then

Check failure on line 107 in pkg/virt-v2v/customize/scripts/rhel/run/network_config_util.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=kubev2v_forklift&issues=AZ1CPD-0y7ka4KSVzjcr&open=AZ1CPD-0y7ka4KSVzjcr&pullRequest=5675
log "Info: no wicked file name found for $S_IP."
continue
fi

# Extract the DEVICE (interface name) from the matching file
DEVICE=$(basename "$WICKED_FILE" | cut -d'-' -f2)
if [ -z "$DEVICE" ]; then

Check failure on line 114 in pkg/virt-v2v/customize/scripts/rhel/run/network_config_util.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=kubev2v_forklift&issues=AZ1CPD-0y7ka4KSVzjcs&open=AZ1CPD-0y7ka4KSVzjcs&pullRequest=5675
log "Info: no interface name found to $S_IP."
continue
fi

echo "SUBSYSTEM==\"net\",ACTION==\"add\",ATTR{address}==\"$(remove_quotes "$S_HW")\",NAME=\"$(remove_quotes "$DEVICE")\""
done
}

# Create udev rules based on the macToip mapping + ifcfg network scripts
# Supports both RHEL (/etc/sysconfig/network-scripts/) and SUSE (/etc/sysconfig/network/)
# Automatically detects which path exists and uses it (RHEL path takes precedence)
Expand Down Expand Up @@ -502,6 +544,7 @@
udev_from_dhclient_lease
udev_from_netplan
udev_from_ifquery
udev_from_wicked
} | check_dupe_hws > "$UDEV_RULES_FILE" 2>/dev/null
echo "New udev rule:"
cat $UDEV_RULES_FILE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ test_dir() {
export NETPLAN_DIR="$TEST_DIR/"
export NM_LEASES_DIR="$TEST_DIR/var/lib/NetworkManager"
export DHCLIENT_LEASES_DIR="$TEST_DIR/var/lib/dhclient"
export WICKED_DIR="$TEST_DIR/var/lib/wicked"

export IFQUERY_CMD="
podman run
Expand Down
Loading