openstack的topo图

[url]http://haoningabc.iteye.com/blog/2317951[/url]装完openstack
[url]http://haoningabc.iteye.com/blog/2322169[/url]做完neutron的试验
复杂的网络关系还是无法获取,
做个topo图
[img]http://dl2.iteye.com/upload/attachment/0119/8932/4a089928-d4cf-340e-9cf2-00f36d3994f0.png[/img]
写个脚本查看nova和neutron的表的结构
mysql_openstack.sh:

#!/bin/sh
#for i in `awk ' {if(NR>4 && NR<40)print $2};' a.log `

mysql_user=root
mysql_password=haoning
mysql_host=mcon

if [ "$1" = "" ]
then
echo "please use ./mysql_openstack.sh [dbname], for example: ./mysql_openstack.sh keystone";
echo "this will exit."
exit 0;
fi

echo "use db " $1

for i in ` mysql -u$mysql_user -h$mysql_host -p$mysql_password $1 -e "show tables" |awk ' {if(NR>1)print $1};'`
do
if [ $i != "ml2_vxlan_allocations" ]
then
echo "mysql -u$mysql_user -h$mysql_host -p$mysql_password $1 -e \"select * from \`$i\`\"";
mysql -u$mysql_user -h$mysql_host -p$mysql_password $1 -e "select * from \`$i\`";
fi
done

./mysql_openstack.sh neutron
./mysql_openstack.sh nova

观察得到 nova库的instance
neutron库的,networks,routers,subnets,ports
这几个表看明白就理解neutron的基础概念了
网络,子网,路由器,端口

其实就是linux的

brctl show
ip netns
bridge fdb
ip neigh

veth pair,tap,桥,vxlan
等概念的组合
如果使用openstack命令

nova list
neutron net-list
neutron subnet-list
neutron router-list
neutron port-list


简单写个java的demo,
生成固定格式的json,
传给noflo显示成topo图

package openstacktopo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

//import net.sf.json.JSONObject;
//https://sourceforge.net/projects/json-lib/files/json-lib/json-lib-2.4/
public class Topo {
static {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (Exception e) {
e.printStackTrace();
}
}
public static Connection getConnection(String db) {
String url = "jdbc:mysql://192.168.139.251:3306/"+db;
String username = "root";
String password = "haoning";
Connection con = null;
try {
con = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
public Map getInstances() {//获取实例
Map vm_processes=new HashMap();
ResultSet rs = null;
Connection con = null;
try {
con = getConnection("nova");
PreparedStatement ps = null;
String sql = "select i.uuid,i.display_name,i.launched_on,i.vm_state from instances i where deleted =0 ";
ps = (PreparedStatement) con.prepareStatement(sql);
if (ps.execute()) {
rs = ps.getResultSet();
StringBuffer b = new StringBuffer();
while (rs.next()) {
JSONObject instance=new JSONObject();
JSONObject metadata=new JSONObject();
//System.out.println(rs.getString("uuid")+"\t");
//System.out.println(rs.getString("display_name")+"\t");
instance.put("component", "vm/"+rs.getString("uuid"));
metadata.put("type", "vm");
metadata.put("vm_id", rs.getString("uuid"));
metadata.put("vm_status", rs.getString("vm_state"));
metadata.put("label", rs.getString("display_name"));
instance.put("metadata", metadata);
//System.out.println(instance);
vm_processes.put("vm/"+rs.getString("uuid"), instance);
}
} else {
int i = ps.getUpdateCount();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
rs.close();
con.close();
} catch (Exception e2) {}
}
return vm_processes;
}
public List<JSONObject> get_instance_net() {//获取vm和网络的关系
List list_i_net=new ArrayList();
ResultSet rs = null;
Connection con = null;
try {
con = getConnection("nova");
PreparedStatement ps = null;
String sql = "select iic.network_info,i.uuid,i.display_name,i.launched_on from instance_info_caches iic , instances i where i.id=iic.id and i.deleted = 0";
ps = (PreparedStatement) con.prepareStatement(sql);
if (ps.execute()) {
rs = ps.getResultSet();
StringBuffer b = new StringBuffer();
while (rs.next()) {
//System.out.println(rs.getString("uuid")+"\t");//vm-id
//System.out.println(rs.getString("display_name")+"\t");//vm-name
String network_info = rs.getString("network_info");
//System.out.println(rs.getString("network_info"));
JSONArray ja = new JSONArray().fromObject(network_info);
for(int i=0;i<ja.size();i++){
JSONObject jo= (JSONObject) ja.get(i);
//System.out.println(jo.get("id"));//port-id ★★★★★
JSONObject network= (JSONObject) jo.get("network");
//System.out.println("---------");
//System.out.println(((JSONObject)((JSONArray)((JSONObject)((JSONArray)(network.get("subnets"))).get(0)).get("ips")).get(0)).get("address"));
//System.out.println(((JSONObject)(((JSONObject)((JSONArray)(network.get("subnets"))).get(0)).get("meta"))).get("dhcp_server"));
String dhcp_server = (String) ((JSONObject)(((JSONObject)((JSONArray)(network.get("subnets"))).get(0)).get("meta"))).get("dhcp_server");
String vm_address = (String) ((JSONObject)((JSONArray)((JSONObject)((JSONArray)(network.get("subnets"))).get(0)).get("ips")).get(0)).get("address");
//System.out.println(network.get("id"));//network-id
//System.out.println(network.get("label"));//network-name
//System.out.println(network);
JSONObject one_connection=new JSONObject();
one_connection.put("src", new JSONObject().fromObject("{\"process\":\"switch/"+network.get("id")+"\",\"port\":\""+dhcp_server+"\"}"));//有port
one_connection.put("tgt", new JSONObject().fromObject("{\"process\":\"vm/"+rs.getString("uuid")+"\",\"port\":\""+vm_address+"\"}"));
// System.out.println(one_connection);
list_i_net.add(one_connection);
}
//System.out.println();
}

} else {
int i = ps.getUpdateCount();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
rs.close();
con.close();
} catch (Exception e2) {}
}
return list_i_net;
}
public List<JSONObject> get_router_net() {//获取router和网络的关系
List list_router_net=new ArrayList();
ResultSet rs = null;
Connection con = null;
try {
con = getConnection("neutron");
PreparedStatement ps = null;
String sql = "select * from routerports rp ,ports p,ipallocations i where rp.port_id=p.id and i.port_id=p.id";
ps = (PreparedStatement) con.prepareStatement(sql);
if (ps.execute()) {
rs = ps.getResultSet();
StringBuffer b = new StringBuffer();
while (rs.next()) {
JSONObject one_connection=new JSONObject();
String ip_address = rs.getString("ip_address");
if("network:router_interface".equals(rs.getString("port_type"))){
one_connection.put("src", new JSONObject().fromObject("{\"process\":\"router/"+rs.getString("router_id")+"\",\"port\":\""+ip_address+"\"}"));
one_connection.put("tgt", new JSONObject().fromObject("{\"process\":\"switch/"+rs.getString("network_id")+"\",\"port\":\""+"in"+"\"}"));

}else{//network:router_gateway
//one_connection.put("src", new JSONObject().fromObject("{\"process\":\"router/"+rs.getString("router_id")+"\",\"port\":\""+jo.get("port_id")+"\"}"));
one_connection.put("src", new JSONObject().fromObject("{\"process\":\"switch/"+rs.getString("network_id")+"\",\"port\":\""+"out"+"\"}"));
one_connection.put("tgt", new JSONObject().fromObject("{\"process\":\"router/"+rs.getString("router_id")+"\",\"port\":\""+ip_address+"\"}"));
}
//System.out.println(one_connection);
list_router_net.add(one_connection);

//System.out.println();
}

} else {
int i = ps.getUpdateCount();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
rs.close();
con.close();
} catch (Exception e2) {}
}
return list_router_net;
}
public Map<String,JSONObject> getRouters() {
Map<String,JSONObject> routers=new HashMap<String,JSONObject>();
Connection con = null;
ResultSet rs = null;
try {
con = getConnection("neutron");
PreparedStatement ps = null;
String sql = "select * from routers";
ps = (PreparedStatement) con.prepareStatement(sql);
if (ps.execute()) {
rs = ps.getResultSet();
StringBuffer b = new StringBuffer();
while (rs.next()) {
JSONObject instance=new JSONObject();
JSONObject metadata=new JSONObject();
instance.put("component", "router/"+rs.getString("id"));
metadata.put("type", "router");
metadata.put("router_id", rs.getString("id"));
metadata.put("router_status", rs.getString("status"));
metadata.put("label", rs.getString("name"));
instance.put("metadata", metadata);
//System.out.println(instance);
routers.put("router/"+rs.getString("id"), instance);
}
} else {
int i = ps.getUpdateCount();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
rs.close();
con.close();
} catch (Exception e2) {}
}
return routers;
}
public Map getNetworkExternal() {//获取网络是外部网络的集合
Map external_map = new HashMap();
Connection con = null;
ResultSet rs = null;
try {
con = getConnection("neutron");
PreparedStatement ps = null;
String sql = "select * from networkrbacs where action='access_as_external'";//where tenant_id= scsssdfs;
ps = (PreparedStatement) con.prepareStatement(sql);
if (ps.execute()) {
rs = ps.getResultSet();
StringBuffer b = new StringBuffer();
while (rs.next()) {
external_map.put(rs.getString("object_id"),"access_as_external");
}
} else {
int i = ps.getUpdateCount();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
rs.close();
con.close();
} catch (Exception e2) {}
}
//System.out.println(external_map.size());
return external_map;
}
public Map getNetworkShared() {//获取网络是共享网络的集合
Map shared_map = new HashMap();
Connection con = null;
ResultSet rs = null;
try {
con = getConnection("neutron");
PreparedStatement ps = null;
String sql = "select * from networkrbacs where action='access_as_shared'";//where tenant_id= scsssdfs;
ps = (PreparedStatement) con.prepareStatement(sql);
if (ps.execute()) {
rs = ps.getResultSet();
StringBuffer b = new StringBuffer();
while (rs.next()) {
shared_map.put(rs.getString("object_id"), "access_as_shared");
}
} else {
int i = ps.getUpdateCount();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
rs.close();
con.close();
} catch (Exception e2) {}
}
//System.out.println(shared_map.size());
return shared_map;
}
public Map getSwitchs() {
Map<String,JSONObject> switchs=new HashMap<String,JSONObject>();
Connection con = null;
ResultSet rs = null;
Map shared_map = getNetworkShared();
Map external_map = getNetworkExternal();
try {
con = getConnection("neutron");
PreparedStatement ps = null;
String sql = "select * from networks";//where tenant_id= scsssdfs;
ps = (PreparedStatement) con.prepareStatement(sql);
if (ps.execute()) {
rs = ps.getResultSet();
StringBuffer b = new StringBuffer();
while (rs.next()) {
JSONObject instance=new JSONObject();
JSONObject metadata=new JSONObject();
instance.put("component", "switch/"+rs.getString("id"));
metadata.put("type", "switch");
metadata.put("switch_id", rs.getString("id"));
metadata.put("switch_status", rs.getString("status"));
metadata.put("label", rs.getString("name"));
if(shared_map.get(rs.getString("id"))!=null){
metadata.put("shared", "true");
}
if(external_map.get(rs.getString("id"))!=null){
metadata.put("router_external", "true");
}
instance.put("metadata", metadata);
//System.out.println(instance);
switchs.put("switch/"+rs.getString("id"), instance);
}
} else {
int i = ps.getUpdateCount();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
rs.close();
con.close();
} catch (Exception e2) {}
}
return switchs;
}
public JSONObject getTopo(){
JSONObject topojson = new JSONObject();
JSONObject processes = new JSONObject();
Map ins =getInstances();
Iterator<Map.Entry<String, JSONObject>> it = ins.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, JSONObject> entry = it.next();
processes.put(entry.getKey(), entry.getValue());
}
Map routers= getRouters();
Iterator<Map.Entry<String, JSONObject>> router = routers.entrySet().iterator();
while (router.hasNext()) {
Map.Entry<String, JSONObject> entry = router.next();
processes.put(entry.getKey(), entry.getValue());
}
Map switchs= getSwitchs();
Iterator<Map.Entry<String, JSONObject>> switcher = switchs.entrySet().iterator();
while (switcher.hasNext()) {
Map.Entry<String, JSONObject> entry = switcher.next();
processes.put(entry.getKey(), entry.getValue());
}
topojson.put("processes", processes);

List<JSONObject> lin = get_instance_net();
List<JSONObject> lrn = get_router_net();
for(int i=0;i<lin.size();i++){
lrn.add(lin.get(i));
}
topojson.put("connections", lrn);
System.out.println(topojson);
return topojson;
}
public static void main(String[] args) {
JSONObject jo = new JSONObject();
//get_instance_net();
//getInstances();
//getRouters();
//getSwitchs();
//get_router_net();
Topo topo=new Topo();
topo.getTopo();
}


}

### OpenStack 架构及其设计组成 OpenStack 是一个开源的云计算平台,提供了基础设施即服务(IaaS)解决方案[^3]。它的架构由多个独立的服务组成,这些服务通过统一的身份认证服务(Keystone)进行身份验证,并通过公共 API 进行交互[^2]。 #### 1. **OpenStack 的主要组成部分** 以下是构成 OpenStack 架构的主要服务: - **Nova**: 负责计算实例的管理,支持虚拟机和其他容器化技术。 - **Neutron**: 提供网络连接服务,允许用户定义复杂的网络拓扑。 - **Cinder**: 提供块存储服务,用于持久化的数据存储需求。 - **Swift**: 对象存储服务,适合大规模的数据存取场景。 - **Glance**: 像服务,负责管理和分发虚拟机镜像。 - **Keystone**: 统一的身份认证服务,为其他服务提供访问控制。 - **Horizon**: Web 界面仪表盘,方便用户和管理员操作 OpenStack 服务。 - **Heat**: 编排服务,帮助自动化复杂的应用程序部署过程。 每项服务都有自己的应用程序编程接口(API),这使得它们可以轻松集成到更大的生态系统中[^3]。 #### 2. **OpenStack 架构概述** 根据引用中的描述,OpenStack 的整体架构可以通过一张概览来表示,这张展示了各个组件之间的交互关系[^2]。通常情况下,该表会显示以下内容: - 各种服务如何通过 Keystone 进行身份验证; - 不同服务之间如何通过 RESTful API 或消息队列通信; - 用户如何通过 Horizon Dashboard 访问并管理资源。 虽然无法在此处直接展示片,但可以从官方文档获取最新的架构: [OpenStack Architecture Diagram](https://docs.openstack.org/arch-design/) #### 3. **OpenStack 部署参考** OpenStack Compute 使用了一种无共享、基于消息的架构,具有高度灵活性。可以根据实际需求将不同的 Nova 服务分布在多台服务器上运行[^4]。例如: - 将 `nova-api` 和 `horizon` 安装在同一台机器上作为前端入口; - 把计算节点分离出来专门处理虚拟机负载; - 利用专用的消息中间件(如 RabbitMQ)协调不同模块间的工作流。 对于生产环境下的高可用性和性能优化,则需考虑更多因素,比如数据库复制策略、存储冗余机制以及网络隔离方案等。 ```bash # 示例命令:查看当前环境中已启用的服务列表 openstack service list ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值