OpenStack의 Neutron 소스 분석 Neutron-server 초기화
10892 단어 OpenStack
Neutron은 OpenStack에서 네트워크 관리를 위한 프로젝트입니다.neutron 코드의 입구 설정 파일neutron.setup.cfg, 우리는 이 파일을 통해 전체 프로젝트의 코드 구조를 이해할 수 있습니다.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-server 시작 과정 분석
Neutron-server가 시작되면, 설정을 불러오고, router는 여러 가지 Resource를 불러오고, 요청을 기다립니다.그중에서router의 어떤 Resource는 완전히 설정 파일에 의해 결정됩니다.물론 시작하는 과정에서db를 초기화할 수 있다. 이것이 바로 뉴트론을 설치할 때nova,glance 등이dbsync를 실행할 필요가 없는 이유다.
neutron-server 초기화
1./etc/init.d/neutron-server 이 스크립트: 새 로그 디렉터리, 서비스 디렉터리,neutron-server 수호 프로세스를 시작합니다.CURD 작업이 지원됩니다.
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 방법의 핵심은 서버wsgi、serve_rpc 두 가지 방법으로 호출하여 각각api 서비스와 rpc 서비스를 만듭니다.새 버전은main 방법에 대해 고도의 추상과 느슨한 결합 처리를 했다.
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:
# RPC API
neutron_rpc = service.serve_rpc()
except NotImplementedError:
LOG.info(_LI("RPC was already started in 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 will be 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 (~/.neutron/, ~/, /etc/neutron/, /etc/) and"
" the '--config-file' option!"))
try:
server_func()
except KeyboardInterrupt:
pass
except RuntimeError as e:
sys.exit(_("ERROR: %s") % e)
그 중에서 wsgi 서비스와 rpc 서비스의 시작 과정은 다음과 같다.
Api 서비스 초기화
serve_wsgi 서비스:http://blog.csdn.net/qiqishuang/article/details/52056491
Rpc 서비스 초기화
serve_rpc 서비스:http://blog.csdn.net/qiqishuang/article/details/52056511
L2-Agent 서비스 초기화
http://blog.csdn.net/qiqishuang/article/details/52056557
L3-Agent 서비스 초기화
http://blog.csdn.net/qiqishuang/article/details/52153034
참조: About 클라우드:http://www.aboutyun.com/thread-10306-1-1.html
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
OpenStack의 Neutron 소스 분석 Neutron-server 초기화Neutron은 OpenStack에서 네트워크 관리를 위한 프로젝트입니다.neutron 코드의 입구 설정 파일neutron.setup.cfg, 우리는 이 파일을 통해 전체 프로젝트의 코드 구조를 이해할 수 있습니다....
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.