Created
March 3, 2020 13:08
-
-
Save treydock/8447cf7ea2cc470c0a342bfa51037285 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
| import logging | |
| import os | |
| from osc.stdlib import exec_cmd | |
| log = logging.getLogger(__name__) | |
| # Needed to support Python 2.6 | |
| from osc.logs import logging_null_handler | |
| log.addHandler(logging_null_handler) | |
| class GPFS(object): | |
| def __init__(self): | |
| self.bindir = '/usr/lpp/mmfs/bin' | |
| self.mmrepquota_path = os.path.join(self.bindir, 'mmrepquota') | |
| self.mmhealth_path = os.path.join(self.bindir, 'mmhealth') | |
| def parse_mm_output(self, output, ignore_headers=[]): | |
| result_map = {} | |
| results = [] | |
| for line in output.splitlines(): | |
| l = line.strip().split(':') | |
| _type = l[1] | |
| if l[2] == 'HEADER': | |
| if _type not in result_map: | |
| result_map[_type] = {} | |
| for idx, h in enumerate(l): | |
| if h in ignore_headers: | |
| continue | |
| if not h: | |
| continue | |
| if h == _type: | |
| continue | |
| result_map[_type][h] = idx | |
| else: | |
| result = {} | |
| result['type'] = _type | |
| for h, idx in result_map[_type].items(): | |
| if len(l) <= idx: | |
| continue | |
| val = l[idx] | |
| if val.isdigit(): | |
| v = int(val) | |
| else: | |
| try: | |
| v = float(val) | |
| except ValueError: | |
| v = val | |
| result[h] = v | |
| results.append(result) | |
| return results | |
| def mmrepquota(self, fs, t=None): | |
| if t == 'user': | |
| type_arg = '-u' | |
| elif t == 'group': | |
| type_arg = '-g' | |
| elif t == 'fileset': | |
| type_arg = '-j' | |
| else: | |
| type_arg = '' | |
| if os.getuid() != 0: | |
| sudo = True | |
| runas = 'root' | |
| else: | |
| sudo = False | |
| runas = None | |
| cmd = [self.mmrepquota_path, type_arg, '-Y', fs] | |
| out, err, exit_code = exec_cmd(cmd=cmd, sudo=sudo, runas=runas) | |
| if exit_code != 0: | |
| log.error("Failed to execute '%s' exit_code=%s", cmd, exit_code) | |
| log.error("OUT: %s", out) | |
| log.error("ERR: %s", err) | |
| return None | |
| results = self.parse_mm_output(out, ['mmdf', 'HEADER', 'version', 'reserved']) | |
| return results | |
| def mmhealth(self): | |
| if os.getuid() != 0: | |
| sudo = True | |
| runas = 'root' | |
| else: | |
| sudo = False | |
| runas = None | |
| cmd = [self.mmhealth_path, 'node', 'show', '-Y'] | |
| out, err, exit_code = exec_cmd(cmd=cmd, sudo=sudo, runas=runas) | |
| if exit_code != 0: | |
| log.error("Failed to execute '%s' exit_code=%s", cmd, exit_code) | |
| log.error("OUT: %s", out) | |
| log.error("ERR: %s", err) | |
| return None | |
| results = self.parse_mm_output(out, ['mmdf', 'HEADER', 'version', 'reserved']) | |
| return results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment