| 1 | #!/bin/sh |
| 2 | |
| 3 | . /etc/sysconfig/heat-params |
| 4 | |
| 5 | if [ "$NETWORK_DRIVER" != "flannel" ]; then |
| 6 | exit 0 |
| 7 | fi |
| 8 | |
| 9 | FLANNEL_ETCD="http://127.0.0.1:2379" |
| 10 | FLANNEL_JSON=/etc/sysconfig/flannel-network.json |
| 11 | FLANNELD_CONFIG=/etc/sysconfig/flanneld |
| 12 | |
| 13 | sed -i ' |
| 14 | /^FLANNEL_ETCD=/ s/=.*/="http:\/\/127.0.0.1:2379"/ |
| 15 | /^#FLANNEL_OPTIONS=/ s//FLANNEL_OPTIONS="-iface eth0 --ip-masq"/ |
| 16 | ' /etc/sysconfig/flanneld |
| 17 | |
| 18 | cat >> /etc/sysconfig/flanneld <<EOF |
| 19 | |
| 20 | # etcd config key. This is the configuration key that flannel queries |
| 21 | # For address range assignment |
| 22 | FLANNEL_ETCD_KEY="/flannel/network" |
| 23 | EOF |
| 24 | |
| 25 | . /etc/sysconfig/flanneld |
| 26 | |
| 27 | # Generate a flannel configuration that we will |
| 28 | # store into etcd using curl. |
| 29 | cat > $FLANNEL_JSON <<EOF |
| 30 | { |
| 31 | "Network": "$FLANNEL_NETWORK_CIDR", |
| 32 | "Subnetlen": $FLANNEL_NETWORK_SUBNETLEN, |
| 33 | "SubnetMin": "$FLANNEL_NETWORK_SUBNET_MIN", |
| 34 | "SubnetMax": "$FLANNEL_NETWORK_SUBNET_MAX", |
| 35 | "Backend": { |
| 36 | "Type": "$FLANNEL_BACKEND" |
| 37 | } |
| 38 | } |
| 39 | EOF |
| 40 | |
| 41 | # wait for etcd to become active (we will need it to push the flanneld config) |
| 42 | while ! curl -sf -o /dev/null $FLANNEL_ETCD/v2/keys/; do |
| 43 | echo "waiting for etcd" |
| 44 | sleep 1 |
| 45 | done |
| 46 | |
| 47 | # put the flannel config in etcd |
| 48 | echo "creating flanneld config in etcd" |
| 49 | curl -sf -L $FLANNEL_ETCD/v2/keys$FLANNEL_ETCD_KEY/config \ |
| 50 | -X PUT \ |
| 51 | --data-urlencode value@$FLANNEL_JSON |
| 52 | |
| 53 | echo "activating flanneld service" |
| 54 | systemctl enable flanneld |
| 55 | |
| 56 | echo "starting flanneld service" |
| 57 | systemctl --no-block start flanneld |