Home > openstack > Querying Openstack Database to dig deep down

Querying Openstack Database to dig deep down

Openstack has many components and each components has many commands as well. But almost every openstack command query openstack database tables for the result. For example, if you issue ‘nova list’ command from nova-client, the client get the output from ‘nova’ database and from ‘instance’ table. The purpose of this note, is to explore openstack databases to be more familiar with openstack and demystify it.

In my current devstack state, if I issue ‘nova list’ it shows the following result

stack@9734efd5-6fcd-4127-92b4-6715a66fda9d:/opt/stack$ nova list
+--------------------------------------+---------+--------+------------+-------------+---------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+---------+--------+------------+-------------+---------------------+
| 1ad34a43-27b8-40bc-8513-24bfb24945c9 | prosun1 | ACTIVE | None | Running | private=172.24.17.2 |
| b815a53d-7e16-403e-82c2-d9f25bc02f0e | prosun2 | ACTIVE | None | Running | private=172.24.17.3 |
| 02528053-71cd-439a-a006-099ab10ff0c4 | prosun3 | ACTIVE | None | Running | private=172.24.17.4 |
| 139d1e92-f92b-4996-af00-1762696a2f8c | prosun5 | ERROR | None | NOSTATE | private=172.24.17.6 |
+--------------------------------------+---------+--------+------------+-------------+---------------------+

lets see how we can generate this (‘nova list’ output) by directly manipulating mysql database. Here I assume that openstack / devstack is using the default mysql db.

#connect to openstack database;
mysql -u root
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cinder |
| glance |
| keystone |
| mysql |
| nova |
| performance_schema |
| test |
+--------------------+

#now change to nova database;
mysql> use nova;
mysql> show tables;
mysql> show tables;
+--------------------------------------------+
| Tables_in_nova |
+--------------------------------------------+
| cells |
| certificates |
| compute_node_stats |
| compute_nodes |
| console_pools |
| consoles |
| dns_domains |
| fixed_ips |
| floating_ips |
| instance_actions |
| instance_actions_events |
| instance_faults |
| instance_types |
| instances |
| networks |
+--------------------------------------------+
--- This list is truncated ---
# Now, we will see all the virtual machines (both deleted and active) that has been created. We may not see all the vms when issuing 'nova list' because of the different status of these machines.
mysql> select hostname from instances;
+------------------+
| hostname |
+------------------+
| myfirstinstance |
| mysecondinstance |
| mythirdinstance |
| my4thinstance |
| my5thinstance |
| my6thinstance |
| my7thinstance |
+---- Truncated ---+

Some important columns of instances table are host, hostname, vm_status, deleted, task_state, deleted and so on. In order to see the active vms (ie, not deleted ones), we need to query instance table with ‘deleted’ set to 0.

mysql> select uuid, hostname, vm_state, task_state, power_state, deleted from instances where deleted=0;
+--------------------------------------+----------+----------+------------+-------------+---------+
| uuid | hostname | vm_state | task_state | power_state | deleted |
+--------------------------------------+----------+----------+------------+-------------+---------+
| 1ad34a43-27b8-40bc-8513-24bfb24945c9 | prosun1 | active | NULL | 1 | 0 |
| b815a53d-7e16-403e-82c2-d9f25bc02f0e | prosun2 | active | NULL | 1 | 0 |
| 02528053-71cd-439a-a006-099ab10ff0c4 | prosun3 | active | NULL | 1 | 0 |
| 139d1e92-f92b-4996-af00-1762696a2f8c | prosun5 | error | NULL | 0 | 0 |
+--------------------------------------+----------+----------+------------+-------------+---------+
4 rows in set (0.00 sec)

This generate the very similar output (without rephrasing) of the output of ‘nova list’. This way, by querying openstack databases you can dig deep down into the openstack bitch…

10/15/2013
@UTSA.

Advertisements
Categories: openstack Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: