Playing with OpenStack Nova APIs from a Python Shell

Image by urielsc26 / Unsplash

A quick hack. If you want to call various OpenStack Nova APIs outside the context of a service like nova-compute, there’s a good chance you’ll need some configuration. If you have deployment, you’ll likely have a configuration file with all the necessary details. DevStack places its Nova configuration files at /etc/nova. Nova provides APIs, which are tiny wrappers around oslo.db functionality, for loading these.

>>> import nova.conf
>>> from nova import config
>>> config.parse_args('foo --config-file /etc/nova/nova.conf'.split())
>>> CONF = nova.conf.CONF

With you configuration, you can now do things that require this configuration. For example, let’s look at our databases using SQLAlchemy.

>>> from nova.db.main import api
>>> engine = api.get_engine()
>>> import sqlalchemy
>>> sqlalchemy.inspect(engine).has_table('alembic_version')
True
>>> sqlalchemy.inspect(engine).has_table('migrate_version')
False

This can be handy to get you out of a hole, or to hack on stuff in a development environment.

comments powered by Disqus