[Tooling update] health_checks
* Added:
- Contrail control peer links summary
- Contrail control peer links state
Prod-Related: PROD-31970
Change-Id: I2b6452992278226e58e5ff7781dc452b7c3cc0e5
diff --git a/README.rst b/README.rst
index fc8366b..7bbb04e 100644
--- a/README.rst
+++ b/README.rst
@@ -877,6 +877,18 @@
salt-call health_checks.contrail_vrouter_agent_info cmp001
+Retrieve contrail control peers summary
+
+.. code-block:: bash
+
+ salt -C s-ntw01* health_checks.contrail_control_peers_summary
+
+Retrieve contrail control filtered peers info
+
+.. code-block:: bash
+
+ salt -C s-ntw03* health_checks.contrail_control_peer_status
+
Fetch libvirt supported machine types for compute node
.. code-block:: bash
diff --git a/_modules/health_checks.py b/_modules/health_checks.py
index 6180023..68a5426 100644
--- a/_modules/health_checks.py
+++ b/_modules/health_checks.py
@@ -30,7 +30,6 @@
VrouterAgent:
- build_info:build-info:0:build-version
- build_info:build-info:0:build-number
-- collector_server_list_cfg
- config_file
- control_ip
- control_node_list_cfg
@@ -63,6 +62,8 @@
- xmpp_peer_list:*:status
""", Loader=Loader)
+default_peer_filter = ["encoding", "peer_address", "state"]
+
def _failed_minions(out, agent, failed_minions):
@@ -1381,6 +1382,40 @@
return json.loads(req.text)
+def contrail_control_peers_summary(api_host='auto', api_port=8083):
+
+ ''' Retrieve contrail control peers summary '''
+
+ import xml.etree.ElementTree as ET
+
+ if api_host[0:4] == 'http':
+ url = api_host + ':' + str(api_port)
+ elif api_host == 'auto':
+ my_ip = '127.0.0.1'
+ url = 'http://' + my_ip+ ':' + str(api_port)
+ else:
+ url = 'http://' + api_host + ':' + str(api_port)
+
+ req = requests.get(url + '/Snh_ShowBgpNeighborSummaryReq')
+ if int(req.status_code) != 200:
+ return "Could not fetch data from contrail control via %s.\nGot bad status code: %s\n%s" % (url, str(req.status_code), str(req.text))
+
+ peers = []
+ summary = req.text
+
+ try:
+ xmletree = ET.fromstring(summary)
+ for elem in xmletree.find('.//list'):
+ attrs = {}
+ for child in elem:
+ attrs[child.tag] = child.text
+ peers.append(attrs)
+ except:
+ return "Could not parse xml tree %s" % str(summary)
+
+ return peers
+
+
def _get_object(json_obj, obj_path):
''' Retrieve subelemet of an JSON object or value '''
@@ -1450,6 +1485,19 @@
return vr_info
+def kafka_brokers_ids():
+
+ ''' Retrieve kafka brokers ids '''
+
+ brokers_ids = []
+ for line in zookeeper_cmd('dump').split('\n'):
+ if line:
+ if '/brokers/ids/' in line:
+ brokers_ids.append(int(line.split('/')[3]))
+
+ return brokers_ids
+
+
def libvirt_capabilities():
''' JSON formatted libvirtcapabilities list '''
@@ -1480,3 +1528,20 @@
except:
return "Unsupported xml tree for this function %s" % str(stdout)
+
+def contrail_control_peer_status(api_host='auto', api_port=8083, fields=default_peer_filter):
+
+ ''' Contrail control peer status '''
+
+ peer_status = {}
+
+ for peer_elem in contrail_control_peers_summary():
+ elem = {}
+ for attr in peer_elem:
+ if attr in fields:
+ elem[attr] = peer_elem[attr]
+
+ peer_name = peer_elem["peer"]
+ peer_status[peer_name] = elem
+
+ return peer_status