From bd91a033d173de442652b75e5c8d0b01ad52a148 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Sat, 16 Jan 2021 02:13:41 +0530 Subject: [PATCH] mbx: refactor Signed-off-by: Rohit Yadav --- README.md | 4 + files/sudoer.mbx | 6 + mbx | 36 +++--- ...e-kvm-centos7.xml => mbxt-kvm-centos7.xml} | 2 +- ...ith-vc.xml => mbxt-vmware67u3-with-vc.xml} | 2 +- ...ate-vmware67u3.xml => mbxt-vmware67u3.xml} | 2 +- ...{template-xcpng76.xml => mbxt-xcpng76.xml} | 2 +- ...e-xenserver71.xml => mbxt-xenserver71.xml} | 2 +- templates/xmls/template-ubuntu1804.xml | 112 ------------------ vpn/ovpn-data/.keep | 0 vpn/run.sh | 16 +++ 11 files changed, 49 insertions(+), 135 deletions(-) create mode 100644 files/sudoer.mbx rename templates/xmls/{template-kvm-centos7.xml => mbxt-kvm-centos7.xml} (99%) rename templates/xmls/{template-vmware67u3-with-vc.xml => mbxt-vmware67u3-with-vc.xml} (98%) rename templates/xmls/{template-vmware67u3.xml => mbxt-vmware67u3.xml} (99%) rename templates/xmls/{template-xcpng76.xml => mbxt-xcpng76.xml} (99%) rename templates/xmls/{template-xenserver71.xml => mbxt-xenserver71.xml} (99%) delete mode 100644 templates/xmls/template-ubuntu1804.xml create mode 100644 vpn/ovpn-data/.keep create mode 100644 vpn/run.sh diff --git a/README.md b/README.md index a95bdd0..5ebab0c 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/files/sudoer.mbx b/files/sudoer.mbx new file mode 100644 index 0000000..0d383f0 --- /dev/null +++ b/files/sudoer.mbx @@ -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 + diff --git a/mbx b/mbx index 916fdb4..5ed409c 100755 --- a/mbx +++ b/mbx @@ -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() { @@ -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) @@ -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() { @@ -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 @@ -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" @@ -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() { @@ -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() { @@ -170,10 +170,10 @@ test() { done } -clean() { +destroy() { env=$1 if [ -z "$env" ]; then - echo "Usage: mbx clean . Please pass a name, run 'mbx list' for list of available envs." + echo "Usage: mbx destroy . Please pass a name, run 'mbx list' for list of available envs." return fi for vm in $(cat $ROOT/boxes/$env.list); do @@ -195,6 +195,6 @@ case "$1" in deploy) deploy;; launch) launch;; test) test;; - clean) clean $2;; + destroy) destroy $2;; *) usage;; esac diff --git a/templates/xmls/template-kvm-centos7.xml b/templates/xmls/mbxt-kvm-centos7.xml similarity index 99% rename from templates/xmls/template-kvm-centos7.xml rename to templates/xmls/mbxt-kvm-centos7.xml index 7ff7a7a..4a267f5 100644 --- a/templates/xmls/template-kvm-centos7.xml +++ b/templates/xmls/mbxt-kvm-centos7.xml @@ -1,5 +1,5 @@ - template-kvm-centos7 + mbxt-kvm-centos7 942496ef-dfb1-4bcd-9751-93d3a02c35a7 8392704 8392704 diff --git a/templates/xmls/template-vmware67u3-with-vc.xml b/templates/xmls/mbxt-vmware67u3-with-vc.xml similarity index 98% rename from templates/xmls/template-vmware67u3-with-vc.xml rename to templates/xmls/mbxt-vmware67u3-with-vc.xml index 05d65b2..7d236c8 100644 --- a/templates/xmls/template-vmware67u3-with-vc.xml +++ b/templates/xmls/mbxt-vmware67u3-with-vc.xml @@ -1,5 +1,5 @@ - template-vmware67u3-with-vc + mbxt-vmware67u3-with-vc 4c72be3c-21c4-444f-8a6e-9df1434d77d3 18874368 18874368 diff --git a/templates/xmls/template-vmware67u3.xml b/templates/xmls/mbxt-vmware67u3.xml similarity index 99% rename from templates/xmls/template-vmware67u3.xml rename to templates/xmls/mbxt-vmware67u3.xml index 230fd41..bfcbc84 100644 --- a/templates/xmls/template-vmware67u3.xml +++ b/templates/xmls/mbxt-vmware67u3.xml @@ -1,5 +1,5 @@ - template-vmware67u3 + mbxt-vmware67u3 ecd9bf1c-d6fa-4794-a8d7-8e936694a0a2 8392704 8392704 diff --git a/templates/xmls/template-xcpng76.xml b/templates/xmls/mbxt-xcpng76.xml similarity index 99% rename from templates/xmls/template-xcpng76.xml rename to templates/xmls/mbxt-xcpng76.xml index cb4e046..65ba68c 100644 --- a/templates/xmls/template-xcpng76.xml +++ b/templates/xmls/mbxt-xcpng76.xml @@ -1,5 +1,5 @@ - template-xcpng76 + mbxt-xcpng76 c948ce2c-5273-4f23-9456-da1647e74e72 8392704 8392704 diff --git a/templates/xmls/template-xenserver71.xml b/templates/xmls/mbxt-xenserver71.xml similarity index 99% rename from templates/xmls/template-xenserver71.xml rename to templates/xmls/mbxt-xenserver71.xml index 73eae47..32a7d32 100644 --- a/templates/xmls/template-xenserver71.xml +++ b/templates/xmls/mbxt-xenserver71.xml @@ -1,5 +1,5 @@ - template-xenserver71 + mbxt-xenserver71 cc6c404d-bfbd-44b4-ac4f-5dd5dcc9daaa 8392704 8392704 diff --git a/templates/xmls/template-ubuntu1804.xml b/templates/xmls/template-ubuntu1804.xml deleted file mode 100644 index 07b8014..0000000 --- a/templates/xmls/template-ubuntu1804.xml +++ /dev/null @@ -1,112 +0,0 @@ - - template-ubuntu1804 - 620621c5-a098-4ffe-9748-c4b7f85c7cfd - 4194304 - 4194304 - 4 - - hvm - - - - - - - - - - - - - destroy - restart - destroy - - - - - - /usr/bin/qemu-system-x86_64 - - - - - -
- - - - - - - -
- - -
- - - -
- - - -
- - - -
- - -
- - -
- - - - - - -
- - - - - - - - - - - -
- - -
- - - - - - - - -
- -