From 43b123bc07a2b0094ac1293a46ba33f6c7afa2cb Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow" Date: Sun, 13 Apr 2014 15:12:25 +0200 Subject: trying a list of loadbalancers and use the first one which has working iControl --- src/fapi.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/fapi.py b/src/fapi.py index 9d2cdc9..c33da9d 100755 --- a/src/fapi.py +++ b/src/fapi.py @@ -45,18 +45,26 @@ class Fapi(object): prompt = 'Enter API password for user %s: ' % username password = getpass.getpass(prompt) self.info('Login to BigIP API with user %s' % username) - hostname = c.get('fapi', 'hostname') - - # Enhance to try to login to a list of hosts - try: - self._f5 = bigsuds.BIGIP(hostname = hostname, - username = username, - password = password) - self._partition = c.get('fapi', 'partition') - self.info('Setting partition to \'%s\'' % self._partition) - self._f5.Management.Partition.set_active_partition(self._partition) - except Exception, e: - self.info(e) + self._partition = c.get('fapi', 'partition') + + # Try a comma separated lists of F5 boxes, use the first one + err = None + for hostname in c.get('fapi', 'hostnames').split(','): + try: + self.info('Trying to login to \'%s\'' % hostname) + self._f5 = bigsuds.BIGIP(hostname = hostname, + username = username, + password = password) + self._f5.Management.Partition.set_active_partition(self._partition) + self.info('Set partition to \'%s\'' % self._partition) + err = None + break + except Exception, e: + err = '%s:%s' % (hostname, e) + pass + + if err: + self.info(err) sys.exit(2) -- cgit v1.2.3