From ce7abc0fd0fa803feefbc92587270795fdc798bf Mon Sep 17 00:00:00 2001 From: Shachar Snapiri Date: Tue, 12 Jun 2018 13:09:04 +0300 Subject: [PATCH] Add Docker support Add support for running dragonflow as a docker container. Includes documentation how to set up with OVS running on the host. Change-Id: Ia7185ea7f9d47a56853def418aeab8c3a4e87d0a Resolves-Bug: #1778007 --- Dockerfile | 27 +++++++++++++ doc/source/docker_install.rst | 75 +++++++++++++++++++++++++++++++++++ etc/standalone/dragonflow.ini | 33 +++++++++++++++ tools/run_dragonflow.sh | 50 +++++++++++++++++++++++ 4 files changed, 185 insertions(+) create mode 100644 Dockerfile create mode 100644 doc/source/docker_install.rst create mode 100644 etc/standalone/dragonflow.ini create mode 100755 tools/run_dragonflow.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..c374cfb5b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM ubuntu:16.04 + +# Install dependencies and some useful tools. +ENV DRAGONFLOW_PACKAGES git \ + python-pip python-psutil python-subprocess32 \ + python-dev libpython-dev + +# Ignore questions when installing with apt-get: +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update && apt-get install -y $DRAGONFLOW_PACKAGES + +RUN mkdir -p /opt/dragonflow + +# Copy Dragonflow sources to the container +COPY . /opt/dragonflow/ + +# Install Dragonflow on the container +WORKDIR /opt/dragonflow +RUN pip install -e . + +# Create config folder +ENV DRAGONFLOW_ETCDIR /etc/dragonflow +RUN mkdir -p $DRAGONFLOW_ETCDIR + +ENTRYPOINT ["./tools/run_dragonflow.sh"] + diff --git a/doc/source/docker_install.rst b/doc/source/docker_install.rst new file mode 100644 index 000000000..7ace78be4 --- /dev/null +++ b/doc/source/docker_install.rst @@ -0,0 +1,75 @@ +Building the image +------------------ +* Run the following command + +.. code-block:: bash + + docker build --tag dragonflow . + + +Running the image +----------------- + +Preparation work +~~~~~~~~~~~~~~~~ +* Create a network to be used by the containers, use any subnet you find fit, the subnet here is + just an example. + +.. code-block:: bash + + export DRAGONFLOW_NET_NAME=dragonflow_net + docker network create --subnet=172.18.0.0/16 $DRAGONFLOW_NET_NAME + +Running etcd node +~~~~~~~~~~~~~~~~~ +* Run the following commands: + +.. code-block:: bash + + mkdir -p /tmp/etcd + chcon -Rt svirt_sandbox_file_t /tmp/etcd + export NODE1=172.18.0.2 # Any free IP in the subnet + export DATA_DIR=/tmp/etcd + docker run --detach --net $DRAGONFLOW_NET_NAME --ip ${NODE1} --volume=${DATA_DIR}:/etcd-data --name etcd quay.io/coreos/etcd:latest /usr/local/bin/etcd --data-dir=/etcd-data --name node1 --initial-advertise-peer-urls http://${NODE1}:2380 --listen-peer-urls http://${NODE1}:2380 --advertise-client-urls http://${NODE1}:2379 --listen-client-urls http://${NODE1}:2379 --initial-cluster node1=http://${NODE1}:2380 + + +* Make sure the IP was properly assigned to the container: + +.. code-block:: bash + + docker inspect --format "{{ .NetworkSettings.Networks.${DRAGONFLOW_NET_NAME}.IPAddress }}" etcd + + +Running controller node +~~~~~~~~~~~~~~~~~~~~~~~ +This section assumes you have OVS set up. Make sure ovsdb-server listens on +TCP port 6640. This can be done with the following command. Note you may need +to allow this via `selinux`. + +.. code-block:: bash + + sudo ovs-appctl -t ovsdb-server ovsdb-server/add-remote ptcp:6640 + +* Run the following commands: + +.. code-block:: bash + + export DRAGONFLOW_ADDRESS=172.18.0.3 # Any free IP in the subnet + export MANAGEMENT_IP=$(docker inspect --format "{{ .NetworkSettings.Networks.${DRAGONFLOW_NET_NAME}.Gateway }}" etcd) # Assuming you put OVS on the host + docker run --name dragonflow --net $DRAGONFLOW_NET_NAME --ip ${DRAGONFLOW_ADDRESS} dragonflow:latest --dragonflow_address ${DRAGONFLOW_ADDRESS} --db_address ${NODE1}:2379 --management_ip ${MANAGEMENT_IP} + +* Make sure the IP was properly assigned to the container: + +.. code-block:: bash + + docker inspect --format "{{ .NetworkSettings.Networks.${DRAGONFLOW_NET_NAME}.IPAddress }}" dragonflow + +There are two configuration files that Dragonflow needs, and creates automatically if they do not +exist: + +* `/etc/dragonflow/dragonflow.ini` + +* `/etc/dragonflow//etc/dragonflow/dragonflow_datapath_layout.yaml` + +If these files exist, they are used as-is, and are not overwritten. You can add these files using +e.g. `-v local-dragonflow-conf.ini:/etc/dragonflow/dragonflow.ini`. diff --git a/etc/standalone/dragonflow.ini b/etc/standalone/dragonflow.ini new file mode 100644 index 000000000..df6189dc3 --- /dev/null +++ b/etc/standalone/dragonflow.ini @@ -0,0 +1,33 @@ +[DEFAULT] + + +[df] +pub_sub_driver = etcd_pubsub_driver +enable_selective_topology_distribution = False +enable_df_pub_sub = True +apps_list = portbinding,l2,l3_proactive,dhcp,dnat,sg,portqos,classifier,tunneling,provider,metadata_service,active_port_detection,migration +integration_bridge = br-int +tunnel_types = vxlan,geneve,gre +local_ip = LOCAL_IP +management_ip = MANAGEMENT_IP +enable_dpdk = False +enable_neutron_notifier = False +remote_db_hosts = DB_SERVER_IP +nb_db_class = etcd_nb_db_driver +auto_detect_port_behind_port = False +publisher_rate_limit_count = 1 +publisher_rate_limit_timeout = 180 +monitor_table_poll_time = 30 +datapath_layout_path=/etc/dragonflow/dragonflow_datapath_layout.yaml + +[df_l2_app] +l2_responder = True + +[df_loadbalancer] +auto_enable_vip_ports = True + +[df_metadata] +metadata_interface = tap-metadata +port = 18080 +ip = 169.254.169.254 + diff --git a/tools/run_dragonflow.sh b/tools/run_dragonflow.sh new file mode 100755 index 000000000..8f5bc6896 --- /dev/null +++ b/tools/run_dragonflow.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# First get all the arguments +while test ${#} -gt 0; do + case $1 in + --dragonflow_address) + shift + DRAGONFLOW_ADDRESS=$1 + ;; + --db_address) + shift + DB_ADDRESS=$1 + ;; + --mgmt_address) + shift + MANAGEMENT_IP=$1 + ;; + --db_init) + DB_INIT=1 + ;; + --) + break + ;; + *) + echo >&2 "Unknown command line argument: $1" + exit 1 + ;; + esac + shift +done + +# SET DRAGONFLOW_ADDRESS and DB_ADDRESS on the ini file +if [ ! -d /etc/dragonflow ]; then + mkdir -p /etc/dragonflow +fi +if [ ! -e /etc/dragonflow/dragonflow.ini ]; then + sed -e "s/LOCAL_IP/$DRAGONFLOW_ADDRESS/g" etc/standalone/dragonflow.ini | \ + sed -e "s/MANAGEMENT_IP/$MANAGEMENT_IP/g" | \ + sed -e "s/DB_SERVER_IP/$DB_ADDRESS/g" > /etc/dragonflow/dragonflow.ini +fi +if [ ! -e /etc/dragonflow/dragonflow_datapath_layout.yaml ]; then + cp etc/dragonflow_datapath_layout.yaml /etc/dragonflow +fi + +if [ -n "$DB_INIT" ]; then + df-db init +fi + +/usr/local/bin/df-local-controller --config-file /etc/dragonflow/dragonflow.ini +