From the name of the folder also basically can draw the role of the directory code, a few important folders are as follows:
Agent: mainly L3 agent and L3 agent ha related code;
Common: It is mainly the interaction layer between the bottom drive and the Linux system command;
DB: is neutron each function and the database interaction data code;
Extensions: mainly includes some extended functions, including DVR code, etc.;
Plugins: is the core plugin code, including OVS,ML2 and each vendor IBM, Ryu provide plugin;
Scheduler: is to create the DHCP service and router to each L3 agent dispatching allocation related code;
Server: is the neutron server related code;
Services : is the metering and agent code that contains Lbaas, Vpnaas, Fwaas, l3-router, plugin, etc.
Neutron is a project in OpenStack for managing your network. The neutron code of the Portal configuration file neutron.setup.cfg, we can use this file to understand the entire project code structure.
Neutron/setup.cfg
[Entry_points]
console_scripts =
neutron-l3-agent = neutron.cmd.eventlet.agents.l3:main
neutron-linuxbridge-agent = Neutron.plugins.ml2.drivers.linuxbridge.agent.linuxbridge_neutron_agent:main
neutron-openvswitch-agent = Neutron.cmd.eventlet.plugins.ovs_neutron_agent:main
neutron-server = neutron.cmd.eventlet.server:main_wsgi_ Eventlet
neutron-rpc-server = neutron.cmd.eventlet.server:main_rpc_eventlet
Neutron-sanity-check = Neutron.cmd.sanity_check:main
neutron.core_plugins =
ML2 = Neutron.plugins.ml2.plugin:Ml2Plugin
neutron-l3-agent: The L3 agent is deployed on a compute node or network node and is responsible for the management of the 3-tier virtual network. According to the setup.cfg file, you can see that the Neutron-l3-agent code path is neutron/agent/l3/agent
neutron-openvswitch-agent: The Open vSwitch agent is deployed on compute nodes or network nodes to manage OvS virtual switches. According to the setup.cfg file, you can see that the Neutron-openvswitch-agent code path is neutron/plugins/openvswitch/agent.ovs_neutron_agent
Neutron-server: Is the only service process in neutron that takes care of the user's RESTful API requests and distributes them to various agen to accomplish these tasks. According to the setup.cfg file, you can see that the neutron code path is Neutron/server
Ml2plugin: Used to provide a two-tier virtual network that implements the operation of the Network/subnet/port resource, which is ultimately done by plugin calling the Openvswitch agent through RPC. According to the setup.cfg file, you can see that the code path is neutron/plugins/ml2/plugin/ml2plugin.
neutron-server Start-up process Analysis
Neutron-server start, no outside is load configuration, router various resource, and then wait for the request. which router which resource is entirely determined by the configuration file. Of course, the DB will also be initialized during startup, which is why it is not necessary to perform DB sync like nova,glance when installing neutron. Neutron-server Initialization
1./etc/init.d/neutron-server
The script: Create a new log directory, service directory, and start the Neutron-server daemon. Supports curd operations.
DAEMON=/usr/bin/neutron-server
DAEMON_ARGS="--log-file=$LOGFILE"
DAEMON_DIR=/var/run
if [ ! -x ${DAEMON} ] ; then
exit 0
fi
case "$1" in
start)
test "$ENABLED" = "true" || exit 0
log_daemon_msg "Starting neutron server" "neutron-server"
start-stop-daemon -Sbmv --pidfile $PIDFILE --chdir $DAEMON_DIR --exec $DAEMON -- $DAEMON_ARGS
log_end_msg $?
;;
stop)
test "$ENABLED" = "true" || exit 0
log_daemon_msg "Stopping neutron server" "neutron-server"
start-stop-daemon --stop --oknodo --pidfile ${PIDFILE}
log_end_msg $?
;;
restart|force-reload)
test "$ENABLED" = "true" || exit 1
$0 stop
sleep 1
$0 start
;;
status)
test "$ENABLED" = "true" || exit 0
status_of_proc -p $PIDFILE $DAEMON neutron-server && exit 0 || exit $?
;;
*)
log_action_msg "Usage: /etc/init.d/neutron-server {start|stop|restart|force-reload|status}"
exit 1
;;
esac
exit 0
2. neutron/server/main Main function
The core of the main method is the Serve_wsgi, Serve_rpc two method calls, creating the API service and the RPC service, respectively. The new version makes a highly abstract and loosely-coupled approach to the main method.
1) neutron.server. wsgi_eventlet.py
def _eventlet_wsgi_server():
pool = eventlet.GreenPool()
# 启动Restful API 以协程方式
neutron_api = service.serve_wsgi(service.NeutronApiService)
api_thread = pool.spawn(neutron_api.wait)
try:
# 启动RPC API
neutron_rpc = service.serve_rpc()
except NotImplementedError:
LOG.info(_LI("RPC was already started in parent process by "
"plugin."))
else:
rpc_thread = pool.spawn(neutron_rpc.wait)
plugin_workers = service.start_plugin_workers()
for worker in plugin_workers:
pool.spawn(worker.wait)
# api and rpc should die together. When one dies, kill the other.
rpc_thread.link(lambda gt: api_thread.kill())
api_thread.link(lambda gt: rpc_thread.kill())
pool.waitall()
def main():
server.boot_server(_eventlet_wsgi_server)
Neutron.server. rpc_eventlet.py
Def _eventlet_rpc_server ():
pool = Eventlet. Greenpool ()
Log.info (_li ("Eventlet based AMQP RPC server starting ..."))
try:
# start RPC API
neutron_rpc = SERVICE.SERVE_RPC ()
except Notimplementederror:
log.info (_li ("RPC is already started in the parent process by"
"plugin."))
else:
pool.spawn (neutron_rpc.wait)
Pool.waitall ()
def main ():
server.boot_server (_eventlet_ Rpc_server)
2) Neutron.server. _ init _.py
def boot_server (Server_func): # The configuration would be a read into the
cfg. CONF Global Data Structure
config.init (sys.argv[1:])
config.setup_logging ()
if not cfg. Conf.config_file:
Sys.exit (_ ("error:unable to find configuration file via the default"
"Search paths (~/.neutro n/, ~/,/etc/neutron/,/etc/) and "
the '--config-file ' option!"))
Try:
server_func ()
except keyboardinterrupt:
pass
except RuntimeError as E:
Sys.exit (_ (" ERROR:%s ")% E)
Where: The WSGI service and the RPC service boot process are as follows: API Service Initialization
SERVE_WSGI Service:
http://blog.csdn.net/qiqishuang/article/details/52056491 RPC Service initialization
SERVE_RPC Service:
http://blog.csdn.net/qiqishuang/article/details/52056511 l2-agent Service initialization
http://blog.csdn.net/qiqishuang/article/details/52056557 l3-agent Service initialization
http://blog.csdn.net/qiqishuang/article/details/52153034
Reference:
About Cloud: http://www.aboutyun.com/thread-10306-1-1.html