Skip to content

Commit bd91a03

Browse files
mbx: refactor
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 9f4772c commit bd91a03

11 files changed

+49
-135
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ We require that you install nfs and run it from /export:
2222
# See Setting up NFS and then execute following:
2323
cd /export
2424
git clone https://github.com/rhtyd/mbx.git monkeybox
25+
cd monkeybox
26+
sudo cp files/sudoer.mbx /etc/sudoers.d/mbx
2527

2628
## Install KVM on your Laptop
2729

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

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

52+
Install docker for packaging: https://docs.docker.com/engine/install/ubuntu/
53+
5054
## Setup Network and Templates
5155

5256
For our local dev-qa environment, we'll create a 172.20.0.0/16 virtual network

files/sudoer.mbx

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Cmnd_Alias CLOUDSTACK = /bin/mkdir, /bin/mount, /bin/umount, /bin/cp, /bin/chmod, /usr/bin/keytool, /bin/keytool, /usr/bin/virsh
2+
3+
Defaults:%sudo !requiretty
4+
5+
%sudo ALL=(root) NOPASSWD:CLOUDSTACK
6+

mbx

+18-18
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ ROOT=/export/monkeybox
77
# Initialise
88
mkdir -p $ROOT/boxes
99
touch $ROOT/boxes/boxes.list
10+
export LIBVIRT_DEFAULT_URI="qemu:///system"
1011

1112
echo MonkeyBox 🐵 1.0
1213

1314
usage() {
1415
echo "Available commands are:"
15-
echo " install: setup monkeynet and templates"
16+
echo " install: setup monkeynet and mbx templates"
1617
echo " list: list available environments"
1718
echo " build: build packages from git repo and sha/tag/branch"
18-
echo " deploy: deploy monkeybox VMs using templates, setup storage"
19+
echo " deploy: deploy monkeybox VMs using mbx templates, setup storage"
1920
echo " launch: creates marvin config file and launches a zone"
2021
echo " test: start marvin tests"
2122
echo " stop: stop monkeyboxes"
22-
echo " clean: destroy environment"
23+
echo " destroy: destroy environment"
2324
}
2425

2526
install() {
@@ -29,21 +30,21 @@ install() {
2930
echo $pwd
3031
echo "Setting up mbx templates, we assumes the templates are already downloaded in templates directory"
3132
for xml in $(ls $ROOT/templates/xmls/*xml); do virsh define $xml; done
33+
sudo cp $ROOT/files/sudoer.mbx /etc/sudoers.d/mbx
3234
}
3335

3436
list() {
35-
echo "List of MonkeyBoxes:"
3637
echo
3738
COUNTER=0
3839
for env in $(cat $ROOT/boxes/boxes.list); do
39-
echo "Name: $env"
40+
echo -e "Name: \033[4m$env\033[0m"
4041
for vm in $(cat $ROOT/boxes/$env.list); do
4142
ip=$(getent hosts $vm | awk '{ print $1 }')
4243
url=""
4344
if [[ $vm == *"mgmt"* ]]; then
4445
url="http://$ip:8080/client"
4546
fi
46-
echo " $vm $ip $url"
47+
echo -e "$vm\t$ip\t$url"
4748
done
4849
echo
4950
options+=($env)
@@ -52,10 +53,9 @@ list() {
5253
if [ ${#options[@]} -eq 0 ]; then
5354
echo "No mbx environments found"
5455
fi
55-
5656
echo
5757
echo "Following mbx templates are available:"
58-
virsh list --all | grep template | awk '{print $2}'
58+
virsh list --all | grep mbxt- | awk '{print $2}'
5959
}
6060

6161
build() {
@@ -64,8 +64,6 @@ build() {
6464
}
6565

6666
deploy() {
67-
set -x
68-
6967
echo "Creating and starting monkeyboxes"
7068
echo FIXME: take input for name, mgmt server, hypervisor and their counts
7169
echo FIXME: find and use available ID
@@ -79,12 +77,13 @@ deploy() {
7977
echo $env >> $ROOT/boxes/boxes.list
8078

8179
# Clone in boxes directory
82-
virt-clone --original template-kvm-centos7 --name $env-kvm1 --file $ROOT/boxes/$env/centos7-kvm1.qcow2
80+
echo "Cloning mbx templates"
81+
virt-clone --original mbxt-kvm-centos7 --name $env-kvm1 --file $ROOT/boxes/$env/centos7-kvm1.qcow2
8382
echo $env-kvm1 >> $ROOT/boxes/$env.list
84-
virt-clone --original template-kvm-centos7 --name $env-kvm2 --file $ROOT/boxes/$env/centos7-kvm2.qcow2
83+
virt-clone --original mbxt-kvm-centos7 --name $env-kvm2 --file $ROOT/boxes/$env/centos7-kvm2.qcow2
8584
echo $env-kvm2 >> $ROOT/boxes/$env.list
8685
mgmt="$env-mgmt1"
87-
virt-clone --original template-kvm-centos7 --name $mgmt --file $ROOT/boxes/$env/centos7-mgmt1.qcow2
86+
virt-clone --original mbxt-kvm-centos7 --name $mgmt --file $ROOT/boxes/$env/centos7-mgmt1.qcow2
8887
echo $env-mgmt1 >> $ROOT/boxes/$env.list
8988

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

129-
echo "VMs created, deploy env using 'mbx deploy'"
128+
echo "VMs deployed, to launch zone run 'mbx launch'"
130129
}
131130

132131
launch() {
@@ -156,8 +155,9 @@ launch() {
156155

157156
# Deploy data center with generated config
158157
while ! nc -vzw 5 $mgmt_ip 8096 2>&1 > /dev/null; do echo "Waiting for management server to come up"; sleep 10; done
159-
echo "Management server is UP now, launch data center now"
158+
echo "Management server is UP now, launching data center now"
160159
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
160+
echo "Launched: http://$mgmt_ip:8080/client"
161161
}
162162

163163
test() {
@@ -170,10 +170,10 @@ test() {
170170
done
171171
}
172172

173-
clean() {
173+
destroy() {
174174
env=$1
175175
if [ -z "$env" ]; then
176-
echo "Usage: mbx clean <env name>. Please pass a name, run 'mbx list' for list of available envs."
176+
echo "Usage: mbx destroy <env name>. Please pass a name, run 'mbx list' for list of available envs."
177177
return
178178
fi
179179
for vm in $(cat $ROOT/boxes/$env.list); do
@@ -195,6 +195,6 @@ case "$1" in
195195
deploy) deploy;;
196196
launch) launch;;
197197
test) test;;
198-
clean) clean $2;;
198+
destroy) destroy $2;;
199199
*) usage;;
200200
esac

templates/xmls/template-kvm-centos7.xml renamed to templates/xmls/mbxt-kvm-centos7.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<domain type='kvm'>
2-
<name>template-kvm-centos7</name>
2+
<name>mbxt-kvm-centos7</name>
33
<uuid>942496ef-dfb1-4bcd-9751-93d3a02c35a7</uuid>
44
<memory unit='KiB'>8392704</memory>
55
<currentMemory unit='KiB'>8392704</currentMemory>

templates/xmls/template-vmware67u3-with-vc.xml renamed to templates/xmls/mbxt-vmware67u3-with-vc.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<domain type='kvm'>
2-
<name>template-vmware67u3-with-vc</name>
2+
<name>mbxt-vmware67u3-with-vc</name>
33
<uuid>4c72be3c-21c4-444f-8a6e-9df1434d77d3</uuid>
44
<memory unit='KiB'>18874368</memory>
55
<currentMemory unit='KiB'>18874368</currentMemory>

templates/xmls/template-vmware67u3.xml renamed to templates/xmls/mbxt-vmware67u3.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<domain type='kvm'>
2-
<name>template-vmware67u3</name>
2+
<name>mbxt-vmware67u3</name>
33
<uuid>ecd9bf1c-d6fa-4794-a8d7-8e936694a0a2</uuid>
44
<memory unit='KiB'>8392704</memory>
55
<currentMemory unit='KiB'>8392704</currentMemory>

templates/xmls/template-xcpng76.xml renamed to templates/xmls/mbxt-xcpng76.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<domain type='kvm'>
2-
<name>template-xcpng76</name>
2+
<name>mbxt-xcpng76</name>
33
<uuid>c948ce2c-5273-4f23-9456-da1647e74e72</uuid>
44
<memory unit='KiB'>8392704</memory>
55
<currentMemory unit='KiB'>8392704</currentMemory>

templates/xmls/template-xenserver71.xml renamed to templates/xmls/mbxt-xenserver71.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<domain type='kvm'>
2-
<name>template-xenserver71</name>
2+
<name>mbxt-xenserver71</name>
33
<uuid>cc6c404d-bfbd-44b4-ac4f-5dd5dcc9daaa</uuid>
44
<memory unit='KiB'>8392704</memory>
55
<currentMemory unit='KiB'>8392704</currentMemory>

templates/xmls/template-ubuntu1804.xml

-112
This file was deleted.

vpn/ovpn-data/.keep

Whitespace-only changes.

vpn/run.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
OVPN_DATA="/export/monkeybox/vpn/ovpn-data"
2+
SERVER="192.168.1.100"
3+
4+
if [ -z $(ls -A $OVPN_DATA) ]; then
5+
docker pull kylemanna/openvpn
6+
# Generate Data
7+
docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://$SERVER
8+
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki
9+
fi
10+
11+
# Start server
12+
docker run -v $OVPN_DATA:/etc/openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
13+
14+
# Create user
15+
# docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn easyrsa build-client-full rohit-hp nopass
16+
# docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_getclient rohit-hp > rohit-hp.ovpn

0 commit comments

Comments
 (0)