Thanks, Murphy.

Here are the additional info:

I tried no #1. Looks OK


nox@nox-ThinkPad-T420:~/pox$ echo "import psycopg2" > testme.py
nox@nox-ThinkPad-T420:~/pox$ python testme.py
nox@nox-ThinkPad-T420:~/pox

My coomponent is in pox/ext
 ls ext
dbInterface.html  nn       vnbak1       vn_core.pyo         vn_dbTest.py
__init__.py       poxdesk  vn_core.old  vn_core.src         vn_dbTest.pyc
init.py           README   vn_core.py   vn_dbInterface.py   vn_test.py
__init__.pyo      vnbak    vn_core.pyc  vn_dbInterface.pyc  vn_test.pyc


Tried #2:
   1. With 'import psycopg2" in vn_dbInterface.py

nox@nox-ThinkPad-T420:~/pox$ ./debug-pox.py openflow vn_dbInterface
POX 0.1.0 (betta) / Copyright 2011-2013 James McCauley, et al.
Module not found: vn_dbInterface
nox@nox-ThinkPad-T420:~/pox$ 

   2. Commented out "import psycopg2" in vn_dbInterface.py. It works.


nox@nox-ThinkPad-T420:~/pox$ ./debug-pox.py py openflow vn_dbInterface
POX 0.1.0 (betta) / Copyright 2011-2013 James McCauley, et al.
Content Type: text/html

base: /home/nox/pox/ext
 Creating vn_dnInterface Object
CreateDB: CreateDB on SQL server Failed %s
DEBUG:core:POX 0.1.0 (betta) going up...
DEBUG:core:Running on PyPy (2.7.2/Jun 07 2012)
DEBUG:core:Platform is Linux-3.5.0-23-generic-i686-with-debian-wheezy-sid
INFO:core:POX 0.1.0 (betta) is up.
This program comes with ABSOLUTELY NO WARRANTY.  This program is free software,
and you are welcome to redistribute it under certain conditions.
Type 'help(pox.license)' for details.

Ready.
POX> 
POX> sys.path
['/home/nox/pox', '/home/nox/pox/pypy/lib_pypy/__extensions__', 
'/home/nox/pox/pypy/lib_pypy', '/home/nox/pox/pypy/lib-python/2.7', 
'/home/nox/pox/pypy/lib-python/2.7/lib-tk', 
'/home/nox/pox/pypy/lib-python/2.7/plat-linux2', 
'/home/nox/pox/pypy/site-packages', '/home/nox/pox/pox', '/home/nox/pox/ext', 
'/usr/lib/python2.7/dist-packages/psycopg2']
POX> 
==========================================================================


The code: vn_dbInterface.py

import os.path
import pox
from pox.core import core
from pox.lib.recoco import Timer
import psycopg2

print "Content Type: text/html\n\n"

class vn_dbInterface (object):
  def __init__ (self):
    print " Creating vn_dnInterface Object"
    Str = self.CreateDB()
    print Str

#Create db vndb
  def CreateDB(self):
    conn = None
    s = "CreateDB: CreateDB on SQL server Failed %s"
    try:
      conn= psycopg2.connect(host='localhost', user='postgres')
      conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
      cursor = conn.cursor()
      cursor.execute ("DROP DATABASE IF EXISTS vndb")
      cursor.execute ("CREATE DATABASE vndb")
      cursor.close()
      s = "CreateDB():VN DB created on SQL server"
    except psygcop2.DatabaseError, e:
      if conn:
        conn.rollback()
        s = "CreateDB: CreateDB on SQL server Failed %s" % e
    finally:
      if conn:
        conn.close()
      return s

  def CreateTable(self,tableName):
    conn = None
    try:
      conn= psycopg2.connect(database='vndb', host='localhost', user='postgres')
      conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
      cursor = conn.cursor()
      cursor.execute ("DROP TABLE IF EXISTS " + tableName)
      cursor.execute ("CREATE TABLE " + tableName + "(VNID INT PRIMARY KEY, 
dl_type INT,\
                       SrcIP VARCHAR(15), DestIP VARCHAR(15), sPort INT, dPort 
INT, FlowID INT,\
                       switch_dpid INT, outAction VARCHAR[10], VNStat 
VARCHAR(255), \
                       TxCount INT, RxCount INT)")
      cursor.close()
      s = "CreateTable(): CreateTable on SQL server: Success"
    except psygcop2.Error, e:
      s = "CreateTable():CreateTable on SQL server Failed %s" % e
    finally:
      if conn:
        conn.close()
      return s

def launch ():
  base = os.path.dirname(__file__)
  print "base:", base
  core.registerNew(vn_dbInterface)





________________________________
 From: Murphy McCauley <[email protected]>
To: Senthil <[email protected]> 
Cc: "[email protected]" <[email protected]> 
Sent: Saturday, March 9, 2013 3:44 PM
Subject: Re: [pox-dev] how to import non-pox compnents from pox
 



On Mar 9, 2013, at 3:28 PM, Senthil wrote:

My database interface file - dbInterface.py that launches my pox componet - 
dbInface  imports
> 
>
>
>import psycopg2  -  to access psycopg2 pkg under 
>/usr/lib/python2.7/dist-packages/psycopg2
>
>
>My module does not come up with 'import psycopg2' but is OK when I commented 
>out this one
>
>
>I have added the following in pos/pox/boot.sh and the same result
>
>
>
> sys.path.append(os.path.abspath(os.path.join(sys.path[0], 
>'/usr/lib/python2.7/dist-packages/psycopg2/')))
>
>
>How to import any non-pox modules in any pox files?

POX shouldn't really make this any more or less difficult than usual, though it 
may hide potentially useful traceback messages especially when run in 
"production mode".

Some things to try:
1) Try a simple program:
$ echo "import psycopg2" > testme.py
$ python testme.py

.. what happens?

2) Run POX in debug mode using debug-pox.py instead of pox.py:
$  ./debug-pox.py openflow <the rest of your components/config here>

3) Give us more information.  You indicate that it doesn't work, but what 
actually happens?  What does the log say?  Is there an error message?  A 
traceback?  Does your computer catch on fire?  In particular, if #2 doesn't 
work, it'd be useful to see what it prints out.

-- Murphy

Reply via email to