Created
May 26, 2022 22:25
-
-
Save gmariette/3e8ac2459f2a25f3e1e3af56aba7c8ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_usage(fs_to_check): | |
print(f"Checking usage of partition {fs_to_check}") | |
partition_usage = float(subprocess.check_output('df -h ' + fs_to_check + ' | tail -1 | awk \'{sub("%","");print $5}\'', shell=True).decode('ascii')) | |
return partition_usage | |
def get_current_partition_size(fs_to_check): | |
print(f"Getting current partition size {fs_to_check}") | |
partition_size = float(subprocess.check_output('df -h ' + fs_to_check + ' | tail -1 | awk \'{gsub("G","");print $2}\'', shell=True).decode('ascii')) | |
return partition_size | |
def calculate_value_to_provision(fs_to_increase, minimum_percentage): | |
current_fs_size = float(subprocess.check_output('df -h ' + fs_to_increase + ' | tail -1 | awk \'{gsub("G","");print $2}\'', shell=True).decode('ascii')) | |
current_fs_usage = float(subprocess.check_output('df -h ' + fs_to_increase + ' | tail -1 | awk \'{gsub("G","");print $3}\'', shell=True).decode('ascii')) | |
space_to_add = int(ceil(float((current_fs_usage / minimum_percentage * 100) - current_fs_size))) | |
if space_to_add < 5: | |
space_to_add = 5 | |
print(f'If we want to increase FS {fs_to_increase} to have minimum {minimum_percentage}% used, we need to add {space_to_add}G to the partition') | |
return int(space_to_add + current_fs_size) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment