opnfvdistro=$6
opnfvmodel=$7
-if [[ "$opnfvmodel" = "openstack" ]]; then
- #copy and download charms
- cp $opnfvsdn/fetch-charms.sh ./fetch-charms.sh
-else
- cp kubernetes/fetch-charms.sh ./fetch-charms.sh
-fi
-
jujuver=`juju --version`
maasver=`apt-cache policy maas | grep Installed | cut -d ':' -f 2 | sed -e 's/ //'`
-#modify the ubuntu series wants to deploy
-sed -i -- "s|distro=trusty|distro=$opnfvdistro|g" ./fetch-charms.sh
-
-./fetch-charms.sh $opnfvdistro
-
if [[ "$opnfvmodel" = "openstack" ]]; then
+ #copy and download charms
+ ./opnfvsdn/fetch-charms.sh $opnfvdistro
tar xvf common/scaleio.tar -C ./$opnfvdistro/ --strip=2 juju-scaleio/trusty/
osdomname=''
+else
+ ./kubernetes/fetch-charms.sh $opnfvdistro
fi
#check whether charms are still executing the code even juju-deployer says installed.
if [[ "$API_KEY" = "" ]]; then
- if [ "$maasver" > "2" ]; then
+ if [[ "$maasver" > "2" ]]; then
API_KEY=`sshpass -p ubuntu ssh ubuntu@$MAAS_IP 'sudo maas-region apikey --username=ubuntu'`
else
API_KEY=`sshpass -p ubuntu ssh ubuntu@$MAAS_IP 'sudo maas-region-admin apikey --username=ubuntu'`
osdomname=`grep "os-domain-name" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
fi
- if [ "$maasver" > "2" ]; then
+ if [[ "$maasver" > "2" ]]; then
workmutiple=`maas maas nodes read | grep "cpu_count" | cut -d ':' -f 2 | sed -e 's/ //' | tr ',' ' '`
else
workmutiple=`maas maas nodes list | grep "cpu_count" | cut -d ':' -f 2 | sed -e 's/ //' | tr ',' ' '`
#
# make sure no password asked during the deployment.
-echo "$USER ALL=(ALL) NOPASSWD:ALL" > 90-joid-init
-
-if [ -e /etc/sudoers.d/90-joid-init ]; then
- sudo cp /etc/sudoers.d/90-joid-init 91-joid-init
- sudo chown $USER:$USER 91-joid-init
- sudo chmod 660 91-joid-init
- sudo cat 90-joid-init >> 91-joid-init
- sudo chown root:root 91-joid-init
- sudo mv 91-joid-init /etc/sudoers.d/
+sudoer_file=/etc/sudoers.d/90-joid-init
+sudoer_entry="$USER ALL=(ALL) NOPASSWD:ALL"
+if [ -e $sudoer_file ]; then
+ if ! sudo grep -q "$sudoer_entry" $sudoer_file; then
+ sudo sed -i -e "1i$sudoer_entry" $sudoer_file
+ fi
else
+ echo "$sudoer_entry" > 90-joid-init
sudo chown root:root 90-joid-init
sudo mv 90-joid-init /etc/sudoers.d/
fi
sudo virsh net-define default-net-org.xml
sudo virsh net-destroy default
sudo virsh net-start default
+ rm -f default-net-org.xml
fi
#
done
fi
sudo virsh -c qemu:///system define --file bootstrap
+ rm -f bootstrap
maas $PROFILE machines create autodetect_nodegroup='yes' name='bootstrap' \
tags='bootstrap' hostname='bootstrap' power_type='virsh' mac_addresses=$bootstrapmac \
sudo virsh -c qemu:///system define --file node1-control
sudo virsh -c qemu:///system define --file node2-compute
sudo virsh -c qemu:///system define --file node5-compute
+ rm -f node1-control node2-compute node5-compute
maas $PROFILE machines create autodetect_nodegroup='yes' name='node1-control' \
# Add the cloud and controller credentials for MAAS for that lab.
jujuver=`juju --version`
-if [ "$jujuver" > "2" ]; then
+if [[ "$jujuver" > "2" ]]; then
addcloud
addcredential
fi
#by default maas creates two VMs in case of three more VM needed.
createresource() {
- maas_ip=`grep " ip_address" deployconfig.yaml | cut -d " " -f 10`
- apikey=`grep maas-oauth: environments.yaml | cut -d "'" -f 2`
- maas login maas http://${maas_ip}/MAAS/api/1.0 ${apikey}
-
- nodeexist=`maas maas nodes list hostname=node3-control`
-
- if [ $nodeexist != *node3* ]; then
- sudo virt-install --connect qemu:///system --name node3-control --ram 8192 --cpu host --vcpus 4 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default --network bridge=virbr0,model=virtio --network bridge=virbr0,model=virtio --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node3-control
-
- sudo virt-install --connect qemu:///system --name node4-control --ram 8192 --cpu host --vcpus 4 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default --network bridge=virbr0,model=virtio --network bridge=virbr0,model=virtio --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node4-control
-
- node3controlmac=`grep "mac address" node3-control | head -1 | cut -d "'" -f 2`
- node4controlmac=`grep "mac address" node4-control | head -1 | cut -d "'" -f 2`
-
- sudo virsh -c qemu:///system define --file node3-control
- sudo virsh -c qemu:///system define --file node4-control
-
- controlnodeid=`maas maas nodes new autodetect_nodegroup='yes' name='node3-control' tags='control' hostname='node3-control' power_type='virsh' mac_addresses=$node3controlmac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node3-control' | grep system_id | cut -d '"' -f 4 `
-
- maas maas tag update-nodes control add=$controlnodeid
-
- controlnodeid=`maas maas nodes new autodetect_nodegroup='yes' name='node4-control' tags='control' hostname='node4-control' power_type='virsh' mac_addresses=$node4controlmac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node4-control' | grep system_id | cut -d '"' -f 4 `
-
- maas maas tag update-nodes control add=$controlnodeid
-
- fi
+ # TODO: make sure this function run with the same parameters used in 03-maasdeploy.sh
+ PROFILE=${PROFILE:-ubuntu}
+ MAAS_IP=$(grep " ip_address" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //')
+ API_SERVER="http://$MAAS_IP/MAAS/api/2.0"
+ API_KEY=`sudo maas-region apikey --username=ubuntu`
+ maas login $PROFILE $API_SERVER $API_KEY
+
+ for node in node3-control node4-control
+ do
+ node_id=$(maas $PROFILE machines read | \
+ jq -r "select(.[].hostname == \"$node\")[0].system_id")
+ if [[ -z "$node_id" ]]; then
+ sudo virt-install --connect qemu:///system --name $node \
+ --ram 8192 --cpu host --vcpus 4 \
+ --disk size=120,format=qcow2,bus=virtio,io=native,pool=default \
+ --network bridge=virbr0,model=virtio \
+ --network bridge=virbr0,model=virtio \
+ --boot network,hd,menu=off \
+ --noautoconsole --vnc --print-xml | tee _node.xml
+ node_mac=$(grep "mac address" _node.xml | head -1 | cut -d "'" -f 2)
+ sudo virsh -c qemu:///system define --file _node.xml
+ rm -f _node.xml
+
+ maas $PROFILE nodes new autodetect_nodegroup='yes' name=$node \
+ tags='control' hostname=$name power_type='virsh' \
+ mac_addresses=$node3controlmac \
+ power_parameters_power_address="qemu+ssh://$USER@192.168.122.1/system" \
+ architecture='amd64/generic' power_parameters_power_id='node3-control'
+ node_id=$(maas $PROFILE machines read | \
+ jq -r "select(.[].hostname == \"$node\")[0].system_id")
+ fi
+ if [[ -z "$node_id" ]]; then
+ echo "Error: failed to create node $node ."
+ exit 1
+ fi
+ maas $PROFILE tag update-nodes control add=$node_id || true
+ done
}
#copy the files and create extra resources needed for HA deployment
check_status() {
retval=0
timeoutiter=0
+
+ echo -n "executing the reltionship within charms ."
while [ $retval -eq 0 ]; do
sleep 30
- juju status > status.txt
- if [ "$(grep -c "executing" status.txt )" -ge 1 ]; then
- echo " still executing the reltionship within charms ..."
+ if juju status | grep -q "executing"; then
+ echo -n '.'
if [ $timeoutiter -ge 120 ]; then
+ echo 'timed out'
retval=1
fi
timeoutiter=$((timeoutiter+1))
else
+ echo 'done'
retval=1
fi
done