def __init__(self, host, port, user, passwd, retries=60, delay=10, log_lvl=logging.INFO, keyPairFiles=None, timeout=10.0): self.host = None self.port = 22 self.user = user self.passwd = passwd self.keyPairFiles = keyPairFiles self.ssh = SSHClient() self.ssh.set_missing_host_key_policy(AutoAddPolicy()) self.retryCnt = 0 self.delay = 0 self.timeout = 3.0 self.logger = MarvinLog('ssh').getLogger() # Check invalid host value and raise exception # Atleast host is required for connection if host is not None and host != '': self.host = host if retries is not None and retries > 0: self.retryCnt = retries if delay is not None and delay > 0: self.delay = delay if timeout is not None and timeout > 0: self.timeout = timeout if port is not None and port >= 0: self.port = port if self.createConnection() == FAILED: raise internalError("Connection Failed")
resultRow = [] cursor = None try: cursor = self.db.cursor() cursor.execute(sql) result = cursor.fetchall() if result is not None: for r in result: resultRow.append(r) return resultRow except pymysql.MySQLError, e: raise cloudstackException.dbException("db Exception:%s"%e[1]) except: raise cloudstackException.internalError(sys.exc_info()) finally: if cursor is not None: cursor.close() def executeSqlFromFile(self, fileName=None): if fileName is None: raise cloudstackException.InvalidParameterException("file can't not none") if not os.path.exists(fileName): raise cloudstackException.InvalidParameterException("%s not exists"%fileName) sqls = open(fileName, "r").read() return self.execute(sqls) if __name__ == "__main__":
cursor = self.db.cursor() cursor.execute(sql) result = cursor.fetchall() if result is not None: for r in result: resultRow.append(r) return resultRow except pymysql.MySQLError, e: if cursor is not None: cursor.close() raise cloudstackException.dbException("db Exception:%s"%e[1]) except: if cursor is not None: cursor.close() raise cloudstackException.internalError(sys.exc_value) def executeSqlFromFile(self, fileName=None): if fileName is None: raise cloudstackException.InvalidParameterException("file can't not none") if not os.path.exists(fileName): raise cloudstackException.InvalidParameterException("%s not exists"%fileName) sqls = open(fileName, "r").read() return self.execute(sqls) if __name__ == "__main__": db = dbConnection() '''
cursor = None try: # commit to restart the transaction, else we don't get fresh data self.db.commit() cursor = self.db.cursor() cursor.execute(sql) result = cursor.fetchall() if result is not None: for r in result: resultRow.append(r) return resultRow except pymysql.MySQLError, e: raise cloudstackException.dbException("db Exception:%s" % e) except: raise cloudstackException.internalError(sys.exc_info()) finally: if cursor is not None: cursor.close() def executeSqlFromFile(self, fileName=None): if fileName is None: raise cloudstackException.InvalidParameterException( "file can't not none") if not os.path.exists(fileName): raise cloudstackException.InvalidParameterException( "%s not exists" % fileName) sqls = open(fileName, "r").read() return self.execute(sqls)