So I installed Jython on the Windows Server 2008 box which runs my LMS 4.1 installation, copied down some sample Java code from Cisco and translated that into Python. After a few tries to get Jython to find the right Java class path, it actually worked.
So here is the code (of course, userid and password have to be filled in) that prints a list of devices in the database:
#!/usr/bin/env jython
##
## Requires this: export CLASSPATH='E:\CSCOpx\lib\classpath'
##
import time
import java.sql
import com.sybase.jdbc2.jdbc.SybDriver
conn = java.sql.DriverManager.getConnection("jdbc:sybase:Tds:localhost:43441?SERVICENAME=cmfDb", userid, password)
print('[%s] INFO: Connection successful...' % time.strftime("%c"))
stmt = conn.createStatement()
query = "SELECT Device_Id, Device_Display_Name, Management_IPAddress FROM Network_Devices"
rs = stmt.executeQuery(query)
cnt = 0
while rs.next():
cnt += 1
print("%d. Device Id: %s" % (cnt, rs.getString("Device_Id")))
print(" Display name: %s" % rs.getString("Device_Display_Name"))
print(" Management IP address: %s" % rs.getString("Management_IPAddress"))
No comments:
Post a Comment