diff options
| author | Paul Buetow (mars.fritz.box) <paul@buetow.org> | 2014-03-10 22:24:43 +0100 |
|---|---|---|
| committer | Paul Buetow (mars.fritz.box) <paul@buetow.org> | 2014-03-10 22:24:43 +0100 |
| commit | 574435be04f2f4b50bfd6a7c896e4ef62fd03f3b (patch) | |
| tree | 21610ca56919c225a630bcda30e76843e1746aed | |
| parent | b9e0eb260a77416dad6a9639e751dfc616d3292c (diff) | |
some stuff
| -rw-r--r-- | fapi.conf | 2 | ||||
| -rwxr-xr-x | fapi.py | 99 |
2 files changed, 69 insertions, 32 deletions
@@ -1,3 +1,5 @@ [fapi] user: paul pass64: Zm9vYmFyYmF6 +apiuri: https://polb-qa-bs-01-mgt.lb.server.lan +sslverify: False @@ -1,10 +1,11 @@ #!/usr/bin/env python +# 2014 (c) Paul Buetow -import sys import argparse import base64 import getpass +import sys from os.path import expanduser @@ -14,44 +15,78 @@ __program__ = 'fapi' __version__ = 'VERSION_DEVEL' # Replaced by a Makefile target class Fapi(object): - """The main F5 API Tool Object """ + '''The main F5 API Tool Object ''' + + config = None + __f5api_user = '' + __f5api_pass = '' + + 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) + + self.__args_merge(config, args) + + if config.has_option('fapi', 'user'): + self.__f5api_user = config.get('fapi', 'user') + else: + self.__f5api_user = getpass.getuser() - __f5api_user = '' - __f5api_pass = '' + if config.has_option('fapi', 'pass64'): + self.__f5api_pass = base64.decodestring( + config.get('fapi', 'pass64')) + else: + prompt = 'Enter API password for user ' + self.__f5api_user + ': ' + self.__f5api_pass = getpass.getpass(prompt) - def __init__(self, config_file): - config = ConfigParser.ConfigParser() - config.read(config_file) + self.__login() - if config.has_option('fapi', 'user'): - __f5api_user = config.get('fapi', 'user') - else: - __f5api_user = getpass.getuser() - if config.has_option('fapi', 'pass64'): - __f5api_pass = base64.decodestring(config.get('fapi', 'pass64')) - else: - prompt = 'Enter API password for user ' + __f5api_user + ': ' - __f5api_pass = getpass.getpass(prompt) + def __args_merge(self, config, args): + ''' Merges args to the config object ''' - print __f5api_pass + if not config.has_section('args'): + config.add_section('args') + + for k, v in args.items(): + if args['v']: print "Set arg %s: %s" % (k, v) + config.set('args', k, str(v)) + + self.config = config + + + def __login(self): + ''' Logs into the F5 BigIP SOAP API ''' + + if self.config.getboolean('args', 'v'): + print 'Login to BigIP API' + + apiuri = self.config.get('fapi', 'apiuri') + # ... to be done 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='Print version') - parser.add_argument('-C', action='store', help='Config file', - default=expanduser('~') + '/.fapi.conf') - args = vars(parser.parse_args()) - - if args['v']: - print 'Verbose' - if args['V']: - print 'This is ' + __program__ + ' version ' + __version__ - - fapi = Fapi(args['C']) + ''' 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='Print version') + parser.add_argument('-C', action='store', help='Config file', + default=expanduser('~') + '/.fapi.conf') + args = vars(parser.parse_args()) + + if args['V']: + print 'This is ' + __program__ + ' version ' + __version__ + + fapi = Fapi(args) + print str(fapi.config) +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 |
