Merge "Get Octavia network resources data from mine"
diff --git a/README.rst b/README.rst
index f04efb3..ab07147 100644
--- a/README.rst
+++ b/README.rst
@@ -92,10 +92,8 @@
           ca_private_key: '/etc/octavia/certs/private/cakey.pem'
           ca_certificate: '/etc/octavia/certs/ca_01.pem'
         controller_worker:
-          amp_boot_network_list: '01d3edaa-422c-40b9-b265-425c981691e7'
           amp_flavor_id: '967972bb-ab54-4679-9f53-bf81d5e28154'
           amp_image_tag: amphora
-          amp_secgroup_list: '9fcd532e-5715-423a-8e3f-51abddbe7705'
           amp_ssh_key_name: octavia_ssh_key
           loadbalancer_topology: 'SINGLE'
         haproxy_amphora:
diff --git a/metadata/service/manager/single.yml b/metadata/service/manager/single.yml
index 845d1e0..13cdddf 100644
--- a/metadata/service/manager/single.yml
+++ b/metadata/service/manager/single.yml
@@ -38,13 +38,9 @@
         ca_private_key: '/etc/octavia/certs/private/cakey.pem'
         ca_certificate: '/etc/octavia/certs/ca_01.pem'
       controller_worker:
-        amp_boot_network_list: ${_param:amp_boot_network_list}
         amp_flavor_id: ${_param:amp_flavor_id}
         amp_image_tag: amphora
-        amp_secgroup_list: ${_param:amp_secgroup_list}
         amp_ssh_key_name: octavia_ssh_key
-        amp_hm_port_id: ${_param:amp_hm_port_id}
-        amp_hm_port_mac: ${_param:amp_hm_port_mac}
         loadbalancer_topology: 'SINGLE'
       haproxy_amphora:
         client_cert: '/etc/octavia/certs/client.pem'
diff --git a/octavia/files/ocata/octavia_manager.conf b/octavia/files/ocata/octavia_manager.conf
index 00c115b..85766ae 100644
--- a/octavia/files/ocata/octavia_manager.conf
+++ b/octavia/files/ocata/octavia_manager.conf
@@ -519,7 +519,7 @@
 # List of networks to attach to the Amphorae. All networks defined in the list
 # will be attached to each amphora. (list value)
 #amp_boot_network_list =
-amp_boot_network_list = {{ manager.controller_worker.amp_boot_network_list }}
+amp_boot_network_list = {{ amp_boot_network_list }}
 
 # DEPRECATED: Network to attach to the Amphorae. (string value)
 # This option is deprecated for removal.
@@ -529,7 +529,7 @@
 
 # List of security groups to attach to the Amphora. (list value)
 #amp_secgroup_list =
-amp_secgroup_list = {{ manager.controller_worker.amp_secgroup_list }}
+amp_secgroup_list = {{ amp_secgroup_list }}
 
 # Client CA for the amphora agent to use (string value)
 #client_ca = /etc/octavia/certs/ca_01.pem
diff --git a/octavia/manager.sls b/octavia/manager.sls
index 77ff454..cdda6fc 100644
--- a/octavia/manager.sls
+++ b/octavia/manager.sls
@@ -1,13 +1,16 @@
 {%- from "octavia/map.jinja" import manager with context %}
 
 {%- if manager.enabled %}
-{%- set mine_data = salt['mine.get']('glance:client', 'glanceng.get_image_owner_id', 'pillar').values() %}
+{%- set image_mine_data = salt['mine.get']('glance:client', 'glanceng.get_image_owner_id', 'pillar').values() %}
+{%- set network_mine_data = salt['mine.get']('neutron:client', 'list_octavia_networks', 'pillar').values() %}
+{%- set secgroup_mine_data = salt['mine.get']('neutron:client', 'list_octavia_mgmt_security_groups', 'pillar').values() %}
+{%- set port_mine_data = salt['mine.get']('neutron:client', 'list_octavia_hm_ports', 'pillar').values() %}
 
 octavia_manager_packages:
   pkg.installed:
   - names: {{ manager.pkgs }}
 
-{%- if mine_data %}
+{%- if image_mine_data and network_mine_data and secgroup_mine_data %}
 /etc/octavia/octavia.conf:
   file.managed:
   - source: salt://octavia/files/{{ manager.version }}/octavia_manager.conf
@@ -15,7 +18,9 @@
   - require:
     - pkg: octavia_manager_packages
   - context:
-    amp_image_owner_id: {{ mine_data|first }}
+    amp_image_owner_id: {{ image_mine_data|first }}
+    amp_boot_network_list: {{ (network_mine_data|first)['networks'][0]['id'] }}
+    amp_secgroup_list: {{ (secgroup_mine_data|first)['lb-mgmt-sec-grp']['id'] }}
 {%- endif %}
 
 /etc/octavia/certificates/openssl.cnf:
@@ -33,23 +38,23 @@
     - pkg: octavia_manager_packages
 
 {%- if not grains.get('noservices', False) %}
+{%- if image_mine_data and network_mine_data and secgroup_mine_data and port_mine_data %}
+
+{%- set amp_hm_port_mac = port_mine_data[0]['octavia-health-manager-listen-port']['mac_address'] %}
+{%- set amp_hm_port_id = port_mine_data[0]['octavia-health-manager-listen-port']['id'] %}
 
 health_manager_ovs_port:
   cmd.run:
   - name: "ovs-vsctl -- --may-exist add-port br-int o-hm0 -- set Interface
   o-hm0 type=internal -- set Interface o-hm0 external-ids:iface-status=active
-  -- set Interface o-hm0 external-ids:attached-mac={{
-  manager.controller_worker.amp_hm_port_mac }} -- set Interface o-hm0
-  external-ids:iface-id={{ manager.controller_worker.amp_hm_port_id }} -- set
-  Interface o-hm0 external-ids:skip_cleanup=true"
+  -- set Interface o-hm0 external-ids:attached-mac={{ amp_hm_port_mac }} -- set Interface o-hm0
+  external-ids:iface-id={{ amp_hm_port_id }} -- set Interface o-hm0 external-ids:skip_cleanup=true"
   - unless: ovs-vsctl show | grep o-hm0
 
 health_manager_port_set_mac:
   cmd.run:
-  - name: "ip link set dev o-hm0 address {{
-  manager.controller_worker.amp_hm_port_mac }}"
-  - unless: "ip link show o-hm0 | grep {{
-  manager.controller_worker.amp_hm_port_mac }}"
+  - name: "ip link set dev o-hm0 address {{ amp_hm_port_mac }}"
+  - unless: "ip link show o-hm0 | grep {{ amp_hm_port_mac }}"
   - require:
     - cmd: health_manager_ovs_port
 
@@ -69,7 +74,6 @@
     - proto: udp
     - save: True
 
-{%- if mine_data %}
 octavia_manager_services:
   service.running:
   - names: {{ manager.services }}
diff --git a/tests/pillar/manager_single.sls b/tests/pillar/manager_single.sls
index f3eb391..4ded26b 100644
--- a/tests/pillar/manager_single.sls
+++ b/tests/pillar/manager_single.sls
@@ -29,13 +29,9 @@
       ca_private_key: '/etc/octavia/certs/private/cakey.pem'
       ca_certificate: '/etc/octavia/certs/ca_01.pem'
     controller_worker:
-      amp_boot_network_list: '01d3edaa-422c-40b9-b265-425c981691e7'
       amp_flavor_id: '967972bb-ab54-4679-9f53-bf81d5e28154'
       amp_image_tag: amphora
-      amp_secgroup_list: '9fcd532e-5715-423a-8e3f-51abddbe7705'
       amp_ssh_key_name: octavia_ssh_key
-      amp_hm_port_id: a52a982d-876d-414e-b8d3-4a0ce8c060c6
-      amp_hm_port_mac: fa:16:3e:c4:bf:b2
       loadbalancer_topology: 'SINGLE'
     haproxy_amphora:
       client_cert: '/etc/octavia/certs/client.pem'