forked from Seagate/cortx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_metric.py
executable file
·56 lines (45 loc) · 1.87 KB
/
set_metric.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
#! /usr/bin/env python3
import cortx_community
import argparse
def Debug(msg):
print(msg)
def main():
parser = argparse.ArgumentParser(description='Set a value for CORTX Community.', add_help=False, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
required = parser.add_argument_group('required arguments')
optional = parser.add_argument_group('optional_requirements')
optional.add_argument(
'-h',
'--help',
action='help',
help='show this help message and exit'
)
required.add_argument('--key', '-k', type=str, help="Which key to set / query", required=True)
optional.add_argument('--value', '-v', type=str, help="Which value to set", required=False)
optional.add_argument('--date', '-d', type=str, help='Which date to set', required=False)
optional.add_argument('--org', '-o', help='Which org', default='Seagate')
optional.add_argument('--repo', '-r', help='Which repo', default='GLOBAL')
optional.add_argument('--verbose', '-V', help='Do not compress array values into a number', action='store_true', default=False, required=False)
args = parser.parse_args()
repo = args.repo
org = args.org
key = args.key
val = args.value
date = args.date
ps = cortx_community.PersistentStats(org_name=args.org)
dates=ps.get_dates(args.repo)
if date is None:
date = dates[-1]
print("Defaulting to use last valid date %s" % date)
if val == 'None':
ps.add_stat(date=date,repo=repo,stat=key,value=None)
print("Changing %s on %s to be %s" % (repo,date,val))
elif val is not None:
ps.add_stat(date=date,repo=repo,stat=key,value=int(val))
print("Changing %s on %s to be %s" % (repo,date,val))
for d in dates:
if args.verbose:
print( d, args.key, ps.get_values(args.repo,args.key,[d]))
else:
print( d, args.key, ps.get_values_as_numbers(args.repo,args.key,[d]))
if __name__ == "__main__":
main()