转载请注明
http://www.cnblogs.com/juandx/p/5418204.html
openstack有3个库,nova,neutron,keystone,我现在需要做的是跨库联表查询虚机的信息
获取一个虚机的floating_ip, fix_ip, project_name, user_name, hostname, host (不知道在instances表中host和node有什么区别) select j.floating_ip_address as floating_ip, i.fix_ip, i.port_id, i.project_name, i.user_name, i.hostname,i.host from neutron.floatingips as j right join (select h.ip_address as fix_ip,h.port_id, g.project_name, g.user_name, g.hostname,g.host from neutron.ipallocations as h right join(select f.name as project_name,e.name as user_name,e.hostname,e.port_id,e.host from keystone.project as f right join (select a.name,b.* from keystone.user as a right join (select substring(substring_index(c.network_info,‘ovs_interfaceid‘,-1),5,36) as port_id, d.* from nova.instance_info_caches as c right join nova.instances as d on c.instance_uuid=d.uuid where d.deleted=0) as b on a.id=b.user_id) as e on f.id=e.project_id) as g on g.port_id=h.port_id) as i on i.port_id=j.fixed_port_id order by host,project_name,user_name,floating_ip;
nova和neutron的连接关系在nova.instance_info_caches这个表中,里面有fix ip的port,可以去neutron.ipallocations这个表中找到对应分配的ip,然后去neutron.floatingips这个表中找对应的floatingip
nova和keystone的连接关系是nova.instances的user_id和project_id,这个就简单了
但是instance_info_caches中的信息是一个mediumstest类型的json,所以我用msyql 的substring_index过滤port的信息,没要找到在这样的数据中直接用key,value的方法,如果大神知道请告诉我。
时间: 2024-10-09 01:51:37