Skip to content

Commit

Permalink
mbx: update tool
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Yadav <[email protected]>
  • Loading branch information
rohityadavcloud committed Feb 9, 2021
1 parent bd4be77 commit e3ea28a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
boxes/boxes.list
boxes/**
templates/*.qcow2
40 changes: 11 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NFS server and KVM are prerequisites to using `mbx`.

### Install and setup NFS

apt-get install nfs-kernel-server quota
apt-get install nfs-kernel-server quota sshpass wget
echo "/export *(rw,async,no_root_squash,no_subtree_check)" > /etc/exports
mkdir -p /export/testing
exportfs -a
Expand Down Expand Up @@ -54,33 +54,26 @@ on your machine:

![VM Manager](doc/images/virt-manager.png)

Install docker for packaging: https://docs.docker.com/engine/install/ubuntu/
Install docker for packaging, follow: https://docs.docker.com/engine/install/ubuntu/

### Install `mbx`

git clone https://github.com/shapeblue/mbx /export/monkeybox
cd /export/monkeybox/templates
# Download pre-built mbx templates
wget http://download.cloudstack.org/templates/mbx/kvm-centos7.qcow2
wget http://download.cloudstack.org/templates/mbx/vmware67u3.qcow2
wget http://download.cloudstack.org/templates/mbx/xcpng76.qcow2
wget http://download.cloudstack.org/templates/mbx/xenserver71.qcow2
wget http://download.cloudstack.org/templates/mbx/md5sum.txt
# After downloading run the md5sum check again the md5sum.txt
md5sum --check md5sum.txt
# Next setup mbx tool:
cd /export/monkeybox
sudo cp files/sudoer.mbx /etc/sudoers.d/mbx
# Enable mbx under $PATH, for bash:
echo export PATH="/export/monkeybox:$PATH" >> ~/.bashrc
# Enable mbx under $PATH, for zsh:
echo export PATH="/export/monkeybox:$PATH" >> ~/.zshrc
# Initialise `mbx` by opening in another shell:
mbx init

The `mbx init` is idempotent and can be used to update templates and domain xml
definitions.

### Setup `mbx` Network

For our local dev-qa environment, we'll create a 172.20.0.0/16 virtual network
with NAT so VMs on this network are only accessible from the host/laptop but
not by the outside network.
not by the outside network. The `mbx init` command will initialise this network.

External Network
. +-----------------+
Expand All @@ -103,17 +96,6 @@ used as a single physical network in CloudStack that has the public, private,
management/control and storage networks. A complex setup is possible by adding
multiple virtual networks and nics on them.

To setup the network run:

$ mbx install

This essentially runs:

virsh net-define monkeynet.xml
virsh net-autostart monkeynet
virsh net-start monkeynet
# finally loops through templates/xmls and defines the templates

The default network xml definition assumes `virbr1` is not already assigned, in
case you get an error change the bridge name to something other than `virbr1`.

Expand Down Expand Up @@ -163,7 +145,7 @@ run in management VMs and their IPs will be dynamically allocated.

To ssh into deployed VMs (with NSS configured), you can login simply using:

$ ssh root@<name of VM/domain>
$ ssh root@<name of VM/domain or IP>

### Storage Setup

Expand Down Expand Up @@ -202,7 +184,7 @@ environments, run smoketests on them and destroy environments. Usage:
$ mbx
MonkeyBox 🐵 1.0
Available commands are:
install: setup monkeynet and mbx templates
init: initialises monkeynet and mbx templates
build: build packages from git repo and sha/tag/branch
list: list available environments
deploy: deploy monkeybox VMs using mbx templates, setup storage
Expand Down Expand Up @@ -316,7 +298,7 @@ Fork the repository at: github.com/apache/cloudstack, or get the code:

Noredist CloudStack builds requires additional jars that may be installed from:

https://github.com/rhtyd/cloudstack-nonoss
https://github.com/shapeblue/cloudstack-nonoss

Clone the above repository and run the install.sh script, you'll need to do
this only once or whenver the noredist jar dependencies are updated in above
Expand Down
87 changes: 66 additions & 21 deletions mbx
Original file line number Diff line number Diff line change
@@ -1,40 +1,57 @@
#!/bin/bash

set -e

ROOT=/export/monkeybox
ROOT="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
mkdir -p $ROOT/boxes
touch $ROOT/boxes/boxes.list
export LIBVIRT_DEFAULT_URI="qemu:///system"

echo MonkeyBox 🐵 1.0

usage() {
echo "Available commands are:"
echo " install: setup monkeynet and mbx templates"
echo " init: initialises monkeynet and mbx templates"
echo " build: build packages from git repo and sha/tag/branch"
echo " list: list available environments"
echo " deploy: deploy monkeybox VMs using mbx templates, setup storage"
echo " launch: creates marvin config file and launches a zone"
echo " test: start marvin tests"
echo " stop: stop all env VMs"
echo " start: start all env VMs"
echo " destroy: destroy environment"
}

install() {
virsh net-define $ROOT/monkeynet.xml
virsh net-autostart monkeynet
virsh net-start monkeynet
echo $pwd
echo "Setting up mbx templates, we assumes the templates are already downloaded in templates directory"
for xml in $(ls $ROOT/templates/xmls/*xml); do virsh define $xml; done
sudo cp $ROOT/files/sudoer.mbx /etc/sudoers.d/mbx
}

build() {
echo "Build Packages, please input git repo URL and git/sha/branch"
echo "Pulling docker build container images"
docker pull bhaisaab/centos8-cloudstack-slave
docker pull bhaisaab/centos7-cloudstack-slave
docker pull bhaisaab/centos6-cloudstack-slave
docker pull bhaisaab/ubuntu-cloudstack-slave
echo "TODO"
}

init() {
if virsh net-list --all --name | grep -q monkeynet;
then
echo "'monkeynet' network is already defined, skipped re-initialisation";
else
virsh net-define $ROOT/monkeynet.xml
virsh net-autostart monkeynet
virsh net-start monkeynet
fi
echo "Setting up mbx sudoers file. Please enter sudoer password if you're prompted."
sudo cp $ROOT/files/sudoer.mbx /etc/sudoers.d/mbx
echo "Updating templates"
for template in $(cat $ROOT/templates/md5sum.txt | awk '{print $2}' | sed 's/.qcow2//g'); do
virsh undefine mbxt-$template >/dev/null 2>/dev/null || true
echo "Updating template: $template"
wget --show-progress -nc https://download.cloudstack.org/templates/mbx/$template.qcow2 -O $ROOT/templates/$template.qcow2 || true
virsh define $ROOT/templates/xmls/mbxt-$template.xml >/dev/null
done
echo "Running md5 checksum checks on templates (this may take some time...)"
(cd $ROOT/templates && md5sum --check md5sum.txt)
}

list() {
echo
for env in $(cat $ROOT/boxes/boxes.list); do
Expand All @@ -48,7 +65,7 @@ list() {
echo -e "$vm\t$ip\t$url"
if [[ $vm == *vmw-host1* ]]; then
vcip=$(sshpass -p 'P@ssword123' ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" root@$vm vim-cmd "vmsvc/get.guest 1 | grep ipAddress | head -1 | sed 's/.*ipAddress = \"//g' | sed 's/\".*//g'" 2> /dev/null) || true
echo -e "VC (photon-machine)\t$vcip\thttps://$vcip/"
echo -e "VC (photon-machine)\t\t$vcip\thttps://$vcip/"
fi
done
echo
Expand Down Expand Up @@ -79,7 +96,7 @@ deploy() {

id=
for idx in {1..9}; do
if ! grep -q qa-$idx- $ROOT/boxes/boxes.list; then
if ! grep -q qa$idx- $ROOT/boxes/boxes.list; then
id=$idx
break
fi
Expand All @@ -99,7 +116,7 @@ deploy() {
hypervisor=$(echo $hyt | awk '{print substr($0,6,3)}')
repo=${4:-"http://packages.shapeblue.com/cloudstack/upstream/centos7/4.15"}
storage=${5:-"/export/testing/4.15"}
env="qa-$id-$name-$hypervisor"
env="qa$id-$name-$hypervisor"

echo -e "Building env with name: \033[4m$env\033[0m"
echo "Management server template: $mst"
Expand Down Expand Up @@ -261,7 +278,7 @@ launch() {
echo "Please provide a valid env name, run 'mbx list' to find name of environments"
exit 1
fi
id=$(echo $env | sed 's/qa-//g' | sed 's/-.*//g')
id=$(echo $env | sed 's/^qa//g' | sed 's/-.*$//g')
echo "Generating marvin config for env ID $id"

msip=$(getent hosts $env-mgmt1 | awk '{ print $1 }')
Expand All @@ -278,14 +295,39 @@ launch() {

test() {
set +x
echo "Please ssh into the env; cd /marvin; bash -x smoketests.sh:"
echo "Please ssh into the env and run: cd /marvin; bash -x smoketests.sh"
for env in $(cat $ROOT/boxes/boxes.list); do
for vm in $(cat $ROOT/boxes/$env/list| grep mgmt1); do
echo "$env: ssh root@$vm"
done
done
}

stop() {
env=$1
if [ -z "$env" ]; then
echo "Usage: mbx stop <env name>. Please pass a name, run 'mbx list' for list of available envs."
return
fi
sync
for vm in $(cat $ROOT/boxes/$env/list); do
sync
virsh destroy $vm 2>/dev/null || true
done
}


start() {
env=$1
if [ -z "$env" ]; then
echo "Usage: mbx start <env name>. Please pass a name, run 'mbx list' for list of available envs."
return
fi
for vm in $(cat $ROOT/boxes/$env/list); do
virsh start $vm 2>/dev/null || true;
done
}

destroy() {
env=$1
if [ -z "$env" ]; then
Expand All @@ -299,18 +341,21 @@ destroy() {
sed -i "/$env/d" $ROOT/boxes/boxes.list
rm -frv $ROOT/boxes/$env
echo "Removed environment VMs and config"
echo "To remove storage run: sudo rm -frv /export/testing/$env"
echo "To remove storage run:"
echo " sudo rm -frv /export/testing/$env"
}

case "$1" in
help) usage;;
-h) usage;;
install) install;;
init) init;;
list) list;;
build) build;;
deploy) deploy ${@:2};;
launch) launch $2;;
test) test;;
start) start $2;;
stop) stop $2;;
destroy) destroy $2;;
*) usage;;
esac
Empty file added packages/.gitkeep
Empty file.

0 comments on commit e3ea28a

Please sign in to comment.