| Total Complexity | 10 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | #! /usr/bin/python |
||
| 9 | class RemediatePoolFailure(Action): |
||
| 10 | |||
| 11 | def run(self, errors, error_level): |
||
| 12 | |||
| 13 | errors = json.loads(errors, encoding="utf-8") |
||
| 14 | if "name" not in errors: |
||
| 15 | raise Exception("Error: Instance name not provided in errors. Can not continue!") |
||
| 16 | |||
| 17 | instance = errors["name"] |
||
| 18 | vtm = Vtm(self.config, self.logger, instance) |
||
| 19 | bsd = Bsd(self.config, self.logger) |
||
| 20 | status = bsd.getStatus(instance)[0] |
||
| 21 | |||
| 22 | nodes = errors["traffic_health"]["failed_nodes"] |
||
| 23 | failedPools = {pool: [node["node"] for node in nodes for pool in node["pools"]] |
||
| 24 | for node in nodes for pool in node["pools"]} |
||
| 25 | |||
| 26 | for pool in failedPools.keys(): |
||
| 27 | nodes = vtm.getPoolNodes(pool) |
||
| 28 | if set(nodes["active"]).issubset(failedPools[pool]): |
||
| 29 | self.logger.debug("Pool Dead") |
||
| 30 | for vs in status["traffic_health"]["virtual_servers"]: |
||
| 31 | if vs["pool"] == pool: |
||
| 32 | self.logger.debug("Putting VS: {} into maintenance.".format(vs["name"])) |
||
| 33 | vtm.enableMaintenance(vs["name"], "maintenance") |
||
| 34 | else: |
||
| 35 | self.logger.debug("Pool not dead") |
||
| 36 |