Node roles with dynamic metadata mapping

For easy scale of any role in the cluster, there are some
dynamic metadata will be prepared for 'Environment' model
based on roles from the inventory:

* Automatically control master/slave relations for the:
    rabbitmq_cluster_role
    mysql_cluster_role
    redis_cluster_role

* Automatically control IDs as counters for the:
    keepalived_vip_priority
    cicd_database_id
    opencontrail_database_id

Change-Id: I4a893662d43c9cb1799ee2bc24d72a62afc00a56
Reviewed-on: https://review.gerrithub.io/377960
Reviewed-by: Dennis Dmitriev <dis.xcom@gmail.com>
Tested-by: Dennis Dmitriev <dis.xcom@gmail.com>
diff --git "a/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/bond0_ab_contrail" "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/bond0_ab_contrail"
index 3147d1f..8de76d6 100644
--- "a/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/bond0_ab_contrail"
+++ "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/bond0_ab_contrail"
@@ -1,16 +1,11 @@
 {#- Provides:     #}
-{#-   br_ctl (linux bridge) + control address #}
 {#-   br_mesh (linux bridge) + tenant address #}
+{#-   vhost0 , as a keepalived vip interface #}
 {#- Requirements:                     #}
-{#-   _param:single_address         #}
-{#-   _param:control_vlan           #}
-{#-   _param:control_network_netmask         #}
 {#-   _param:tenant_vlan           #}
 {#-   _param:tenant_address         #}
 {#-   _param:tenant_netmask         #}
 {#-   _param:tenant_network_gateway         #}
-{#-   _param:_param:dns_server01         #}
-{#-   _param:_param:dns_server02         #}
 
               # {{ interfaces_role }}
               {%- for interface_name, interface in interfaces.items() %}
@@ -38,27 +33,7 @@
                 - {{ interface_name }}
                 {%- endfor %}
 
-              br_ctl:
-                address: ${_param:_esc}{_param:single_address}
-                enabled: true
-                netmask: ${_param:_esc}{_param:control_network_netmask}
-                proto: static
-                type: bridge
-                use_interfaces:
-                - bond0.${_param:_esc}{_param:control_vlan}
-                require_interfaces:
-                - bond0.${_param:_esc}{_param:control_vlan}
-              bond0.control_vlan:
-                mtu: 9000
-                name: bond0.${_param:_esc}{_param:control_vlan}
-                enabled: true
-                proto: manual
-                type: vlan
-                use_interfaces:
-                - bond0
-                require_interfaces:
-                - bond0
-
+              {{- set_param('keepalived_vip_interface', 'vhost0') }}
               vhost0:
                 mtu: 9000
                 address: ${_param:_esc}{_param:tenant_address}
diff --git "a/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/bond0_ab_ctl_contrail" "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/bond0_ab_ctl_contrail"
new file mode 100644
index 0000000..dfee7cd
--- /dev/null
+++ "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/bond0_ab_ctl_contrail"
@@ -0,0 +1,88 @@
+{#- Provides:     #}
+{#-   br_ctl (linux bridge) + control address #}
+{#-   vhost0  #}
+{#- Requirements:                     #}
+{#-   _param:single_address         #}
+{#-   _param:control_vlan           #}
+{#-   _param:control_network_netmask         #}
+{#-   _param:tenant_vlan           #}
+{#-   _param:tenant_address         #}
+{#-   _param:tenant_netmask         #}
+{#-   _param:tenant_network_gateway         #}
+{#-   _param:_param:dns_server01         #}
+{#-   _param:_param:dns_server02         #}
+
+              # {{ interfaces_role }}
+              {%- for interface_name, interface in interfaces.items() %}
+              {{ interface_name }}:
+                mtu: 9000
+                enabled: true
+                name: {{ interface_name }}
+                proto: manual
+                type: eth
+                ipflush_onchange: true
+              {%- endfor %}
+              bond0:
+                mtu: 9000
+                enabled: true
+                mode: active-backup
+                proto: manual
+                slaves: {{ ' '.join(interfaces.keys()) }}
+                type: bond
+                use_interfaces:
+                {%- for interface_name in interfaces.keys() %}
+                - {{ interface_name }}
+                {%- endfor %}
+                require_interfaces:
+                {%- for interface_name in interfaces.keys() %}
+                - {{ interface_name }}
+                {%- endfor %}
+
+              br_ctl:
+                address: ${_param:_esc}{_param:single_address}
+                enabled: true
+                netmask: ${_param:_esc}{_param:control_network_netmask}
+                proto: static
+                type: bridge
+                use_interfaces:
+                - bond0.${_param:_esc}{_param:control_vlan}
+                require_interfaces:
+                - bond0.${_param:_esc}{_param:control_vlan}
+              bond0.control_vlan:
+                mtu: 9000
+                name: bond0.${_param:_esc}{_param:control_vlan}
+                enabled: true
+                proto: manual
+                type: vlan
+                use_interfaces:
+                - bond0
+                require_interfaces:
+                - bond0
+
+              vhost0:
+                mtu: 9000
+                address: ${_param:_esc}{_param:tenant_address}
+                netmask: ${_param:_esc}{_param:tenant_network_netmask}
+                gateway: ${_param:_esc}{_param:tenant_network_gateway}
+                enabled: true
+                proto: static
+                type: eth
+                pre_up_cmds:
+                - /usr/lib/contrail/if-vhost0
+                name_servers:
+                - ${_param:_esc}{_param:dns_server01}
+                - ${_param:_esc}{_param:dns_server02}
+                use_interfaces:
+                - bond0.${_param:_esc}{_param:tenant_vlan}
+                require_interfaces:
+                - bond0.${_param:_esc}{_param:tenant_vlan}
+              bond0.tenant_vlan:
+                mtu: 9000
+                name: bond0.${_param:_esc}{_param:tenant_vlan}
+                enabled: true
+                proto: manual
+                type: vlan
+                use_interfaces:
+                - bond0
+                require_interfaces:
+                - bond0
diff --git "a/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/bond0_ab_ovs_vlan_ctl" "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/bond0_ab_ovs_vlan_ctl"
index 4326138..d6bbd72 100644
--- "a/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/bond0_ab_ovs_vlan_ctl"
+++ "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/bond0_ab_ovs_vlan_ctl"
@@ -51,4 +51,3 @@
                 - bond0
                 require_interfaces:
                 - bond0
-{%- set _ = params.update({'keepalived_vip_interface': 'br_ctl'}) %}
\ No newline at end of file
diff --git "a/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/readme.txt" "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/readme.txt"
new file mode 100644
index 0000000..cf80b5b
--- /dev/null
+++ "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/readme.txt"
@@ -0,0 +1,10 @@
+Patterns from this folder are used for two purposes:
+1. Configure the real node interfaces as specified in the inventory.
+2. Provide the following list of interfaces for the underlay level:
+  - br_mgm: Access from infrastructure management network / admin network / DHCP / PXE
+  - br_ctl: OpenStack control network for internal services
+  - br-prv: For tenant networks with VLAN segmentation
+  - br-ten: For tenant networks with VXLAN segmentation
+  - br-mesh: Endpoint for VXLAN tunnels that are used by br-ten
+  - br-floating: Connection to the floating network
+  - vhost0: for OpenContrail workloads
\ No newline at end of file
diff --git "a/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/single_ctl" "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/single_ctl"
index a289c99..ce54ed7 100644
--- "a/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/single_ctl"
+++ "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/single_ctl"
@@ -29,4 +29,3 @@
                 - {{ interface_name }}
                 require_interfaces:
                 - {{ interface_name }}
-{%- set _ = params.update({'keepalived_vip_interface': 'br_ctl'}) %}
diff --git "a/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/single_dhcp" "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/single_dhcp"
index 107b523..87315e0 100644
--- "a/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/single_dhcp"
+++ "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/single_dhcp"
@@ -1,12 +1,6 @@
-{#- Management (admin) network. For nodes where deploy address must be configured as static (at least cfg*) #}
+{#- Management (admin) network with DHCP #}
 {#- Provides:                         #}
-{#-   br_mgm (linux bridge) + address #}
-{#- Requires:                         #}
-{#-   _param:deploy_address         #}
-{#-   _param:deploy_network_netmask         #}
-{#-   _param:deploy_network_gateway         #}
-{#-   _param:dns_server01         #}
-{#-   _param:dns_server02         #}
+{#-   <interface_name> + DHCP address #}
 
               # {{ interfaces_role }}
               {%- set interface_name = interfaces.keys()[0] %}
@@ -14,4 +8,4 @@
                 enabled: true
                 type: eth
                 proto: dhcp
-                name: {{ interface_name }}
+                name: {{ interface_name }}
\ No newline at end of file
diff --git "a/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/single_mgm_dhcp" "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/single_mgm_dhcp"
new file mode 100644
index 0000000..fd2bf66
--- /dev/null
+++ "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/single_mgm_dhcp"
@@ -0,0 +1,18 @@
+{#- Management (admin) network. For nodes where deploy address provided by DHCP server #}
+{#- Provides:                         #}
+{#-   br_mgm (linux bridge) + DHCP address #}
+
+              # {{ interfaces_role }}
+              {%- set interface_name = interfaces.keys()[0] %}
+              {{ interface_name }}:
+                enabled: true
+                type: eth
+                proto: manual
+                ipflush_onchange: true
+                name: {{ interface_name }}
+              br_mgm:
+                enabled: true
+                proto: dhcp
+                type: bridge
+                use_interfaces:
+                - {{ interface_name }}
diff --git "a/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/single_vlan_ctl" "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/single_vlan_ctl"
index db00e14..2b899a2 100644
--- "a/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/single_vlan_ctl"
+++ "b/tcp_tests/environment/environment_template/\173\043 interfaces \043\175/single_vlan_ctl"
@@ -39,4 +39,3 @@
                 - {{ interface_name }}
                 require_interfaces:
                 - {{ interface_name }}
-{%- set _ = params.update({'keepalived_vip_interface': 'br_ctl'}) %}