Container Infrastructure Management Service for OpenStack
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.

network-config-service.sh 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/sh
  2. . /etc/sysconfig/heat-params
  3. echo "Configuring ${NETWORK_DRIVER} network ..."
  4. if [ "$NETWORK_DRIVER" != "flannel" ]; then
  5. exit 0
  6. fi
  7. FLANNELD_CONFIG=/etc/sysconfig/flanneld
  8. FLANNEL_CONFIG_BIN=/usr/local/bin/flannel-config
  9. FLANNEL_CONFIG_SERVICE=/etc/systemd/system/flannel-config.service
  10. FLANNEL_JSON=/etc/sysconfig/flannel-network.json
  11. CERT_DIR=/etc/docker
  12. PROTOCOL=https
  13. FLANNEL_OPTIONS="-etcd-cafile $CERT_DIR/ca.crt \
  14. -etcd-certfile $CERT_DIR/server.crt \
  15. -etcd-keyfile $CERT_DIR/server.key"
  16. ETCD_CURL_OPTIONS="--cacert $CERT_DIR/ca.crt \
  17. --cert $CERT_DIR/server.crt --key $CERT_DIR/server.key"
  18. if [ "$TLS_DISABLED" = "True" ]; then
  19. PROTOCOL=http
  20. FLANNEL_OPTIONS=""
  21. ETCD_CURL_OPTIONS=""
  22. fi
  23. sed -i '
  24. /^FLANNEL_ETCD=/ s|=.*|="'"$PROTOCOL"'://'"$ETCD_SERVER_IP"':2379"|
  25. ' $FLANNELD_CONFIG
  26. sed -i '/FLANNEL_OPTIONS/'d $FLANNELD_CONFIG
  27. cat >> $FLANNELD_CONFIG <<EOF
  28. FLANNEL_OPTIONS="$FLANNEL_OPTIONS"
  29. EOF
  30. . $FLANNELD_CONFIG
  31. echo "creating $FLANNEL_CONFIG_BIN"
  32. cat > $FLANNEL_CONFIG_BIN <<EOF
  33. #!/bin/sh
  34. if ! [ -f "$FLANNEL_JSON" ]; then
  35. echo "ERROR: missing network configuration file" >&2
  36. exit 1
  37. fi
  38. if ! [ "$FLANNEL_ETCD" ] && [ "$FLANNEL_ETCD_KEY" ]; then
  39. echo "ERROR: missing required configuration" >&2
  40. exit 1
  41. fi
  42. echo "creating flanneld config in etcd"
  43. while ! curl -sf -L $ETCD_CURL_OPTIONS \
  44. $FLANNEL_ETCD/v2/keys${FLANNEL_ETCD_KEY}/config \
  45. -X PUT --data-urlencode value@${FLANNEL_JSON}; do
  46. echo "waiting for etcd"
  47. sleep 1
  48. done
  49. EOF
  50. cat > $FLANNEL_CONFIG_SERVICE <<EOF
  51. [Unit]
  52. After=etcd.service
  53. Requires=etcd.service
  54. [Service]
  55. Type=oneshot
  56. EnvironmentFile=/etc/sysconfig/flanneld
  57. ExecStart=$FLANNEL_CONFIG_BIN
  58. [Install]
  59. WantedBy=multi-user.target
  60. EOF
  61. chown root:root $FLANNEL_CONFIG_BIN
  62. chmod 0755 $FLANNEL_CONFIG_BIN
  63. chown root:root $FLANNEL_CONFIG_SERVICE
  64. chmod 0644 $FLANNEL_CONFIG_SERVICE
  65. systemctl enable flannel-config
  66. systemctl start --no-block flannel-config