Skip to content

Commit

Permalink
mbx: refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Yadav <[email protected]>
  • Loading branch information
rohityadavcloud committed Jan 15, 2021
1 parent 9f4772c commit bd91a03
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 135 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ We require that you install nfs and run it from /export:
# See Setting up NFS and then execute following:
cd /export
git clone https://github.com/rhtyd/mbx.git monkeybox
cd monkeybox
sudo cp files/sudoer.mbx /etc/sudoers.d/mbx

## Install KVM on your Laptop

Expand All @@ -47,6 +49,8 @@ on your machine:

Note: you need to install/setup KVM only once.

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

## Setup Network and Templates

For our local dev-qa environment, we'll create a 172.20.0.0/16 virtual network
Expand Down
6 changes: 6 additions & 0 deletions files/sudoer.mbx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Cmnd_Alias CLOUDSTACK = /bin/mkdir, /bin/mount, /bin/umount, /bin/cp, /bin/chmod, /usr/bin/keytool, /bin/keytool, /usr/bin/virsh

Defaults:%sudo !requiretty

%sudo ALL=(root) NOPASSWD:CLOUDSTACK

36 changes: 18 additions & 18 deletions mbx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ ROOT=/export/monkeybox
# Initialise
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 templates"
echo " install: setup monkeynet and mbx templates"
echo " list: list available environments"
echo " build: build packages from git repo and sha/tag/branch"
echo " deploy: deploy monkeybox VMs using templates, setup storage"
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 monkeyboxes"
echo " clean: destroy environment"
echo " destroy: destroy environment"
}

install() {
Expand All @@ -29,21 +30,21 @@ install() {
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
}

list() {
echo "List of MonkeyBoxes:"
echo
COUNTER=0
for env in $(cat $ROOT/boxes/boxes.list); do
echo "Name: $env"
echo -e "Name: \033[4m$env\033[0m"
for vm in $(cat $ROOT/boxes/$env.list); do
ip=$(getent hosts $vm | awk '{ print $1 }')
url=""
if [[ $vm == *"mgmt"* ]]; then
url="http://$ip:8080/client"
fi
echo " $vm $ip $url"
echo -e "$vm\t$ip\t$url"
done
echo
options+=($env)
Expand All @@ -52,10 +53,9 @@ list() {
if [ ${#options[@]} -eq 0 ]; then
echo "No mbx environments found"
fi

echo
echo "Following mbx templates are available:"
virsh list --all | grep template | awk '{print $2}'
virsh list --all | grep mbxt- | awk '{print $2}'
}

build() {
Expand All @@ -64,8 +64,6 @@ build() {
}

deploy() {
set -x

echo "Creating and starting monkeyboxes"
echo FIXME: take input for name, mgmt server, hypervisor and their counts
echo FIXME: find and use available ID
Expand All @@ -79,12 +77,13 @@ deploy() {
echo $env >> $ROOT/boxes/boxes.list

# Clone in boxes directory
virt-clone --original template-kvm-centos7 --name $env-kvm1 --file $ROOT/boxes/$env/centos7-kvm1.qcow2
echo "Cloning mbx templates"
virt-clone --original mbxt-kvm-centos7 --name $env-kvm1 --file $ROOT/boxes/$env/centos7-kvm1.qcow2
echo $env-kvm1 >> $ROOT/boxes/$env.list
virt-clone --original template-kvm-centos7 --name $env-kvm2 --file $ROOT/boxes/$env/centos7-kvm2.qcow2
virt-clone --original mbxt-kvm-centos7 --name $env-kvm2 --file $ROOT/boxes/$env/centos7-kvm2.qcow2
echo $env-kvm2 >> $ROOT/boxes/$env.list
mgmt="$env-mgmt1"
virt-clone --original template-kvm-centos7 --name $mgmt --file $ROOT/boxes/$env/centos7-mgmt1.qcow2
virt-clone --original mbxt-kvm-centos7 --name $mgmt --file $ROOT/boxes/$env/centos7-mgmt1.qcow2
echo $env-mgmt1 >> $ROOT/boxes/$env.list

echo "Starting VMs"
Expand Down Expand Up @@ -126,7 +125,7 @@ deploy() {
sshpass -p 'P@ssword123' ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" root@$env-kvm1 yum install -y cloudstack-agent
sshpass -p 'P@ssword123' ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" root@$env-kvm2 yum install -y cloudstack-agent

echo "VMs created, deploy env using 'mbx deploy'"
echo "VMs deployed, to launch zone run 'mbx launch'"
}

launch() {
Expand Down Expand Up @@ -156,8 +155,9 @@ launch() {

# Deploy data center with generated config
while ! nc -vzw 5 $mgmt_ip 8096 2>&1 > /dev/null; do echo "Waiting for management server to come up"; sleep 10; done
echo "Management server is UP now, launch data center now"
echo "Management server is UP now, launching data center now"
sshpass -p 'P@ssword123' ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" root@$mgmt_ip python /usr/lib/python2.7/site-packages/marvin/deployDataCenter.py -i /marvin/marvin.cfg
echo "Launched: http://$mgmt_ip:8080/client"
}

test() {
Expand All @@ -170,10 +170,10 @@ test() {
done
}

clean() {
destroy() {
env=$1
if [ -z "$env" ]; then
echo "Usage: mbx clean <env name>. Please pass a name, run 'mbx list' for list of available envs."
echo "Usage: mbx destroy <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
Expand All @@ -195,6 +195,6 @@ case "$1" in
deploy) deploy;;
launch) launch;;
test) test;;
clean) clean $2;;
destroy) destroy $2;;
*) usage;;
esac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<domain type='kvm'>
<name>template-kvm-centos7</name>
<name>mbxt-kvm-centos7</name>
<uuid>942496ef-dfb1-4bcd-9751-93d3a02c35a7</uuid>
<memory unit='KiB'>8392704</memory>
<currentMemory unit='KiB'>8392704</currentMemory>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<domain type='kvm'>
<name>template-vmware67u3-with-vc</name>
<name>mbxt-vmware67u3-with-vc</name>
<uuid>4c72be3c-21c4-444f-8a6e-9df1434d77d3</uuid>
<memory unit='KiB'>18874368</memory>
<currentMemory unit='KiB'>18874368</currentMemory>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<domain type='kvm'>
<name>template-vmware67u3</name>
<name>mbxt-vmware67u3</name>
<uuid>ecd9bf1c-d6fa-4794-a8d7-8e936694a0a2</uuid>
<memory unit='KiB'>8392704</memory>
<currentMemory unit='KiB'>8392704</currentMemory>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<domain type='kvm'>
<name>template-xcpng76</name>
<name>mbxt-xcpng76</name>
<uuid>c948ce2c-5273-4f23-9456-da1647e74e72</uuid>
<memory unit='KiB'>8392704</memory>
<currentMemory unit='KiB'>8392704</currentMemory>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<domain type='kvm'>
<name>template-xenserver71</name>
<name>mbxt-xenserver71</name>
<uuid>cc6c404d-bfbd-44b4-ac4f-5dd5dcc9daaa</uuid>
<memory unit='KiB'>8392704</memory>
<currentMemory unit='KiB'>8392704</currentMemory>
Expand Down
112 changes: 0 additions & 112 deletions templates/xmls/template-ubuntu1804.xml

This file was deleted.

Empty file added vpn/ovpn-data/.keep
Empty file.
16 changes: 16 additions & 0 deletions vpn/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
OVPN_DATA="/export/monkeybox/vpn/ovpn-data"
SERVER="192.168.1.100"

if [ -z $(ls -A $OVPN_DATA) ]; then
docker pull kylemanna/openvpn
# Generate Data
docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://$SERVER
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki
fi

# Start server
docker run -v $OVPN_DATA:/etc/openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn

# Create user
# docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn easyrsa build-client-full rohit-hp nopass
# docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_getclient rohit-hp > rohit-hp.ovpn

0 comments on commit bd91a03

Please sign in to comment.