PoC for ironic provisioning of physical_mcp11_ovs_dpdk

Change-Id: I257a061ceaf34bc8ca310a94335371a480db301d
Reviewed-on: https://review.gerrithub.io/363525
Reviewed-by: Dennis Dmitriev <dis.xcom@gmail.com>
Tested-by: Dennis Dmitriev <dis.xcom@gmail.com>
diff --git a/tcp_tests/templates/ironic_standalone/underlay--user-data-ironic.yaml b/tcp_tests/templates/ironic_standalone/underlay--user-data-ironic.yaml
index 0544ae6..f35127d 100644
--- a/tcp_tests/templates/ironic_standalone/underlay--user-data-ironic.yaml
+++ b/tcp_tests/templates/ironic_standalone/underlay--user-data-ironic.yaml
@@ -47,8 +47,8 @@
 
    - echo "172.18.248.114    jenkins.mcp.mirantis.net  gerrit.mcp.mirantis.net" >> /etc/hosts;
    - echo "185.135.196.10    apt-mk.mirantis.com" >> /etc/hosts;
-   - echo "nameserver 172.18.208.44 >> /etc/resolv.conf;
-   - echo "nameserver 8.8.8.8 >> /etc/resolv.conf;
+   - echo "nameserver 172.18.208.44" >> /etc/resolv.conf;
+   - echo "nameserver 8.8.8.8" >> /etc/resolv.conf;
    - which wget >/dev/null || (apt-get update; apt-get install -y wget);
    - apt-get install -y ntp
 
@@ -63,6 +63,18 @@
    - ip a a $IRONIC_PXE_INTERFACE_ADDRESS/$IRONIC_DHCP_POOL_NETMASK_PREFIX dev $IRONIC_PXE_INTERFACE_NAME
    - curl https://raw.githubusercontent.com/dis-xcom/underpillar/master/bootstrap.sh -o ./bootstrap.sh && bash ./bootstrap.sh
 
+   # Disable dnsmasq in favour to external DHCP provider
+   #- systemctl disable dnsmasq
+   # - service dnsmasq stop
+
+   {%- if os_env('IRONIC_DNSMASQ_HOSTFILE', '') %}
+   - echo "dhcp-hostsfile=/var/lib/libvirt/dnsmasq/{{ IRONIC_ENV_NAME }}.hostsfile" >> /etc/dnsmasq.conf
+   - service dnsmasq restart
+   {%- endif %}
+
+   # Enable SNAT to allow internet access for deploying nodes using ironic node as a gateway
+   - iptables -t nat -A POSTROUTING -s {{ os_env('IRONIC_DHCP_POOL_START', '10.0.175.100') }}/{{ os_env('IRONIC_DHCP_POOL_NETMASK_PREFIX', '24') }} ! -d {{ os_env('IRONIC_DHCP_POOL_START', '10.0.175.100') }}/{{ os_env('IRONIC_DHCP_POOL_NETMASK_PREFIX', '24') }} -j MASQUERADE
+
    - echo "Building ironic agent image (stable/newton) ..."
    - apt-get install -y docker.io gzip uuid-runtime cpio findutils grep gnupg make
    - service docker start
@@ -130,3 +142,12 @@
             ServerAliveCountMax 10
             StrictHostKeyChecking no
             UserKnownHostsFile /dev/null
+
+   {%- if os_env('IRONIC_DNSMASQ_HOSTFILE', '') %}
+   - path: /var/lib/libvirt/dnsmasq/{{ IRONIC_ENV_NAME }}.hostsfile
+     permissions: '0644'
+     content: |
+     {%- for host in os_env('IRONIC_DNSMASQ_HOSTFILE').splitlines() %}
+       {{ host }}
+     {%- endfor %}
+   {%- endif %}