Skip to content

Commit

Permalink
Revert "Feature/only run on master"
Browse files Browse the repository at this point in the history
  • Loading branch information
cvk98 authored May 23, 2022
1 parent d3b3209 commit 0254f0f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 36 deletions.
1 change: 0 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ parameters:
threshold: 90 # Percentage of maximum load
lxc_migration: OFF # Container migration (LXCs are rebooted during migration!!!)
migration_timeout: 1000 # For the future
only_on_master: OFF # Only run PLB on the current cluster master

# List of exclusions
exclusions:
Expand Down
35 changes: 0 additions & 35 deletions plb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import urllib3
import yaml
import smtplib
import socket
from random import random
from email.message import EmailMessage
from time import sleep
Expand All @@ -31,7 +30,6 @@
THRESHOLD = cfg["parameters"]["threshold"] / 100
LXC_MIGRATION = cfg["parameters"]["lxc_migration"]
MIGRATION_TIMEOUT = cfg["parameters"]["migration_timeout"]
ONLY_ON_MASTER = cfg["parameters"].get("only_on_master", False)

"""Exclusions"""
excluded_vms = tuple(cfg["exclusions"]["vms"])
Expand Down Expand Up @@ -74,8 +72,6 @@ def __init__(self, server: str):
"""Cluster"""
self.server: str = server
self.cl_name = self.cluster_name()
self.master_node: str = None
self.quorate: bool = False
"""VMs and nodes"""
self.cl_nodes: int = 0 # The number of nodes. Calculated in Cluster.cluster_name
self.cluster_information = {} # Retrieved in Cluster.cluster_items
Expand Down Expand Up @@ -140,34 +136,14 @@ def cluster_hosts(self):
"""Getting nodes from cluster resources"""
logger.debug("Launching Cluster.cluster_hosts")
nodes_dict = {}

# Find out which node is the current cluster master
url = f'{self.server}/api2/json/cluster/ha/status/manager_status'
logger.debug('Attempt to get information about the cluster HA manager...')
resources_request = rr = requests.get(url, cookies=payload, verify=False)
if resources_request.ok:
logger.debug(f'Information about the cluster HA Manager has been received. Response code: {rr.status_code}')
else:
logger.warning(f'Execution error {Cluster.cluster_items.__qualname__}')
logger.warning(f'Could not get information about the HA cluster manager. Response code: {rr.status_code}. Reason: ({rr.reason})')
sys.exit(0)

self.master_node = rr.json()['data']['manager_status']['master_node']
self.quorate = (rr.json()['data']['quorum']['quorate'] == "1")
if self.quorate == False:
# This is probably an error condition that should cause a "try again later"
logger.warning(f'Quorum is currently not quorate!')

temp = deepcopy(self.cluster_information)
for item in temp:
if item["type"] == "node":
self.cluster_information.remove(item)
item["cpu_used"] = round(item["maxcpu"] * item["cpu"], 2) # Adding the value of the cores used
item["free_mem"] = item["maxmem"] - item["mem"] # Adding the value of free RAM
item["mem_load"] = item["mem"] / item["maxmem"] # Adding the RAM load value
item["is_master"] = (item["node"] == self.master_node) # Flagging the current master node
nodes_dict[item["node"]] = item

if item["node"] not in excluded_nodes:
self.included_nodes[item["node"]] = item
del temp
Expand Down Expand Up @@ -438,21 +414,11 @@ def main():
global iteration
authentication(server_url, auth)
cluster = Cluster(server_url)

if ONLY_ON_MASTER:
hostname = socket.gethostname()
master = cluster.master_node
if hostname != master:
logger.info(f'This server ({hostname}) is not the current cluster master, {master} is. Waiting 300 seconds.')
sleep(300)
return

verification_status = cluster_load_verification(cluster.mem_load_included, cluster)
if verification_status == False:
logger.warning('Cluster health verification failed. Waiting 300 seconds.')
sleep(300)
return

need_to_balance = need_to_balance_checking(cluster)
logger.info(f'Need to balance: {need_to_balance}')
if need_to_balance:
Expand All @@ -464,7 +430,6 @@ def main():
logger.info('Waiting 10 seconds for cluster information update')
sleep(10)
else:
sleep(60)
pass # TODO Aggressive algorithm
else:
logger.info('The cluster is balanced. Waiting 300 seconds.')
Expand Down

0 comments on commit 0254f0f

Please sign in to comment.