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

Support old ubuntu netplan #1031

Merged
merged 6 commits into from
Sep 12, 2024
Merged
Changes from 1 commit
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
48 changes: 47 additions & 1 deletion virt-v2v/pkg/customize/scripts/rhel/run/network_config_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,42 @@ extract_mac_ip() {
fi
}

netplan_get_py() {
python -c "
import os
import yaml
import sys

netplan_dir = os.getenv('NETPLAN_DIR', '') + '/etc/netplan'
args = sys.argv[1].split('.')
mnecas marked this conversation as resolved.
Show resolved Hide resolved

def find_yaml_files(directory):
yaml_files = []
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(('.yaml', '.yml')):
yaml_files.append(os.path.join(root, file))

return yaml_files

def get_yaml_path(yaml_data, keys):
for key in keys:
if yaml_data is None:
return None
yaml_data = yaml_data.get(key)
return yaml_data

yaml_files = find_yaml_files(netplan_dir)

for yaml_file in yaml_files:
with open(yaml_file, 'r') as file:
yaml_data = yaml.safe_load(file)
result = get_yaml_path(yaml_data, ['network'] + args)
if result is not None:
print(yaml.dump(result, default_flow_style=False))
mnecas marked this conversation as resolved.
Show resolved Hide resolved
" "$@"
}

# Network infrastructure reading functions
# ----------------------------------------

Expand Down Expand Up @@ -133,9 +169,19 @@ udev_from_netplan() {
return 0
fi

# Function to check if netplan supports the 'get' subcommand
netplan_supports_get() {
netplan get 2>/dev/null
mnecas marked this conversation as resolved.
Show resolved Hide resolved
return $?
}

# netplan with root dir
netplan_get() {
netplan get --root-dir "$NETPLAN_DIR" "$@" 2>/dev/null
if netplan_supports_get; then
netplan get --root-dir "$NETPLAN_DIR" "$@" 2>/dev/null
mnecas marked this conversation as resolved.
Show resolved Hide resolved
else
netplan_get_py "$@" 2>/dev/null
fi
}

# Loop over all interface names and treturn the one with target_ip, or null
Expand Down
Loading