def getConnection(self, extraParams={}):
     if self.dbtype == 'mysql':
         from Products.ZenUtils.mysql import MySQLdb
         p = self.dbparams
         params = {}
         params['host'] = p['host']
         params['port'] = int(p['port'])
         params['user'] = p['user']
         params['passwd'] = p['password']
         params['db'] = p['db']
         if 'socket' in p:
             params['unix_socket'] = p['socket']
         elif self._db == 'zep':
             # ZEP does not use unix_socket, its a java app
             # assume the socket is the same as zodb's if the
             # hosts are the same
             zodbZenDB = ZenDB('zodb')
             if zodbZenDB.dbparams['host'] == params['host']:
                if 'socket' in zodbZenDB.dbparams:
                    params['unix_socket'] = zodbZenDB.dbparams['socket']
         params.update(extraParams)
         connection = MySQLdb.connect(**params)
         return connection
     else:
         raise NotImplemented("This method does not support %s" % self.dbtype) 
Exemple #2
0
 def getConnection(self, extraParams={}):
     if self.dbtype == 'mysql':
         from Products.ZenUtils.mysql import MySQLdb
         p = self.dbparams
         params = {}
         params['host'] = p['host']
         params['port'] = int(p['port'])
         params['user'] = p['user']
         params['passwd'] = p['password']
         params['db'] = p['db']
         if 'socket' in p:
             params['unix_socket'] = p['socket']
         elif self._db == 'zep':
             # ZEP does not use unix_socket, its a java app
             # assume the socket is the same as zodb's if the
             # hosts are the same
             zodbZenDB = ZenDB('zodb')
             if zodbZenDB.dbparams['host'] == params['host']:
                 if 'socket' in zodbZenDB.dbparams:
                     params['unix_socket'] = zodbZenDB.dbparams['socket']
         params.update(extraParams)
         connection = MySQLdb.connect(**params)
         return connection
     else:
         raise NotImplemented("This method does not support %s" %
                              self.dbtype)
Exemple #3
0
    def getMySQLVersion(self):
        """
        This function returns a Version-ready tuple. For use with the Version
        object, use extended call syntax:

            v = Version(*getMySQLVersion())
            v.full()
        """
        cfg = getGlobalConfiguration()
        params = {
                'host': cfg.get("zodb-host", "localhost"),
                'port': int(cfg.get("zodb-port", 3306)),
                'user': cfg.get("zodb-user", "zenoss"),
                'passwd': cfg.get("zodb-password", "zenoss"),
            }
        if "zodb-socket" in cfg:
            params["unix_socket"] = cfg["zodb-socket"]
        db = None
        useZenDS = os.environ.get("USE_ZENDS", False)
        name = "ZenDS" if useZenDS else "MySQL"
        try:
            db = MySQLdb.connect(**params)
            db.query("select version()")
            data = db.use_result().fetch_row()
            if data:
                regex = re.compile("([0-9]+)\.([0-9]+)\.([0-9]+)(.*)")
                versionstr = data[0][0]
                match = regex.match(versionstr)
                if match:
                    major, minor, micro, info = match.groups()
                    return Version(
                            name,
                            int(major), int(minor), int(micro), 0,
                            versionstr
                        )
            raise RuntimeError("Unable to determine %s version" % (name,))
        finally:
            if db:
                db.close()