Skip to content

Commit

Permalink
Added support for pymysql in addition to mysql.connector
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Smith committed Mar 19, 2015
1 parent a00b3da commit 0840513
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions applications/endpointtracker/aci-endpoint-tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
"""
import sys
import acitoolkit.acitoolkit as ACI
import mysql.connector
import warnings
try:
import mysql.connector as mysql
except ImportError:
import pymysql as mysql


def convert_timestamp_to_mysql(timestamp):
Expand All @@ -45,23 +49,27 @@ def convert_timestamp_to_mysql(timestamp):
sys.exit(0)

# Create the MySQL database
cnx = mysql.connector.connect(user=args.mysqllogin,
password=args.mysqlpassword,
host=args.mysqlip)
cnx = mysql.connect(user=args.mysqllogin,
password=args.mysqlpassword,
host=args.mysqlip)
c = cnx.cursor()
c.execute('CREATE DATABASE IF NOT EXISTS acitoolkit;')
cnx.commit()
with warnings.catch_warnings():
warnings.filterwarnings('ignore')
c.execute('CREATE DATABASE IF NOT EXISTS acitoolkit;')
cnx.commit()
c.execute('USE acitoolkit;')
c.execute('''CREATE TABLE IF NOT EXISTS endpoints (
mac CHAR(18) NOT NULL,
ip CHAR(16),
tenant CHAR(100) NOT NULL,
app CHAR(100) NOT NULL,
epg CHAR(100) NOT NULL,
interface CHAR(100) NOT NULL,
timestart TIMESTAMP NOT NULL,
timestop TIMESTAMP);''')
cnx.commit()
with warnings.catch_warnings():
warnings.filterwarnings('ignore')
c.execute('''CREATE TABLE IF NOT EXISTS endpoints (
mac CHAR(18) NOT NULL,
ip CHAR(16),
tenant CHAR(100) NOT NULL,
app CHAR(100) NOT NULL,
epg CHAR(100) NOT NULL,
interface CHAR(100) NOT NULL,
timestart TIMESTAMP NOT NULL,
timestop TIMESTAMP);''')
cnx.commit()

# Download all of the Endpoints and store in the database
endpoints = ACI.Endpoint.get(session)
Expand Down

0 comments on commit 0840513

Please sign in to comment.