Script support for DevStack Configuration. 00/6800/3
authorThomas Bachman <tbachman@yahoo.com>
Fri, 16 May 2014 06:53:06 +0000 (06:53 +0000)
committerThomas Bachman <tbachman@yahoo.com>
Fri, 16 May 2014 06:56:33 +0000 (06:56 +0000)
Addition of several scripts that are helpful for DevStack
environment setup.

Signed-off-by: Thomas Bachman <tbachman@yahoo.com>
Change-Id: Ibe87275fed5199557996b3de4e3d30ade7f523e1

resources/openstack/README
resources/openstack/bootvm.sh [new file with mode: 0755]
resources/openstack/dsconf.sh [new file with mode: 0755]
resources/openstack/make-vxlan-net.sh [new file with mode: 0755]
resources/openstack/pingvm.sh [new file with mode: 0755]
resources/openstack/sethostname.sh [new file with mode: 0755]

index 10c0f3e529117aba4ae3fc18e8b4d83019206616..d2fa6ceecba2e287ea173ff46bb26d9140740877 100644 (file)
@@ -16,3 +16,13 @@ Contents
 3. local.conf.compute : A sample development local.conf used on the devstack Compute node with Neutron ML2 mechanism driver for OpenDaylight.  
 
 4. DevStack.json.postman_collection : Relevant POSTMAN OpenDaylight REST-APIs that can be used for testing Openstack / Devstack deployments.
+
+5. dsconf.sh : Menu-driven script to create a local.conf, based on DevStack node configuration/need
+
+6. sethostname.sh : script to set the hostname (/etc/hosts, /etc/hostname, and "hostname" command)
+
+7. bootvm.sh : script to boot a VM from DevStack controller (requires . ./openrc admin admin)
+
+8. pingvm.sh : script to ping a VM from DevStack controller (requires . ./openrc admin admin)
+
+9. make-vxlan-net.sh : script to create a Neutron network and subnet using VXLAN tunnels (requires . ./openrc admin admin)
diff --git a/resources/openstack/bootvm.sh b/resources/openstack/bootvm.sh
new file mode 100755 (executable)
index 0000000..526ee8a
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/sh
+#
+# Copyright (C) 2013 Cisco Systems, Inc.
+#
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0 which accompanies this distribution,
+# and is available at http://www.eclipse.org/legal/epl-v10.html
+#
+# Authors : Thomas Bachman
+
+#
+# Script for booting VMs onto networks
+#
+
+#defaults
+vm=`hostname`
+net=private
+image=cirros-0.3.1-x86_64-uec
+
+nova hypervisor-list
+echo -n "Enter the hypervisor name to use for new instance [$vm]: "
+read -a entry
+if [ "$entry" != "" ]; then
+    vm=$entry
+fi
+
+neutron net-list
+echo -n "Enter the name of the network to use for the VM [$net]: "
+read -a entry
+if [ "$entry" != "" ]; then
+    net=$entry
+fi
+
+nova image-list
+echo -n "Enter the name of the image to use for the VM [$image]: "
+read -a entry
+if [ "$entry" != "" ]; then
+    image=$entry
+fi
+
+nova boot --flavor m1.tiny --image $(nova image-list | grep "$image\s" | awk '{print $2}') --nic net-id=$(neutron net-list | grep $net | awk '{print $2}') admin-private --availability_zone=nova:$vm
diff --git a/resources/openstack/dsconf.sh b/resources/openstack/dsconf.sh
new file mode 100755 (executable)
index 0000000..b85bab1
--- /dev/null
@@ -0,0 +1,368 @@
+#!/bin/sh
+#
+# Copyright (C) 2013 Cisco Systems, Inc.
+#
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0 which accompanies this distribution,
+# and is available at http://www.eclipse.org/legal/epl-v10.html
+#
+# Authors : Thomas Bachman
+
+#
+# Generate the local.conf, based on this machine's settings,
+# and user input
+#
+
+odl_ip=""
+odl_in_ds="y"
+vm_personality="ODC"
+active_ifs=""
+service_host=""
+service_host_name=""
+odl_mgr_ip=""
+host_ip=""
+host_name=`hostname`
+host_list=""
+
+# Minimum memory requirements, in kB
+od_mem=50000000
+oc_mem=3000000
+o_mem=2000000
+odoc_mem=5000000
+oco_mem=3000000
+
+
+
+#
+# personality-dependent services
+#
+ds_common_services="qpid neutron odl-compute n-cpu"
+ds_compute_services="nova n-novnc"
+ds_controller_services="n-cond q-svc q-dhcp q-l3 q-meta tempest"
+
+#
+# everyone gets these services
+#
+services=$ds_common_services
+
+#
+# services that are disabled
+#
+disabled_services="rabbit n-net"
+
+header='''
+LOGFILE=stack.sh.log\n
+#SCREEN_LOGDIR=/opt/stack/data/log\n
+#LOG_COLOR=False\n
+OFFLINE=True\n
+#RECLONE=yes\n
+\n
+'''
+
+#
+# single quoted to prevent variable substitutions
+#
+# add host info
+
+footer='''
+Q_HOST=$SERVICE_HOST\n
+Q_PLUGIN=ml2\n
+Q_ML2_PLUGIN_MECHANISM_DRIVERS=opendaylight,logger\n
+ENABLE_TENANT_TUNNELS=True\n
+ODL_BOOT_WAIT=70\n
+\n
+VNCSERVER_PROXYCLIENT_ADDRESS=${HOST_IP}\n
+VNCSERVER_LISTEN=0.0.0.0\n
+\n
+#FLOATING_RANGE=192.168.210.0/24\n
+#PUBLIC_NETWORK_GATEWAY=192.168.75.254\n
+MYSQL_HOST=$SERVICE_HOST\n
+RABBIT_HOST=$SERVICE_HOST\n
+GLANCE_HOSTPORT=$SERVICE_HOST:9292\n
+KEYSTONE_AUTH_HOST=$SERVICE_HOST\n
+KEYSTONE_SERVICE_HOST=$SERVICE_HOST\n
+\n
+MYSQL_PASSWORD=mysql\n
+RABBIT_PASSWORD=rabbit\n
+QPID_PASSWORD=rabbit\n
+SERVICE_TOKEN=service\n
+SERVICE_PASSWORD=admin\n
+ADMIN_PASSWORD=admin\n
+\n
+[[post-config|/etc/neutron/plugins/ml2/ml2_conf.ini]]\n
+[agent]\n
+minimize_polling=True\n
+'''
+
+#
+# Create a list of active network interfaces
+#
+get_active_ifs()
+{
+   all_ifs=`egrep 'ONBOOT' /etc/sysconfig/network-scripts/ifcfg-*`
+   for interface in $all_ifs
+   do
+       active=`echo $interface | awk 'BEGIN {FS="="} {print $2}'`
+       if [ "$active" == "yes" ]; then
+           file=`echo $interface | awk 'BEGIN {FS=":"} {print $1}'`
+           intf=`basename $file | awk 'BEGIN {FS="-"} {print $2}'`
+           active_ifs=`echo "$active_ifs $intf"`
+       fi
+   done
+}
+
+#
+# Have the user select the IP address to use
+#
+select_host_ip()
+{
+    get_active_ifs
+    echo "Your system has the following IP addresses: "
+    count=0
+    if_index="0"
+    for interface in $active_ifs
+    do
+        if [ "$interface" == "lo" ]; then
+            continue;
+        fi
+        exists=`ifconfig | grep $interface`
+        if [ "$exists" == "" ]; then
+            continue;
+        fi
+        ip=`ifconfig $interface | grep 'inet ' | awk 'BEGIN {FS=" "} {print $2}'`
+        echo "    [$count] $interface: $ip"
+        let "count+=1";
+    done
+
+    entry=$if_index
+    if [ $count == 0 ]; then
+        echo "No active interfaces: please reconfigure /etc/sysconfig/network-scripts/ifcfg-<interface> and re-run"
+        exit
+    elif [ $count > 1 ]; then
+        echo -n "Select which interface to use [$entry]: "
+        read -a entry
+        if [ "$entry" > "$count" ]; then
+            let "maxcnt=count-1"
+            echo "Invalid entry, must be less than $maxcnt"
+            exit
+        elif [ "$entry" == "" ]; then
+            entry=$if_index
+        else
+            $if_index=$entry
+        fi
+    fi
+
+    count=0
+    for interface in $active_ifs
+    do
+        if [ $count == $if_index ]; then
+            #echo "foo"
+            host_ip=`ifconfig $interface | grep 'inet ' | awk 'BEGIN {FS=" "} {print $2}'`
+            break;
+        fi
+        let "count+=1"
+    done
+}
+
+#
+#  Verify the memory is sufficient for the configuration
+#
+check_mem()
+{
+    memory=`cat /proc/meminfo  | grep MemTotal | awk 'BEGIN {FS=" "} {print $2}'`
+    if [ "$vm_personality" == "O" ]; then
+        mem_needed=$od_mem
+    elif [ "$vm_personality" == "DC" ]; then
+        mem_needed=$oc_mem
+    elif [ "$vm_personality" == "D" ]; then
+        mem_needed=$o_mem
+    elif [ "$vm_personality" == "ODC" ]; then
+        mem_needed=$odoc_mem
+    elif [ "$vm_personality" == "DCD" ]; then
+        mem_needed=$oco_mem
+    fi
+    if [ "$memory" -lt "$mem_needed" ]; then
+        echo """
+             $vm_personality configurations require at least $mem_needed (have $memory).
+             Please shutdown the VM and reconfigure its memory
+             """
+        exit
+    fi
+}
+
+echo """
+   This script configures the local.conf for the
+   VM, based on the desired configuration.  The
+   VM can take on any of the following roles:
+
+       O:    OpenDaylight Controller.
+               In this role, the VM is only responsible
+               for running the OpenDaylight Controller
+
+       DC:   DevStack Controller.
+               In this role, the VM is only responsible
+               for running the DevStack controller.
+
+       D:    DevStack Compute. In this role,
+               the VM is only responsible for
+               running the DevStack compute.
+
+       ODC:  OpenDaylight Controller with DevStack Controller.
+               In this role, the VM runs both the OpenDaylight
+               controller and the DevStack controller. The
+               OpenDaylight controller is launched by DevStack.
+
+       DCD:  DevStack Controller with DevStack Compute.
+               In this role, the VM acts as both an DevStack
+               controller and compute node.
+"""
+
+echo -n "Enter VM's personality [$vm_personality]: "
+read -a entry
+if [ "$entry" == "" ]; then
+    entry=$vm_personality
+else
+    vm_personality=$entry
+fi
+if [ "$vm_personality" != "O" ] &&
+   [ "$vm_personality" != "DC" ] &&
+   [ "$vm_personality" != "D" ]  &&
+   [ "$vm_personality" != "ODC" ]  &&
+   [ "$vm_personality" != "DCD" ]; then
+    echo "$vm_personality is invalid"
+    exit;
+fi
+
+# For all nodes, run the memory check to make
+# sure they've allocated enough memory to
+# run the system.
+check_mem
+
+# Get the right IP
+select_host_ip
+
+service_host=$host_ip
+service_host_name=$host_name
+
+# For a combined ODL/DS coontroller, we still need
+# to add in the services
+if [ "$vm_personality" == "ODC" ]; then
+   services="$services $ds_controller_services odl-server"
+fi
+
+# For all pure DS nodes (no ODL -- DS controller, compute, or both),
+# we need to point it to the ODL Controller
+if [ "$vm_personality" == "D" ] ||
+   [ "$vm_personality" == "DC" ] ||
+   [ "$vm_personality" == "DCD" ]; then
+   if [ "$vm_personality" == "D" ]; then
+      services="$services $ds_compute_services"
+   else
+      services="$services $ds_controller_services"
+   fi
+   service_host=$host_ip
+   service_host_name=$host_name
+   echo """
+           DevStack nodes need to point to the OpenDaylight Controller.
+           Please provide the IP address of the OpenDaylight Controller.
+        """
+   echo -n "OpenDaylight Controller IP: "
+   read -a odl_ip
+fi
+
+
+#
+# For DS Compute Only, we need to point it to
+# the DS Controller and update the DS services
+if [ "$vm_personality" == "D" ]; then
+   services="$services $ds_compute_services"
+   echo """
+           DevStack Compute nodes need to point to the DevStack
+           Controller. Please provide the IP address and hostname
+           of the DevStack Controller
+        """
+   echo -n "DevStack Controller IP: "
+   read -a service_host
+   echo -n "DevStack Controller hostname: "
+   read -a service_host_name
+   if [ "$service_host_name" == "$host_name" ]; then
+       echo """
+               Note: You have configured the DevStack controller's
+                     with the same name as this host. If this host
+                     requires a name change, run the set_hostname.sh
+                     script before running this one.
+            """
+   fi
+   echo """
+           DevStack Compute nodes also need to point to the
+           OpenDaylight Controller. Please provide the IP address
+           of the OpenDaylight Controller
+        """
+
+   # for DS compute, keep track of service host
+   host_list=$service_host_name
+fi
+
+######
+# Generate local.conf, using parameters
+######
+echo "[[local|localrc]]" > local.conf
+
+#
+#  Header
+#
+echo -e $header | while read -r line
+do
+    echo -e $line >> local.conf
+done
+
+#
+# Services
+#
+# disable all services for compute only nodes
+if [ "$vm_personality" == "D" ]; then
+   echo "disable_all_services" >> local.conf
+fi
+
+for line in $disabled_services
+do
+   echo "disable_service $line" >> local.conf
+done
+
+for line in $services
+do
+   echo -e "enable_service $line" >> local.conf
+done
+echo -e "\n" >> local.conf
+
+
+
+#
+# Add in VM-specific parameters
+#
+echo "HOST_IP=$host_ip" >> local.conf
+echo "HOST_NAME=$host_name" >> local.conf
+echo "SERVICE_HOST=$service_host" >> local.conf
+echo "SERVICE_HOST_NAME=$service_host_name" >> local.conf
+if [ "$vm_personality" != "O" ] &&
+   [ "$vm_personality" != "ODC" ]; then
+    echo "ODL_MGR_IP=$odl_ip" >> local.conf
+fi
+
+
+#
+# Footer
+#
+echo -e $footer | while read -r line
+do
+    echo -e $line >> local.conf
+done
+
+
+if [ "$host_list" != "" ]; then
+    echo "*********************************************************"
+    echo "===========>>>> Be sure to add $host_list to /etc/hosts!"
+    echo "*********************************************************"
+fi
+
+
diff --git a/resources/openstack/make-vxlan-net.sh b/resources/openstack/make-vxlan-net.sh
new file mode 100755 (executable)
index 0000000..f4cdc6f
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/sh
+#
+# Copyright (C) 2013 Cisco Systems, Inc.
+#
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0 which accompanies this distribution,
+# and is available at http://www.eclipse.org/legal/epl-v10.html
+#
+# Authors : Thomas Bachman
+
+#
+# Create a neutron network and subnet for VXLAN (hard-coded)
+#
+
+neutron net-create vxlan-net --tenant_id  $(keystone tenant-list | grep '\sadmin' | awk '{print $2}') --provider:network_type vxlan --provider:segmentation_id 1300
+neutron  subnet-create vxlan-net 10.100.1.0/24 --name vxlan-net
diff --git a/resources/openstack/pingvm.sh b/resources/openstack/pingvm.sh
new file mode 100755 (executable)
index 0000000..c9fdacd
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# Copyright (C) 2013 Cisco Systems, Inc.
+#
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0 which accompanies this distribution,
+# and is available at http://www.eclipse.org/legal/epl-v10.html
+#
+# Authors : Thomas Bachman
+
+
+#
+# Ping an instance created by DevStack
+#
+
+# get the prefix
+ip=$1
+uuid=`neutron net-list | grep $(echo $ip | awk 'BEGIN {FS="."} {print $1 "." $2 "." $3}') | awk '{print $2}'`
+dhcp_server="qdhcp-$uuid"
+foo="ip netns exec $dhcp_server ping $ip"
+sudo $foo
diff --git a/resources/openstack/sethostname.sh b/resources/openstack/sethostname.sh
new file mode 100755 (executable)
index 0000000..db1c54c
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash
+#
+# Copyright (C) 2013 Cisco Systems, Inc.
+#
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0 which accompanies this distribution,
+# and is available at http://www.eclipse.org/legal/epl-v10.html
+#
+# Authors : Thomas Bachman
+
+#
+#  Set the hostname
+#
+currname=`cat /etc/hostname`
+echo "Current hostname: $currname"
+
+echo -n "Enter new hostname: "
+read -a newname
+
+#
+# Update /etc/hosts & /etc/hostname with new hostname
+#
+if [ "$newname" != "$currname" ]; then
+    res=`sed -i "s/$currname/$newname/g" /etc/hosts`
+    if [ $? -ne 0 ]; then
+        echo "failed to update /etc/hosts"
+    fi
+    res=`sed -i "s/$currname/$newname/g" /etc/hostname`
+    if [ $? -ne 0 ]; then
+        echo "failed to update /etc/hostname"
+    fi
+    res=`hostname $newname`
+    if [ $? -ne 0 ]; then
+        echo "failed to update hostname"
+    else
+        echo "Your new hostname is $newname"
+    fi
+else
+    echo "hostname already set to $newname"
+fi