def __init__(self, log='Sync_Data', logerror='Error_Sync_Data'): self.db = osDb.DATABASE_NAME self.user = osDb.DATABASE_USER self.password = osDb.DATABASE_PASSWORD self.host = osDb.DATABASE_HOST self.port = osDb.DATABASE_PORT self.logger = getLog(log) self.logerr = getLog(logerror)
def get_job(host): """ return array tuple, job, job param host : thomson name """ argsJob = [] #argsJobPara = [] obJob = Job(host['host'], host['user'], host['passwd']) try: #lstjId = obJob.get_jobid_list() lstJob = obJob.get_job_non_jname() for item in lstJob: #isBackup = get_backup_job(host, item['jid']) tmp = (item['jid'], host['host'], item['state'], item['status'], item['prog'], item['ver'], item['startdate'], item['enddate']) argsJob.append(tmp) #logerr = getLog('Error_Sync_Data') #logerr.error("Get Job %s"%(argsJob)) #argsJobPara.append((item['jid'], host['host'], item['jname'], item['wid'],"{0}".format(isBackup))) except Exception as e: logerr = getLog('Error_Sync_Data') logerr.error("Get Job %s" % (e)) finally: return argsJob
def many_insert(self, table, data, *args): """ table: name table data: array tuple *args: chua cac filed """ col = ',' val = ',' for item in args: col += '%s,' % (item) val += '%s,' val = val[1:-1] col = col[1:-1] sql = "insert into {0} ({1}) values({2})".format(table, col, val) session = self.connect() cur = session.cursor() start = time.time() logger = getLog('Sync_Data') try: for item in data: cur.execute(sql, item) #host = item[2] cur.execute('commit;') #cur.execute('select * from workflow where host = \'{0}\''.format(host)) #results = cur.fetchall() session.commit() self.close_connect(session) logger.info('Insert workflow complited in %s.' % (time.time() - start)) except Exception as e: logerr = getLog('Error_Sync_Data') self.close_connect(session) logerr.error('Insert workflow error: %s.' % (e)) return 0 finally: return 0
def get_list_node_id(host): """ return array node id host: ip thomson """ args = [] db = Database() sql = "select nid from node where host = '{0}'".format(host) try: res = db.execute_query(sql) for item in res: args.append(item[0]) except Exception as e: logerr = getLog("Error_Sync_Data") logerr.error("Get node id %s" % (e)) finally: return args
def get_workflow(host): """ host: thomson name """ Worf = Workflow(host=host['host'], user=host['user'], passwd=host['passwd']) args = [] logerr = getLog('Error_Data') try: lstWorf = Worf.get_workflow() lstWorf = json.loads(lstWorf) for item in lstWorf: args.append((item['wid'], host['host'], item['name'])) except Exception as e: logerr.error("Get worlkfow %s" % (e)) raise return args
def get_node_detail(host): """ return array node detail host : thomson name """ args = [] lstnodeId = get_list_node_id(host['host']) try: for item in lstnodeId: node = NodeDetail(host['host'], host['user'], host['passwd'], item) array_jid = node.get_array_job_id() for ite in array_jid: args.append((int(item), host['host'], ite)) except Exception as e: logerr = getLog('Error_Data') logerr.error("Get node %s" % (e)) finally: return args
def get_job_param(host): """ return array tuple(job param) """ argsJobparam = [] obJob = Job(host['host'], host['user'], host['passwd']) try: lstjId = obJob.get_jobid_list() for item in lstjId: jname, wid, backup = JobDetail(host['host'], host['user'], host['passwd'], item).get_job_name_w_backup() argsJobparam.append((item, host['host'], jname, wid, backup)) print item #argsJobPara.append((item['jid'], host['host'], item['jname'], item['wid'],"{0}".format(isBackup))) except Exception as e: logerr = getLog('Error_Sync_Data') logerr.error("Get Job Param %s" % (e)) finally: return argsJobparam
def get_node(host): """ host: thomson name """ node = Node(host=host['host'], user=host['user'], passwd=host['passwd']) args = [] logerr = getLog('Error_Data') #print host['host'] try: lstNode = node.get_nodes() lstNode = json.loads(lstNode) #print len(lstNode) for item in lstNode: #print item args.append((item['nid'], host['host'], item['cpu'], item['alloccpu'], item['mem'], item['allocmem'], item['status'], item['state'], item['uncreahable'])) #print len(args) except Exception as e: logerr.error("Get node %s" % (e)) raise finally: #print len(args) return args