diff options
| author | Paul C. Buetow <paul@buetow.org> | 2014-04-12 11:51:01 +0200 |
|---|---|---|
| committer | Paul C. Buetow <paul@buetow.org> | 2014-04-12 11:51:01 +0200 |
| commit | c3ef986541e055edb347bcf7d9dde58945bc971b (patch) | |
| tree | b320778a24be3f4c0c4b8bdb827161bef87b7c43 /src/fapi.py | |
| parent | f1aa053b42ce80e7636ec6aa9e848613c60ce3f4 (diff) | |
introduce info messages
Diffstat (limited to 'src/fapi.py')
| -rwxr-xr-x | src/fapi.py | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/src/fapi.py b/src/fapi.py index 30e690f..244c730 100755 --- a/src/fapi.py +++ b/src/fapi.py @@ -14,6 +14,7 @@ import ConfigParser __program__ = 'fapi' __version__ = 'VERSION_DEVEL' # Replaced by a Makefile target +__prompt__ = '>>>' # Default prompt class Fapi(object): ''' The main F5 API Tool Object ''' @@ -21,11 +22,7 @@ class Fapi(object): def __init__(self, args): ''' Initialize the config file, username and password ''' - if args.v: - print 'Reading configuration' - config_file = args.C - config = ConfigParser.ConfigParser() config.read(config_file) @@ -47,17 +44,17 @@ class Fapi(object): try: self._partition = config.get('fapi', 'partition') - if args.v: print 'Setting partition to %s' % self._partition + self.__info('Setting partition to %s' % self._partition) self._f5.Management.Partition.set_active_partition(self._partition) except Exception, e: - print e + self.__info(e) def __login(self, username, password): ''' Logs into the F5 BigIP SOAP API ''' - if self._args.v: print 'Login to BigIP API with user %s' % username + self.__info('Login to BigIP API with user %s' % username) hostname = self._config.get('fapi', 'hostname') try: @@ -67,35 +64,49 @@ class Fapi(object): password = password, ) except Exception, e: - print e + self.__info(e) + + + def __info(self, message): + ''' Prints an informational message to stderr ''' + print >> sys.stderr, '%s %s' % (__prompt__, message) def run(self): ''' Do the actual stuff ''' - if self._args.v: print 'Do fancy stuff now' - f = self._f5 a = self._args flag = False if a.action == 'show': - if a.arg == 'pools': - print f.LocalLB.Pool.get_list() - flag = True - - elif a.arg == 'poolstatus': - pool_name = args.subarg - print f.LocalLB.Pool.get_object_status([pool_name]) - flag = True - - if not flag: print 'Don\'t know what to do' + if a.arg == 'pool': + if a.subarg == 'status': + self.__info('Get pool status') + pool_name = args.subarg2 + print f.LocalLB.Pool.get_object_status([pool_name]) + flag = True + + elif a.subarg == 'members': + self.__info('Get pool members') + pool_name = args.subarg2 + print f.LocalLB.Pool.get_member_v2([pool_name]) + flag = True + + else: + self.__info('Get pool list') + print f.LocalLB.Pool.get_list() + flag = True + + if not flag: + self.__info('Don\'t know what to do') + sys.exit(1) if __name__ == '__main__': ''' The main function, here we will have Popcorn for free! ''' parser = argparse.ArgumentParser() - parser.add_argument('-v', action='store_true', help='Verbose') + #parser.add_argument('-v', action='store_true', help='Verbose') parser.add_argument('-V', action='store_true', help='Print version') parser.add_argument('-C', action='store', help='Config file', default=expanduser('~') + '/.fapi.conf') @@ -103,11 +114,12 @@ if __name__ == '__main__': parser.add_argument('action', help='The action') parser.add_argument('arg', help='The argument for the action') parser.add_argument('subarg', nargs='?', help='A sub argument') + parser.add_argument('subarg2', nargs='?', help='Another sub argument') args = parser.parse_args() if args.V: - print 'This is ' + __program__ + ' version ' + __version__ + print 'This is %s version %s' % (__program__, __version__) sys.exit(0) fapi = Fapi(args) |
