[openstack-dev] Extending nova models

Solly Ross sross at redhat.com
Thu May 22 14:57:57 UTC 2014


Actually, that line you linked to about IMPL is a bit misleading.  In this case,
under the hood IMPL is really just the sqlalchemy implementation of the Nova db api at
https://github.com/openstack/nova/blob/master/nova/db/sqlalchemy/api.py#L2404.

In Nova we don't "insert a row in to a table" per se.  Instead (in general), we have
sqlalchemy models which are then saved (which handles inserting, etc).  So the path
is "api wrapper (the file you linked to) --> sqlalchemy api implementation --> sqlalchemy
model".

Hope this helps.

Best Regards,
Solly Ross

----- Original Message -----
> From: "Rad Gruchalski" <radek at gruchalski.com>
> To: openstack-dev at lists.openstack.org
> Sent: Wednesday, May 21, 2014 3:38:04 PM
> Subject: [openstack-dev] Extending nova models
> 
> Hi everyone,
> 
> This is my first question here. I hope I could get an answer for the problem
> I'm currently facing in the development of a nova API extension. I am trying
> to add a couple of API endpoints that would serve as an interface to the
> table storing some data. I was able to create an API endpoint by placing my
> extension in api/openstack/compute/contrib and modifying the policy.json
> file. This is now working.
> 
> I then added the migration to create a table to
> nova/db/sqlalchemy/migrate_repo_versions/245_add_custom_table.
> 
> After unstack.sh and stack.sh (I'm using devstack) I can see my table being
> created. Great.
> 
> Next, I proceeded with creating an object definition and created a file in
> nova/objects. I am basing myself on keypairs.py example
> (https://github.com/openstack/nova/blob/2efd3faa3e07fdf16c2d91c16462e7e1e3f33e17/nova/api/openstack/compute/contrib/keypairs.py#L97)
> 
> self.api.create_key_pair
> 
> calls this
> https://github.com/openstack/nova/blob/839fe777e256d36e69e9fd7c571aed2c860b122c/nova/compute/api.py#L3512
> the important part is
> 
> keypair = keypair_obj.KeyPair()
> keypair.user_id = user_id
> keypair.name = key_name
> keypair.fingerprint = fingerprint
> keypair.public_key = public_key
> keypair.create(context)
> 
> `KeyPair()` is
> https://github.com/openstack/nova/blob/master/nova/objects/keypair.py
> 
> this has a method
> https://github.com/openstack/nova/blob/master/nova/objects/keypair.py#L52
> and it's calling `db_keypair = db.key_pair_create(context, updates)`
> `db` points to `from nova import db`
> 
> which I believe points to this
> https://github.com/openstack/nova/blob/master/nova/db/__init__.py
> which loads https://github.com/openstack/nova/blob/master/nova/db/api.py
> there's a function called
> https://github.com/openstack/nova/blob/master/nova/db/api.py#L922
> `key_pair_create`
> https://github.com/openstack/nova/blob/master/nova/db/api.py#L924
> 
> `IMPL` is
> https://github.com/openstack/nova/blob/master/nova/db/api.py#L69-L95
> but where is `IMPL.key_pair_create`?
> 
> Is there an easy way to insert a record into the table?
> Thank you for any pointers.
> 
> I’ve posted the same question on ask.openstack.org
> (https://ask.openstack.org/en/questions/30231).
> 
> 
> 
> 
> 
> 
> 
> 
> Kind regards,
> Radek Gruchalski
> radek at gruchalski.com
> de.linkedin.com/in/radgruchalski/
> +4917685656526
> 
> Confidentiality:
> This communication is intended for the above-named person and may be
> confidential and/or legally privileged.
> If it has come to you in error you must take no action based on it, nor must
> you copy or show it to anyone; please delete/destroy and inform the sender
> immediately.
> 
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
> 



More information about the OpenStack-dev mailing list