Browse Source

initial version of create-cumulus-vx-image.sh

master
Sebastian Rieger 9 years ago
parent
commit
ca95830725
  1. 81
      create-cumulusvx-image/create-cumulus-vx-image.sh
  2. 21
      create-cumulusvx-image/dynamic-subtype-CumulusVX.json
  3. 5
      create-cumulusvx-image/minimal-config-CumulusVX.txt

81
create-cumulusvx-image/create-cumulus-vx-image.sh

@ -0,0 +1,81 @@
#!/bin/bash
# create-cumulus-vx-image.sh V0.1
# HS-Fulda - sebastian.rieger@informatik.hs-fulda.de
# usage
if [ ! $# -eq 2 ] ; then
echo -e "usage: $0 <CumulusVX.qcow2> <new glance image name>, e.g.:\n"
echo "$0 CumulusVX-2.5.3-f3df86c478e1a4ef.qcow2 CumulusVX"
exit -1
fi
# sudo check
if [ ! $UID -eq 0 ] ; then
echo "Insufficient privileges. Please consider using sudo -s."
exit -1
fi
CUMULUS_QCOW2=$1
CUMULUS_QCOW2_BASENAME=$(basename -s .qcow2 $1)
CUMULUS_PATCHED_QCOW2=$1-patched.qcow2
GLANCE_IMAGE_NAME=$2
GLANCE_IMAGE_RELEASE=$CUMULUS_QCOW2_BASENAME
TMP_NAME="CumulusVX-$GLANCE_IMAGE_RELEASE"
TIMESTAMP=$(date +%Y%m%d%H%M%S)
echo
echo "Creating CumulusVX image..."
echo "==========================================================="
qemu-img convert -O raw $CUMULUS_QCOW2 $CUMULUS_QCOW2_BASENAME.raw
LOOPDEV=$(kpartx -av $CUMULUS_QCOW2_BASENAME.raw)
LOOPDEV_PART1=$(echo "$LOOPDEV" | sed '1q;d' | cut -d " " -f 3)
LOOPDEV_PART2=$(echo "$LOOPDEV" | sed '2q;d' | cut -d " " -f 3)
mkdir cumulusvx-boot-$TIMESTAMP
mkdir cumulusvx-root-$TIMESTAMP
echo
echo "Injecting changes to use serial console and startup script to get switch config..."
echo "=================================================================================="
mount /dev/mapper/$LOOPDEV_PART1 cumulusvx-boot-$TIMESTAMP
mount /dev/mapper/$LOOPDEV_PART2 cumulusvx-root-$TIMESTAMP
# changing grub and inittab to use a serial console on kernel command line
sed -i.bak -e s/"linux \/bzImage root=\/dev\/sda2"/"linux \/bzImage root=\/dev\/sda2 console=ttyS0 console=tty0"/g cumulusvx-root-$TIMESTAMP/vbox_grub.cfg
sed -i.bak -e s/"linux \/bzImage root=\/dev\/sda2"/"linux \/bzImage root=\/dev\/sda2 console=ttyS0 console=tty0"/g cumulusvx-boot-$TIMESTAMP/grub/grub.cfg
sed -i.bak -e s/"# S0:3:respawn:\/sbin\/getty -L \$(get-cmdline-console) vt100"/"S0:3:respawn:\/sbin\/getty -L \$(get-cmdline-console) vt100"/g cumulusvx-root-$TIMESTAMP/etc/inittab
sed -i.bak -e s/"^exit 0$"/""/g cumulusvx-root-$TIMESTAMP/etc/rc.local
cat << EOF >> cumulusvx-root-$TIMESTAMP/etc/rc.local
mkdir /virl-config
mount /dev/sdb1 /virl-config
chmod +x /virl-config/cumulusvx.sh
/virl-config/cumulusvx.sh >/var/log/virl-startup.log
EOF
bash
# inject script to handle dhcp for eth0 and import of config defined in VM Maestro (config-drive)
umount cumulusvx-boot-$TIMESTAMP
umount cumulusvx-root-$TIMESTAMP
rm -rf cumulusvx-boot-$TIMESTAMP
rm -rf cumulusvx-root-$TIMESTAMP
kpartx -d $CUMULUS_QCOW2_BASENAME.raw
echo
echo "Saving CumulusVX image..."
echo "==========================================================="
qemu-img convert -O qcow2 $CUMULUS_QCOW2_BASENAME.raw $CUMULUS_PATCHED_QCOW2
# use e1000 for now as with virtio we get dhcp errors due to "bad udp checksum" in Debian
glance image-create --container-format bare --disk-format qcow2 --is-public true --name $GLANCE_IMAGE_NAME \
--file $CUMULUS_PATCHED_QCOW2 --property hw_disk_bus=ide --property serial=1 \
--property hw_vif_model=e1000 --property hw_cdrom_type=ide --property release="$GLANCE_IMAGE_RELEASE" --property subtype=CumulusVX --property config_disk_type=disk
echo
echo "Cleaning up..."
echo "==========================================================="
rm $CUMULUS_QCOW2_BASENAME.raw

21
create-cumulusvx-image/dynamic-subtype-CumulusVX.json

@ -0,0 +1,21 @@
{
"dynamic-subtypes": [
{
"config_disk_type": "disk",
"interface_pattern": "swp{0}",
"interface_first": 1,
"interface_range": 25,
"interface_management": "eth0",
"baseline_flavor": "CumulusVX.small",
"baseline_image": "CumulusVX",
"gui_icon": "iosvl2",
"config_file": "/cumulusvx.sh",
"gui_visible": true,
"plugin_base": "generic",
"plugin_name": "CumulusVX",
"plugin_desc": "CumulusVX",
"hw_vm_extra": "",
"cli_serial": 1
}
]
}

5
create-cumulusvx-image/minimal-config-CumulusVX.txt

@ -0,0 +1,5 @@
#!/bin/bash
touch /tmp/cumulusvx-config
useradd -m cisco -s /bin/bash
echo "cisco:cisco" | chpasswd
addgroup cisco sudo
Loading…
Cancel
Save