Commit f0134171 authored by SIMONIN Matthieu's avatar SIMONIN Matthieu
Browse files

WiP get rid of the bash script

parent 751159ba
......@@ -2,3 +2,6 @@
path = src/crossbeam
url = https://gitlab.inria.fr/lrilling/crossbeam.git
branch = dev/waitfree
[submodule "src/qemu"]
path = src/qemu
url = git@gitlab.inria.fr:msimonin/qemu.git
......@@ -31,16 +31,23 @@ class TansivVM(object):
qemu_cmd: str,
qemu_image: Path(),
qemu_args: Optional[str] = None,
public_key: Optional[str] = None,
):
self.tantap = ip_tantap
self.management = ip_management
self.qemu_cmd = qemu_cmd
self.qemu_image = qemu_image.resolve()
self.public_key = public_key
if qemu_args is None:
self.qemu_args = " --icount shift=1,sleep=on" " -rtc clock=vm" " -m 1g"
# Tansiv profile ?
self.qemu_args = (
" --icount shift=1,sleep=on"
" -rtc clock=vm"
f" -m 1g --vsg mynet0,src={ip_tantap.ip}"
)
else:
self.qemu_args = args
self.qemu_args = qemu_args
@property
def hostname(self) -> str:
......@@ -63,6 +70,9 @@ class TansivVM(object):
def ci_meta_data(self) -> Dict:
meta_data = dict()
meta_data.update({"instance-id": self.hostname})
if self.public_key is not None:
meta_data.update({"public-keys": self.public_key})
return meta_data
def ci_network_config(self) -> Dict:
......@@ -154,7 +164,7 @@ class TansivVM(object):
f" {self.qemu_args}"
f" -drive file={image} "
f" -cdrom {iso}"
f" -netdev tantap,src={self.tantap.ip},id=mynet0,ifname={self.tapname[0]},script=no,downscript=no"
f" -netdev tantap,id=mynet0,ifname={self.tapname[0]},script=no,downscript=no"
f" -device e1000,netdev=mynet0,mac={self.mac[0]}"
f" -netdev tap,id=mynet1,ifname={self.tapname[1]},script=no,downscript=no"
f" -device e1000,netdev=mynet1,mac={self.mac[1]}"
......@@ -210,17 +220,33 @@ done
help="The ip (in cidr) to use for the management interface",
)
parser.add_argument("--qemu-args", type=str, help="arguments to pass to qemu")
logging.basicConfig(level=logging.DEBUG)
args = parser.parse_args()
ip_tantap = IPv4Interface(args.ip_tantap)
ip_management = IPv4Interface(args.ip_management)
qemu_args = args.qemu_args
# get the mandatory variables from the env
qemu_cmd = from_env(ENV_QEMU)
qemu_image = Path(from_env(ENV_IMAGE))
vm = TansivVM(ip_tantap, ip_management, qemu_cmd=qemu_cmd, qemu_image=qemu_image)
# check the required third party software
check_call("genisoimage --help", shell=True)
check_call("qemu-img --help", shell=True)
# will be pushed to the root authorized_keys (root)
public_key = (Path().home() / ".ssh" / "id_rsa.pub").open().read()
vm = TansivVM(
ip_tantap,
ip_management,
qemu_cmd=qemu_cmd,
qemu_image=qemu_image,
qemu_args=qemu_args,
public_key=public_key,
)
with tempfile.TemporaryDirectory() as tmp:
LOGGER.info(f"Launching in {tmp}")
......
#!/usr/bin/env bash
set -x
usage() {
cat <<EOF
USAGE:
./boot_and_log.sh IP MAC MAC2
Boots a VM. Use two nics: one for tantap the other for a regular tap (management interface).
The mapping mac <-> ip must be set in your dhcp.
You can use libvirt network to get the bridge and dhcp up and running.
Positional Arguments:
IP : The IP to use for the tantap interface. This will the source of the vsg packet.
MAC : The mac address to use for the tantap interface.
The tap to use is named based on the last byte of the mac.
MAC2 : The mac address to use for the management interface (regular tantap).
The tap to use is named based on the last byte of the mac.
Environment Variables:
owned:
QEMU: path to the qemu binary (useful to test a modified version)
IMAGE: path to a qcow2 or raw image disk (to serve as backing file for the disk images)
from third party (examples)
SLIRP_DEBUG="all": activate all debug message from slirp
G_MESSAGES_DEBUG="Slirp": glib debug filter
NOTE:
- create tuntap before:
- for tap in {tap10,tap11}
do
sudo ip tuntap add $tap mode tap user msimonin && sudo ip link set $tap master tantap0 && sudo ip link set $tap up
done
- for tap in {tap20,tap21}
do
sudo ip tuntap add $tap mode tap user msimonin && sudo ip link set $tap master tantap0-mgmt && sudo ip link set $tap up
done
EOF
}
if [ -z $QEMU ]
then
echo "QEMU variable isn't set."
exit 1
fi
if [ -z $IMAGE ]
then
echo "IMAGE disk isn't set"
exit 1
fi
if (( "$#" != "3" ))
then
usage
exit 1
fi
IP=$1
MAC=$2
MAC2=$3
DESCRIPTOR=${MAC:(-2)}
DESCRIPTOR2=${MAC2:(-2)}
VM_NAME="vm-${MAC//:/-}"
# A decent key to use
cloud_init_key=$(cat ~/.ssh/id_rsa.pub)
CLOUD_INIT_DIR=cloud-init-data-$VM_NAME
CLOUD_INIT_ISO=cloud-init-$VM_NAME.iso
mkdir -p $CLOUD_INIT_DIR
# Generate a minimal cloud-init to enable passwordless SSH access
cat <<EOF > $CLOUD_INIT_DIR/meta-data
instance-id: iid-local01
public-keys:
- $cloud_init_key"
EOF
cat <<EOF > $CLOUD_INIT_DIR/user-data
#cloud-config
hostname: $VM_NAME
local-hostname: $VM_NAME
disable_root: false
bootcmd:
- echo "-----> START of MY CLOUD INIT <---------- \n"
- echo "-----> END of MY CLOUD INIT <---------- \n"
- echo "192.168.120.10 t10" >> /etc/hosts
- echo "192.168.120.11 t11" >> /etc/hosts
- echo "192.168.121.20 m10" >> /etc/hosts
- echo "192.168.121.21 m11" >> /etc/hosts
- echo 127.0.0.1 $VM_NAME >> /etc/hosts
EOF
cat <<EOF > $CLOUD_INIT_DIR/network-config
version: 2
ethernets:
ens3:
addresses: [192.168.120.${DESCRIPTOR}/24]
gateway4: 192.168.120.1
dhcp4: false
dhcp6: false
ens4:
addresses: [192.168.121.${DESCRIPTOR2}/24]
gateway4: 192.168.120.1
dhcp4: false
dhcp6: false
EOF
genisoimage -output $CLOUD_INIT_ISO -volid cidata -joliet -rock $CLOUD_INIT_DIR/user-data $CLOUD_INIT_DIR/meta-data $CLOUD_INIT_DIR/network-config
# Create the qcow2 to boot from
qemu-img create -f qcow2 -o backing_file=$IMAGE $VM_NAME.qcow2
VM_IMAGE=$VM_NAME.qcow2
# start on the base one
# VM_IMAGE=debian10-x64-min.qcow2
TAP_NAME=tap$DESCRIPTOR
TAP2_NAME=tap$DESCRIPTOR2
$QEMU \
--icount shift=1,sleep=on \
-rtc clock=vm \
--vsg mynet0,src=$IP \
-m 1g \
-drive file=$VM_IMAGE \
-cdrom $CLOUD_INIT_ISO \
-netdev tantap,src=$IP,id=mynet0,ifname=$TAP_NAME,script=no,downscript=no \
-device e1000,netdev=mynet0,mac=$MAC \
-netdev tap,id=mynet1,ifname=$TAP2_NAME,script=no,downscript=no \
-device e1000,netdev=mynet1,mac=$MAC2
\ No newline at end of file
......@@ -16,4 +16,11 @@
<argument value="172.16.0.11/24"/> <!-- management -->
</actor>
<actor host="nova-2.lyon.grid5000.fr" function="vsg_vm">
<argument value="192.168.120.12"/> <!-- how simgrid knows me-->
<argument value="./examples/qemus/boot.py"/>
<argument value="192.168.120.12/24"/> <!-- how vsg knows me-->
<argument value="172.16.0.12/24"/> <!-- management -->
</actor>
</platform>
\ No newline at end of file
#!/bin/sh -eux
apt-get -y update
# netperf
apt-get -y install software-properties-common
apt-add-repository non-free
apt-get -y update
apt-get -y install cloud-init iperf mpi-default-bin wget vim
# Get the NAS parallel benchmark
mkdir -p /opt
cd /opt
wget https://www.nas.nasa.gov/assets/npb/NPB3.3.1.tar.gz
tar -xvzf NPB3.3.1.tar.gz
chown -R tansiv:tansiv .
apt -y update
# some utils
apt -y install cloud-init iperf wget vim
# some apps to validate the bouzin
# since we have ssh ready on the management interface, we could also install
# some apps on the fly
apt -y install taktuk
mkdir -p /home/tansiv/.ssh
ssh-keygen -t rsa -f /home/tansiv/.ssh/id_rsa -P ''
......
Subproject commit 9cd3c18d7dbe1ec25fb969e8eb11ad1b07b79648
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment