1. 程式人生 > >python cx_oracle 繫結變數

python cx_oracle 繫結變數

insert into tlcb_collect_f5 values(:stime,:virtual_servers,:default_pool_name,:ipaddr,:port,:AVAILABILITY_STATUS,:ENABLED_STATUS,:POOL_MEMBER_STATUS);


# -*- coding: utf-8 -*- 
import sys
import pycontrol.pycontrol as pc
import time
import csv
import ssl
import cx_Oracle 
import time
import datetime
conn = cx_Oracle.connect('tlcbuser/
[email protected]
/tlyy') cursor = conn.cursor() #coding:UTF-8 #獲取當前時間 time_now = int(time.time()) #轉換成localtime #time_local = time.localtime(time_now) #print time_local #dt = time.strftime("%Y-%m-%d %H:%M:%S",time_local) dt=datetime.datetime.now() b = pc.BIGIP( hostname = '20.2.200.1', username = 'zjtlcb', password = '12345678', fromurl = True, wsdls=['LocalLB.VirtualServer']) pool01 = b.LocalLB.VirtualServer c = pc.BIGIP( hostname = '2.2.20.99', username = 'x'x, password = 'xx', fromurl = True, wsdls=['LocalLB.PoolMember']) pool02 = c.LocalLB.PoolMember aa=pool01.get_list() for x in aa: a= pool01.get_default_pool_name(virtual_servers=[x]) # print a if a[0]: b= pool02.get_object_status(pool_names=[a[0]]) # print b # print type(b) for y in b: # print '11111111111' # print y # # print type(y) # print '11111111111' for z in y: # print '22222222222' # print z # print type(z) # print '22222222222' print x+'=>'+a[0]+'=>'+z.member.address+':'+str(z.member.port)+'=>'+z.object_status.availability_status+'=>'+z.object_status.enabled_status+'=>'+z.object_status.status_description param={'stime':dt,'virtual_servers':x,'default_pool_name':a[0],'ipaddr':z.member.address,'port':str(z.member.port),'AVAILABILITY_STATUS':z.object_status.availability_status,'ENABLED_STATUS':z.object_status.enabled_status,'POOL_MEMBER_STATUS':z.object_status.status_description} cursor.execute('insert into tlcb_collect_f5 values(:stime,:virtual_servers,:default_pool_name,:ipaddr,:port,:AVAILABILITY_STATUS,:ENABLED_STATUS,:POOL_MEMBER_STATUS)',param) conn.commit() # print z.object_status cursor.close