-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompute_healthcheck.py
115 lines (98 loc) · 4.67 KB
/
compute_healthcheck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import json
import logging
from log_setup import Logging
from program_data import PDApi, Common
"""
NetApp / SolidFire
CPE
mnode support utility
"""
# set up logging
logmsg = Logging.logmsg()
# Generate a list of clusters
#
class ComputeHealthcheck():
def generate_cluster_list(repo):
""" Display a list of vCenters.
Select target vCenter. Auto select if only one.
"""
logmsg.info("Generating Controller List....")
controllerlist = {}
userinput = ""
if len(repo.assets[0]['controller']) == 0:
logmsg.info('No compute controllers (vCenter) found in Inventory')
exit()
for controller in repo.assets[0]["controller"]:
logmsg.info(f'Controller name: {controller["host_name"]} ')
controllerlist[(controller["host_name"])] = controller["id"]
if len(repo.assets[0]["controller"]) > 1:
while userinput not in controllerlist:
userinput = input("\nEnter the controller name: ").rstrip()
controller_id = controllerlist[userinput]
else:
controller_id = repo.assets[0]["controller"][0]["id"]
return controller_id
def generate_domain_list(repo, controller_id):
""" Display a list of Host Clusters
Select target host cluster. Auto select if only one
"""
userinput = "none"
url = f'{repo.base_url}/vcenter/1/compute/{controller_id}/clusters?includeUnmanaged=true'
domainlist = {}
logmsg.info("\nGenerating Domain list (Host clusters)...")
json_return = PDApi.send_get_return_json(repo, url, debug=repo.debug)
if json_return is not None:
if 'result' in json_return:
for result in json_return["result"]:
try:
logmsg.info(f'{result["clusterName"]}')
domainlist[(result["clusterName"])] = result["clusterId"]
except:
logmsg.info(f'No valid result for controller {userinput}')
else:
logmsg.info(f'No valid result for controller {userinput} or login credentials failed')
exit(1)
while userinput not in domainlist:
userinput = input("\nEnter the domain name: ").rstrip()
cluster_id = domainlist[userinput]
return cluster_id
def run_compute_healthcheck(repo, controller_id, cluster_id):
""" Start the healthcheck """
url = f'{repo.base_url}/vcenter/1/compute/{controller_id}/health-checks'
payload = {"cluster": cluster_id,"nodes":[]}
json_return = PDApi.send_post_return_json(repo, url, payload)
if json_return is not None:
logmsg.info("Healthcheck running...")
return json_return
else:
logmsg.info("Failed return. There may be a Healthcheck already running for this target. See /var/log/mnode-support-util.log for details")
exit(1)
def print_healthcheck_status(repo, healthcheck_start):
""" Watch the progress
Write report to file
"""
# prevent the log from filling up with debug messages in the while loop
logging.getLogger("urllib3").setLevel(logging.WARNING)
report_file_name = f'ComputeHealthcheck-{healthcheck_start["taskId"]}.json'
output_file = f'{repo.support_dir}{report_file_name}'
step = "none"
url = f'{repo.base_url}/task-monitor/1/tasks/{healthcheck_start["taskId"]}'
json_return = PDApi.send_get_return_json(repo, url, debug=repo.debug)
if json_return is not None:
while json_return["state"] == "inProgress":
json_return = PDApi.send_get_return_json(repo, url, 'no')
if json_return is not None:
if step != json_return["step"]:
step = json_return["step"]
logmsg.info(step)
if json_return["state"] == 'completed':
resource_link = json_return["resourceLink"]
url = (resource_link.replace("127.0.0.1", repo.about["mnode_host_ip"]))
resource_json = PDApi.send_get_return_json(repo, url, debug=repo.debug)
with open(output_file, "w") as outfile:
print(json.dumps(resource_json), file=outfile)
logmsg.info(f'Healthcheck completed. See report {output_file}')
Common.cleanup_download_dir("ComputeHealthcheck")
Common.file_download(repo, json.dumps(resource_json), report_file_name)
# Set logging back to debug
logging.getLogger("urllib3").setLevel(logging.DEBUG)