Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

[Do Not Merge] Add full support for provisioning with 2 nics #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
14 changes: 10 additions & 4 deletions prepare-image.pl
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,30 @@
}
elsif ($distro =~ m/^(fedora|rhel|redhat-based|centos|scientificlinux)$/) {
print "Setting up for Fedora / RHEL\n";
$file = "/etc/sysconfig/network-scripts/ifcfg-eth0";
$file = "/etc/sysconfig/network-scripts/ifcfg-eth1";
if ($ENV{STATIC_IPADDR}) {
print "Setting static network configuration\n";
$content = "DEVICE=eth0\n";
$content = "DEVICE=eth1\n";
$content .= "ONBOOT=yes\n";
$content .= "BOOTPROTO=static\n";
$content .= "NM_CONTROLLED=no\n";
$content .= "HWADDR=$ENV{MAC}\n";
$content .= "HWADDR=$ENV{MAC2}\n";
$content .= "IPADDR=$ENV{STATIC_IPADDR}\n";
$content .= "NETMASK=$ENV{STATIC_NETMASK}\n";
$content .= "GATEWAY=$ENV{STATIC_GATEWAY}\n";
} else {
print "Setting MAC address\n";
$content = $g->read_file ($file);
$content =~ s/HWADDR=.*/HWADDR=$ENV{MAC}/g;
$content =~ s/HWADDR=.*/HWADDR=$ENV{MAC2}/g;
}
$g->write ($file, $content);

print "Configuring /etc/sysconfig/network-scripts/ifcfg-eth0 file\n";
$file = "/etc/sysconfig/network-scripts/ifcfg-eth0";
$content = $g->read_file ($file);
$content =~ s/HWADDR=.*/HWADDR=$ENV{MAC1}/g;
$g->write ($file, $content);

print "Setting hostname\n";
if ($major >= 18 || ($distro eq "rhel" || $distro eq "centos") && $major >= 7) {
$g->write ("/etc/hostname", $ENV{TARGET_HOSTNAME});
Expand Down
14 changes: 8 additions & 6 deletions snap-guest
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ done
SOURCE_IMG=$(ls -v1 $BASE_IMAGE_DIR/${SOURCE_NAME}*.img | tail -n1)
TARGET_IMG=$IMAGE_DIR/$TARGET_NAME.img
TARGET_IMG_SWAP=$IMAGE_DIR/$TARGET_NAME-swap.img
MAC="52:54:00$(echo "$(hostname)$TARGET_NAME" | openssl dgst -md5 -binary | hexdump -e '/1 ":%02x"' -n 3)"
MAC1="52:54:00$(echo "$(hostname)$TARGET_NAME" | openssl dgst -md5 -binary | hexdump -e '/1 ":%02x"' -n 3)"
MAC2="52:54:00$(echo "$(hostname)$TARGET_IMG" | openssl dgst -md5 -binary | hexdump -e '/1 ":%02x"' -n 3)"
TARGET_HOSTNAME=$TARGET_HOSTNAME
if [ -z "$TARGET_HOSTNAME" ]; then
TARGET_HOSTNAME="$PREFIX$TARGET_NAME$DOMAIN"
Expand Down Expand Up @@ -226,7 +227,7 @@ qemu-img create -f qcow2 -b $SOURCE_IMG $TARGET_IMG
# -- Image Manipulation ----------

if [ $CLOUD -eq 0 -o $CLOUD_PRECONF -eq 1 ]; then
export COMMAND TARGET_HOSTNAME MAC SOURCE_NAME SWAP TARGET_IMG TARGET_NAME \
export COMMAND TARGET_HOSTNAME MAC1 MAC2 SOURCE_NAME SWAP TARGET_IMG TARGET_NAME \
STATIC_IPADDR STATIC_NETMASK STATIC_GATEWAY
perl -w "$SCRIPTDIR/prepare-image.pl"
fi
Expand Down Expand Up @@ -287,15 +288,16 @@ echo "Hostname: $TARGET_HOSTNAME"
echo "CPUs: $CPUS"
echo "Memory: $MEM MB"
echo "Swap: $MEM MB"
echo "MAC: $MAC"
echo "MAC1: $MAC1"
echo "MAC2: $MAC2"
virt-install --vcpus $CPUS \
--ram $MEM --import \
--name $TARGET_NAME \
--disk $TARGET_IMG,device=disk,bus=virtio,format=qcow2 $DISK_SWAP $DISK_SEED \
--graphics "$GRAPHICS_OPTS" \
--noautoconsole --force \
--network=$NETWORK,mac=$MAC \
$NETWORK2 \
--network=$NETWORK,mac=$MAC1,model="virtio" \
"$NETWORK2,mac=$MAC2,model=virtio" \
$CPU_FEATURE

# -- IP Determining -------------
Expand All @@ -304,7 +306,7 @@ virt-install --vcpus $CPUS \
if [ $ADD_IP -eq 1 ]; then
echo "Waiting for IP"
i=0
until [ $i -ge 100 ] || IP_LINE=`cat /var/lib/libvirt/dnsmasq/${NETWORK/network=}.leases /var/lib/dnsmasq/dnsmasq.leases 2>/dev/null | grep "$MAC"`; do
until [ $i -ge 100 ] || IP_LINE=`cat /var/lib/libvirt/dnsmasq/${NETWORK/network=}.leases /var/lib/dnsmasq/dnsmasq.leases 2>/dev/null | grep "$MAC1"`; do
i=$((i + 1))
sleep 1
done
Expand Down