| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 1 | # lib/opendaylight | 
|  | 2 | # Functions to control the configuration and operation of the opendaylight service | 
|  | 3 |  | 
|  | 4 | # Dependencies: | 
|  | 5 | # | 
|  | 6 | # - ``functions`` file | 
|  | 7 | # # ``DEST`` must be defined | 
|  | 8 | # # ``STACK_USER`` must be defined | 
|  | 9 |  | 
|  | 10 | # ``stack.sh`` calls the entry points in this order: | 
|  | 11 | # | 
|  | 12 | # - is_opendaylight_enabled | 
|  | 13 | # - is_opendaylight-compute_enabled | 
|  | 14 | # - install_opendaylight | 
|  | 15 | # - install_opendaylight-compute | 
|  | 16 | # - configure_opendaylight | 
|  | 17 | # - init_opendaylight | 
|  | 18 | # - start_opendaylight | 
|  | 19 | # - stop_opendaylight-compute | 
|  | 20 | # - stop_opendaylight | 
|  | 21 | # - cleanup_opendaylight | 
|  | 22 |  | 
|  | 23 | # Save trace setting | 
|  | 24 | XTRACE=$(set +o | grep xtrace) | 
|  | 25 | set +o xtrace | 
|  | 26 |  | 
|  | 27 |  | 
|  | 28 | # For OVS_BRIDGE and PUBLIC_BRIDGE | 
|  | 29 | source $TOP_DIR/lib/neutron_plugins/ovs_base | 
|  | 30 |  | 
|  | 31 | # Defaults | 
|  | 32 | # -------- | 
|  | 33 |  | 
|  | 34 | # The IP address of ODL. Set this in local.conf. | 
|  | 35 | # ODL_MGR_IP= | 
|  | 36 | ODL_MGR_IP=${ODL_MGR_IP:-$SERVICE_HOST} | 
|  | 37 |  | 
|  | 38 | # <define global variables here that belong to this project> | 
|  | 39 | ODL_DIR=$DEST/opendaylight | 
|  | 40 |  | 
|  | 41 | # The OpenDaylight Package, currently using 'Hydrogen' release | 
|  | 42 | ODL_PKG=${ODL_PKG:-distributions-virtualization-0.1.1-osgipackage.zip} | 
|  | 43 |  | 
|  | 44 | # The OpenDaylight URL | 
|  | 45 | ODL_URL=${ODL_URL:-https://nexus.opendaylight.org/content/repositories/opendaylight.release/org/opendaylight/integration/distributions-virtualization/0.1.1} | 
|  | 46 |  | 
|  | 47 | # Default arguments for OpenDaylight. This is typically used to set | 
|  | 48 | # Java memory options. | 
|  | 49 | #   ODL_ARGS=Xmx1024m -XX:MaxPermSize=512m | 
|  | 50 | ODL_ARGS=${ODL_ARGS:-"-XX:MaxPermSize=384m"} | 
|  | 51 |  | 
|  | 52 | # How long to pause after ODL starts to let it complete booting | 
|  | 53 | ODL_BOOT_WAIT=${ODL_BOOT_WAIT:-60} | 
|  | 54 |  | 
|  | 55 | # Set up default directories | 
|  | 56 |  | 
|  | 57 |  | 
|  | 58 | # Entry Points | 
|  | 59 | # ------------ | 
|  | 60 |  | 
|  | 61 | # Test if OpenDaylight is enabled | 
|  | 62 | # is_opendaylight_enabled | 
|  | 63 | function is_opendaylight_enabled { | 
|  | 64 | [[ ,${ENABLED_SERVICES} =~ ,"odl-" ]] && return 0 | 
|  | 65 | return 1 | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | # cleanup_opendaylight() - Remove residual data files, anything left over from previous | 
|  | 69 | # runs that a clean run would need to clean up | 
|  | 70 | function cleanup_opendaylight { | 
|  | 71 | : | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | # configure_opendaylight() - Set config files, create data dirs, etc | 
|  | 75 | function configure_opendaylight { | 
|  | 76 | # Remove simple forwarder | 
|  | 77 | rm -f $ODL_DIR/opendaylight/plugins/org.opendaylight.controller.samples.simpleforwarding* | 
|  | 78 |  | 
|  | 79 | # Configure OpenFlow 1.3 | 
|  | 80 | echo "ovsdb.of.version=1.3" >> $ODL_DIR/opendaylight/configuration/config.ini | 
|  | 81 | } | 
|  | 82 |  | 
|  | 83 | # init_opendaylight() - Initialize databases, etc. | 
|  | 84 | function init_opendaylight { | 
|  | 85 | # clean up from previous (possibly aborted) runs | 
|  | 86 | # create required data files | 
|  | 87 | : | 
|  | 88 | } | 
|  | 89 |  | 
|  | 90 | # install_opendaylight() - Collect source and prepare | 
|  | 91 | function install_opendaylight { | 
|  | 92 | local _pwd=$(pwd) | 
|  | 93 |  | 
|  | 94 | if is_ubuntu; then | 
|  | 95 | install_package maven openjdk-7-jre openjdk-7-jdk | 
|  | 96 | else | 
|  | 97 | yum_install maven java-1.7.0-openjdk | 
|  | 98 | fi | 
|  | 99 |  | 
|  | 100 | # Download OpenDaylight | 
|  | 101 | mkdir -p $ODL_DIR | 
|  | 102 | cd $ODL_DIR | 
|  | 103 | wget -N $ODL_URL/$ODL_PKG | 
|  | 104 | unzip -u $ODL_PKG | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 | # install_opendaylight-compute - Make sure OVS is install | 
|  | 108 | function install_opendaylight-compute { | 
|  | 109 | local kernel_version | 
|  | 110 | # Install deps | 
|  | 111 | # FIXME add to ``files/apts/neutron``, but don't install if not needed! | 
|  | 112 | if is_ubuntu; then | 
|  | 113 | kernel_version=`cat /proc/version | cut -d " " -f3` | 
|  | 114 | install_package make fakeroot dkms openvswitch-switch openvswitch-datapath-dkms linux-headers-$kernel_version | 
|  | 115 | elif is_fedora; then | 
|  | 116 | install_package openvswitch | 
|  | 117 | # Ensure that the service is started | 
|  | 118 | restart_service openvswitch | 
|  | 119 | elif is_suse; then | 
|  | 120 | install_package openvswitch | 
|  | 121 | restart_service openvswitch-switch | 
|  | 122 | restart_service openvswitch-controller | 
|  | 123 | fi | 
|  | 124 | } | 
|  | 125 |  | 
|  | 126 | # start_opendaylight() - Start running processes, including screen | 
|  | 127 | function start_opendaylight { | 
|  | 128 | if is_ubuntu; then | 
|  | 129 | JHOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64 | 
|  | 130 | else | 
|  | 131 | JHOME=/usr/lib/jvm/java-1.7.0-openjdk | 
|  | 132 | fi | 
|  | 133 |  | 
|  | 134 | # The flags to ODL have the following meaning: | 
|  | 135 | #   -of13: runs ODL using OpenFlow 1.3 protocol support. | 
|  | 136 | #   -virt ovsdb: Runs ODL in "virtualization" mode with OVSDB support | 
|  | 137 | screen_it odl-server "cd $ODL_DIR/opendaylight && JAVE_HOME=$JHOME ./run.sh $ODL_ARGS -of13 -virt ovsdb" | 
|  | 138 |  | 
|  | 139 | # Sleep a bit to let OpenDaylight finish starting up | 
|  | 140 | sleep $ODL_BOOT_WAIT | 
|  | 141 | } | 
|  | 142 |  | 
|  | 143 | # stop_opendaylight() - Stop running processes (non-screen) | 
|  | 144 | function stop_opendaylight { | 
|  | 145 | screen_stop odl-server | 
|  | 146 | } | 
|  | 147 |  | 
|  | 148 | # stop_opendaylight-compute() - Remove OVS bridges | 
|  | 149 | function stop_opendaylight-compute { | 
|  | 150 | # remove all OVS ports that look like Neutron created ports | 
|  | 151 | for port in $(sudo ovs-vsctl list port | grep -o -e tap[0-9a-f\-]* -e q[rg]-[0-9a-f\-]*); do | 
|  | 152 | sudo ovs-vsctl del-port ${port} | 
|  | 153 | done | 
|  | 154 |  | 
|  | 155 | # remove all OVS bridges created by Neutron | 
|  | 156 | for bridge in $(sudo ovs-vsctl list-br | grep -o -e ${OVS_BRIDGE} -e ${PUBLIC_BRIDGE}); do | 
|  | 157 | sudo ovs-vsctl del-br ${bridge} | 
|  | 158 | done | 
|  | 159 | } | 
|  | 160 |  | 
|  | 161 | # Restore xtrace | 
|  | 162 | $XTRACE | 
|  | 163 |  | 
|  | 164 | # Tell emacs to use shell-script-mode | 
|  | 165 | ## Local variables: | 
|  | 166 | ## mode: shell-script | 
|  | 167 | ## End: |