summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow (lxpbuetow.webde.local) <paul.buetow@1und1.de>2014-03-31 21:37:19 +0200
committerPaul Buetow (lxpbuetow.webde.local) <paul.buetow@1und1.de>2014-03-31 21:37:19 +0200
commit3921a6ea87c48a4bf2a6f2f3f27bac55c70c188a (patch)
treea213853b763768d7b2efbba4d4cb5ee74a203e43
parent6deba4e862a318c16df57625880bd1e7524a734e (diff)
can login via bigsuds
-rw-r--r--fapi.conf.sample6
-rwxr-xr-xfapi.py41
2 files changed, 27 insertions, 20 deletions
diff --git a/fapi.conf.sample b/fapi.conf.sample
index 15fb1ab..a76302e 100644
--- a/fapi.conf.sample
+++ b/fapi.conf.sample
@@ -1,4 +1,4 @@
[fapi]
-user: paul
-pass64: Zm9vYmFyYmF6
-apiuri: https://bigip.example.com
+username: paul
+password64: Zm9vYmFyYmF6
+hostname: bigip.example.com
diff --git a/fapi.py b/fapi.py
index 8897763..83d5f70 100755
--- a/fapi.py
+++ b/fapi.py
@@ -1,11 +1,12 @@
#!/usr/bin/env python
-# 2014 (c) Paul Buetow
+# 2014 (c) Paul C. Buetow
import argparse
import base64
import getpass
import sys
+import bigsuds
from os.path import expanduser
@@ -18,8 +19,6 @@ class Fapi(object):
''' The main F5 API Tool Object '''
config = None
- __f5api_user = ''
- __f5api_pass = ''
def __init__(self, args):
''' Initialize the config file, username and password '''
@@ -35,22 +34,21 @@ class Fapi(object):
self.config = config
self.__args_merge(args)
- if config.has_option('fapi', 'user'):
- self.__f5api_user = config.get('fapi', 'user')
+ if config.has_option('fapi', 'username'):
+ username = config.get('fapi', 'username')
else:
- self.__f5api_user = getpass.getuser()
+ username = getpass.getuser()
- if config.has_option('fapi', 'pass64'):
- self.__f5api_pass = base64.decodestring(
- config.get('fapi', 'pass64'))
+ if config.has_option('fapi', 'password64'):
+ password = base64.decodestring(config.get('fapi', 'password64'))
else:
- prompt = 'Enter API password for user %s: ' % self.__f5api_user
- self.__f5api_pass = getpass.getpass(prompt)
+ prompt = 'Enter API password for user %s: ' % username
+ password = getpass.getpass(prompt)
- self.__login()
+ self.__login(username, password)
- def __args_merge(self, args):
+ def __args_merge(self, args):
''' Merges args to the config object '''
if not self.config.has_section('args'):
@@ -61,14 +59,23 @@ class Fapi(object):
self.config.set('args', k, str(v))
- def __login(self):
+ def __login(self, username, password):
''' Logs into the F5 BigIP SOAP API '''
if self.config.getboolean('args', 'v'):
- print 'Login to BigIP API'
+ print 'Login to BigIP API with user %s' % username
+
+ hostname = self.config.get('fapi', 'hostname')
+
+ try:
+ b = bigsuds.BIGIP(
+ hostname = hostname,
+ username = username,
+ password = password,
+ )
+ except Exception, e:
+ print "Exception: %s" % e
- apiuri = self.config.get('fapi', 'apiuri')
- # ... to be done
if __name__ == '__main__':
''' The main function, here we will have Popcorn for free! '''