Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/local/bin/python # encoding: utf-8 *Class to setup database object for the breaker*
:Author: David Young
:Date Created: October 29, 2015 """ ################# GLOBAL IMPORTS ####################
""" *The worker class for the database module*
**Key Arguments:** - ``log`` -- logger - ``settings`` -- the settings dictionary """ # INITIALISATION
self, log, settings=False,
):
del self return None
# METHOD ATTRIBUTES """ *get the database object*
**Return:** - ``self.transientsDbConn, self.ps1gwDbConn, self.cataloguesDbConn`` -- three database connections """
self): """ *setup database connections for transient and catalogue databases* """
db)
# SETUP TUNNEL IF REQUIRED # TEST TUNNEL DOES NOT ALREADY EXIST self.settings["database settings"][db]["host"], sshPort) else: # GRAB TUNNEL SETTINGS FROM SETTINGS FILE ru = tunnel["remote user"] rip = tunnel["remote ip"] rh = tunnel["remote datbase host"]
cmd = "ssh -fnN %(ru)s@%(rip)s -L %(sshPort)s:%(rh)s:3306" % locals() p = Popen(cmd, shell=True, close_fds=True) output = p.communicate()[0] self.log.debug('output: %(output)s' % locals())
# TEST CONNECTION - QUIT AFTER SO MANY TRIES connected = False count = 0 while not connected: for db in tunnelDatabases[tunnelName]: connected = self._checkServer( self.settings["database settings"][db]["host"], sshPort) if connected: break time.sleep(1) count += 1 if count == 5: self.log.error( 'cound not setup tunnel to remote datbase' % locals()) sys.exit(0)
# SETUP A DATABASE CONNECTION FOR THE ps1gw "ps1gw"]["host"] "ps1gw"]["user"] "ps1gw"]["password"] "ps1gw"]["db"] "ps1gw"]["port"] host=host, user=user, passwd=passwd, db=dbName, port=port, use_unicode=True, charset='utf8' )
# SETUP A DATABASE CONNECTION FOR THE ps13pi "ps13pi"]["host"] "ps13pi"]["user"] "ps13pi"]["password"] "ps13pi"]["db"] "ps13pi"]["port"] host=host, user=user, passwd=passwd, db=dbName, port=port, use_unicode=True, charset='utf8' )
# SETUP A DATABASE CONNECTION FOR THE altas DATABASE "atlas"]["host"] "atlas"]["user"] "atlas"]["password"] "atlas"]["db"] "atlas"]["port"] host=host, user=user, passwd=passwd, db=dbName, port=port, use_unicode=True, charset='utf8' )
# SETUP DATABASE CONNECTION FOR WAVE DATABASE "ligo_virgo_waves"]["host"] "ligo_virgo_waves"]["user"] "ligo_virgo_waves"]["password"] "ligo_virgo_waves"]["db"] "ligo_virgo_waves"]["port"] host=host, user=user, passwd=passwd, db=dbName, port=port, use_unicode=True, charset='utf8' )
# SETUP DATABASE CONNECTION FOR CATALOGUE DATABASE "catalogues"]["host"] "catalogues"]["user"] "catalogues"]["password"] "catalogues"]["db"] "catalogues"]["port"] host=host, user=user, passwd=passwd, db=dbName, port=port, use_unicode=True, charset='utf8' )
""" *Check that the TCP Port we've decided to use for tunnelling is available* """
# CREATE A TCP SOCKET """Attempting to connect to `%(address)s` on port `%(port)s`""" % locals()) """Connected to `%(address)s` on port `%(port)s`""" % locals()) except socket.error, e: self.log.info( """Connection to `%(address)s` on port `%(port)s` failed - try again: %(e)s""" % locals()) return False
return None
# xt-class-method
main() |