OpenStack/Neutron integration for Calico networking
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bootstrap.sh 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/bin/bash
  2. # Copyright 2015 Metaswitch Networks
  3. # All Rights Reserved.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. # not use this file except in compliance with the License. You may obtain
  7. # a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. # License for the specific language governing permissions and limitations
  15. # under the License.
  16. set -ex
  17. #------------------------------------------------------------------------------
  18. # IMPORTANT - Review before use!
  19. #
  20. # This script can be used to bootstrap a single or multi-node Calico/DevStack
  21. # cluster. Please note that it has not been exhaustively reviewed or tested
  22. # for safety, and is designed for use on a fresh Ubuntu Trusty VM, with no data
  23. # that you would care about losing. We recommend that you review the following
  24. # code, before running the script.
  25. #------------------------------------------------------------------------------
  26. #------------------------------------------------------------------------------
  27. # Environment Variables
  28. #
  29. # SERVICE_HOST
  30. #
  31. # If the SERVICE_HOST environment variable is already set when ./stack.sh
  32. # is run, and is _different_ from the local machine's hostname, the
  33. # networking-calico DevStack plugin will interpret that as a request to set
  34. # up a compute-only node, that points to $SERVICE_HOST as its controller.
  35. #
  36. # On the other hand, if SERVICE_HOST is not set, or is the _same_ as the
  37. # local hostname, the plugin will set up a combined controller and compute
  38. # node.
  39. #
  40. # Therefore, to bring up a multi-node Calico/DevStack cluster, set and
  41. # export SERVICE_HOST in the environment, to the hostname for the chosen
  42. # controller node in your cluster, before invoking this script.
  43. #
  44. # For a single node Calico/DevStack cluster, the environment should leave
  45. # SERVICE_HOST unset.
  46. #
  47. # TEST_GERRIT_CHANGE
  48. #
  49. # By default this script uses the master branch of networking-calico. To
  50. # test a networking-calico change in Gerrit that hasn't yet been merged to
  51. # master, set the TEST_GERRIT_CHANGE environment variable to indicate that
  52. # change, before running this script; for example:
  53. #
  54. # export TEST_GERRIT_CHANGE=219646/1
  55. #
  56. # DEVSTACK_BRANCH
  57. #
  58. # By default this script uses the master branch of devstack. To use a
  59. # different branch, set the DEVSTACK_BRANCH environment variable before
  60. # running this script; for example:
  61. #
  62. # export DEVSTACK_BRANCH=stable/liberty
  63. # ------------------------------------------------------------------------------
  64. # Assume that we are starting from the home directory of a non-root
  65. # user that can sudo, and hence is suitable for running DevStack. For
  66. # example, the 'ubuntu' user on Ubuntu.
  67. cd
  68. # Create a directory for Calico stuff.
  69. mkdir -p calico
  70. cd calico
  71. # Ensure that Git is installed.
  72. sudo apt-get update
  73. sudo apt-get -y install git
  74. # Prepare networking-calico tree - the following lines will check out
  75. # the master branch of networking-calico (if not already present).
  76. test -e networking-calico || \
  77. git clone https://git.openstack.org/openstack/networking-calico
  78. cd networking-calico
  79. # If TEST_GERRIT_CHANGE has been specified, merge that change from Gerrit.
  80. if [ -n "$TEST_GERRIT_CHANGE" ]; then
  81. git fetch https://review.openstack.org/openstack/networking-calico \
  82. refs/changes/${TEST_GERRIT_CHANGE:4:2}/${TEST_GERRIT_CHANGE}
  83. git checkout FETCH_HEAD
  84. git checkout -b devstack-test
  85. git checkout master
  86. git config user.name "someone"
  87. git config user.email "someone@someplace.com"
  88. git merge --no-edit devstack-test
  89. fi
  90. # Remember the current directory.
  91. ncdir=`pwd`
  92. cd ..
  93. # Enable IPv4 and IPv6 forwarding.
  94. sudo sysctl -w net.ipv4.ip_forward=1
  95. sudo sysctl -w net.ipv6.conf.all.forwarding=1
  96. # Clone the DevStack repository (if not already present).
  97. test -e devstack || \
  98. git clone https://git.openstack.org/openstack-dev/devstack
  99. cd devstack
  100. # If DEVSTACK_BRANCH has been specified, check out that branch. (Otherwise we
  101. # use DevStack's master branch.)
  102. if [ -n "$DEVSTACK_BRANCH" ]; then
  103. git checkout ${DEVSTACK_BRANCH}
  104. fi
  105. # Prepare DevStack config.
  106. cat > local.conf <<EOF
  107. [[local|localrc]]
  108. SERVICE_HOST=${SERVICE_HOST:-$HOSTNAME}
  109. ADMIN_PASSWORD=015133ea2bdc46ed434c
  110. DATABASE_PASSWORD=d0060b07d3f3631ece78
  111. RABBIT_PASSWORD=6366743536a8216bde26
  112. SERVICE_PASSWORD=91eb72bcafb4ddf246ab
  113. SERVICE_TOKEN=c5680feca5e2c9c8f820
  114. enable_plugin networking-calico $ncdir
  115. disable_service tempest
  116. # Devstack by default creates an initial Neutron network topology for VMs to
  117. # attach to: a private tenant network, an external public network, and a
  118. # Neutron router connecting these; and then VMs are attached to the tenant
  119. # network. This setup works fine with the Calico driver, and it is the setup
  120. # that - for example - Tempest testing expects. But for a first demonstration
  121. # of Calico we prefer to use a simpler setup with only a public provider
  122. # network: shared and with a 'local' network_type but no segmentation ID. So
  123. # for that demonstration we tell Devstack not to create those initial networks,
  124. # and instead create a provider network with the 'neutron net-create' and
  125. # 'neutron subnet-create' invocations below.
  126. NEUTRON_CREATE_INITIAL_NETWORKS=False
  127. LOGFILE=stack.log
  128. LOG_COLOR=False
  129. EOF
  130. # Stack!
  131. ./stack.sh
  132. # If we're on the controller node, create a Calico network.
  133. if [ x${SERVICE_HOST:-$HOSTNAME} = x$HOSTNAME ]; then
  134. . openrc admin admin
  135. neutron net-create --shared --provider:network_type local calico
  136. neutron subnet-create --gateway 10.65.0.1 --enable-dhcp --ip-version 4 --name calico-v4 calico 10.65.0.0/24
  137. fi