@@ -16,39 +16,44 @@ class ServerInfo(object):
16
16
subsystems = ('cpu' , 'memory' , 'net' , 'disk' , 'system' )
17
17
18
18
def __init__ (self ):
19
+ self .parser = argparse .ArgumentParser ()
19
20
self .__parse_args ()
20
21
self .__check_args ()
21
22
self .main ()
22
23
23
24
def __parse_args (self ):
24
25
default_directory = '/tmp/netutils_server_info/'
25
- parser = argparse .ArgumentParser ()
26
- parser .add_argument ('--directory' , type = str , help = "Specify a data directory or a tarball" ,
27
- default = default_directory )
28
- parser .add_argument ('--collect' , action = 'store_true' , help = 'Collect the data about the server' , default = False )
29
- parser .add_argument ('--gzip' , action = 'store_true' , help = "Compress the data" , default = False )
30
- parser .add_argument ('--show' , action = 'store_true' , help = 'Shows data about the server in YAML' , default = False )
31
- parser .add_argument ('--rate' , action = 'store_true' , help = 'Rates data about the server' , default = False )
32
- parser .add_argument ('-f' , '--folding' , action = 'count' , help = '-f - device, -ff - subsystem, -fff - server' ,
33
- default = FOLDING_NO )
34
- parser .add_argument ('--device' , action = 'store_const' , const = FOLDING_DEVICE , dest = 'folding' ,
35
- help = 'Folds rates details to entire devices' )
36
- parser .add_argument ('--subsystem' , action = 'store_const' , const = FOLDING_SUBSYSTEM , dest = 'folding' ,
37
- help = 'Folds rates details to entire subsystems' )
38
- parser .add_argument ('--server' , action = 'store_const' , const = FOLDING_SERVER , dest = 'folding' ,
39
- help = 'Folds rates details to entire server' )
40
- parser .add_argument ('--cpu' , action = 'store_true' , help = 'Show information about CPU' , default = False )
41
- parser .add_argument ('--memory' , action = 'store_true' , help = 'Show information about RAM' , default = False )
42
- parser .add_argument ('--net' , action = 'store_true' , help = 'Show information about network devices' , default = False )
43
- parser .add_argument ('--disk' , action = 'store_true' , help = 'Show information about disks' , default = False )
44
- parser .add_argument ('--system' , action = 'store_true' , help = 'Show information about system overall (rate only)' ,
45
- default = False )
46
- self .args = parser .parse_args ()
26
+ self .parser .add_argument ('--directory' , type = str , help = "Specify a data directory or a tarball" ,
27
+ default = default_directory )
28
+ self .parser .add_argument ('--collect' , action = 'store_true' , help = 'Collect the data about the server' ,
29
+ default = False )
30
+ self .parser .add_argument ('--gzip' , action = 'store_true' , help = "Compress the data" , default = False )
31
+ self .parser .add_argument ('--show' , action = 'store_true' , help = 'Shows data about the server in YAML' ,
32
+ default = False )
33
+ self .parser .add_argument ('--rate' , action = 'store_true' , help = 'Rates data about the server' , default = False )
34
+ self .parser .add_argument ('-f' , '--folding' , action = 'count' , help = '-f - device, -ff - subsystem, -fff - server' ,
35
+ default = FOLDING_NO )
36
+ self .parser .add_argument ('--device' , action = 'store_const' , const = FOLDING_DEVICE , dest = 'folding' ,
37
+ help = 'Folds rates details to entire devices' )
38
+ self .parser .add_argument ('--subsystem' , action = 'store_const' , const = FOLDING_SUBSYSTEM , dest = 'folding' ,
39
+ help = 'Folds rates details to entire subsystems' )
40
+ self .parser .add_argument ('--server' , action = 'store_const' , const = FOLDING_SERVER , dest = 'folding' ,
41
+ help = 'Folds rates details to entire server' )
42
+ self .parser .add_argument ('--cpu' , action = 'store_true' , help = 'Show information about CPU' , default = False )
43
+ self .parser .add_argument ('--memory' , action = 'store_true' , help = 'Show information about RAM' , default = False )
44
+ self .parser .add_argument ('--net' , action = 'store_true' , help = 'Show information about network devices' ,
45
+ default = False )
46
+ self .parser .add_argument ('--disk' , action = 'store_true' , help = 'Show information about disks' , default = False )
47
+ self .parser .add_argument ('--system' , action = 'store_true' ,
48
+ help = 'Show information about system overall (rate only)' , default = False )
49
+ self .args = self .parser .parse_args ()
47
50
48
51
def __check_args (self ):
49
52
""" Maybe they should be positional arguments, not options. But subparsers/groups are stupid """
50
- assert any ([self .args .collect , self .args .rate , self .args .show ]), "Specify command: {0}" .format (self .commands )
51
-
53
+ if not any ([self .args .collect , self .args .rate , self .args .show ]):
54
+ print ('Error: please, specify --rate, --show or --collect command' )
55
+ self .parser .print_help ()
56
+ exit (1 )
52
57
if not any (getattr (self .args , subsystem ) for subsystem in self .subsystems ):
53
58
for subsystem in self .subsystems :
54
59
setattr (self .args , subsystem , True )
0 commit comments