← Back to team overview

openstack team mailing list archive

Re: Nova session question

 

I suspect you are not loading the flags that are actually in use by the program.  If you are running nova using sqllite, it is possible that your program is accessing
a different sqlite database.  you can do the following to use the same process for loading flags that nova does:

import sys
from nova import flags
from nova import utils
FLAGS = flags.FLAGS

utils.default_flagfile()
FLAGS(sys.argv)

Make sure you start from the same working directory that you start the nova services from as well.  It is possible that your code is a little off as well

from nova import context
from nova import db
ctx = context.get_admin_context()
result = db.service_get_all_compute_sorted(ctx)

Or direct sqlalchemy usage

from nova.db.sqlalchemy import models
from nova.db.sqlalchemy.session import get_session
session = get_session()
result = session.query(models.Instance).filter_by(deleted=False).all()

Vish

On Dec 6, 2010, at 7:01 AM, jaiber john wrote:

> hello,
> 
> I’m trying to read some values from the db of Nova, using Sql alchemy interface.
> I found that I need to get a session, which is authenticated. I wrote
> a simple program to read instance cores from the instances table, but
> it’s not working. Can you please check and let me know how to proceed?
> 
> I tried 2 ways: Getting a context, and getting a session, however I
> didnt get any output from this code snippet. Can someone point out the
> error?
> 
> 
>        ctx = context.RequestContext('admin', 'admin', is_admin=True)
> 
>        print "Got ctx", (ctx)
>        print "DB conn flags", (FLAGS.sql_connection)
> 
>        session = get_session()
> 
>        session.begin()
>        instances = session.query(models.Instance).all()
> 
>        for i in instances:
>            print i         # Nothing is printed here as instances is empty
> 
>        results = db.service_get_all_compute_sorted(ctx)
>        for result in results: # Nothing is returned here as well
>            (service, instance_cores) = result
>            print service, instance_cores
> 
> 
> 
> 
> Thanks!
> Jaiber
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~openstack
> Post to     : openstack@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~openstack
> More help   : https://help.launchpad.net/ListHelp




References