OpenStack의 Neutron 소스 분석 Neutron-server 초기화

10892 단어 OpenStack
폴더의 이름도 기본적으로 이 디렉터리 코드의 역할을 알 수 있다. 몇 가지 중요한 폴더는 다음과 같다. 에이전트: 주로 l3에이전트와 l3에이전트하의 관련 코드이다.common: 주로 각 하위 드라이브와 linux 시스템 명령의 상호작용층;db:neutron의 각 기능과 데이터베이스 상호작용 데이터의 코드입니다.extensions: dvr 코드 등을 포함한 확장 기능;plugins:coreplugin의 코드로 ovs, ml2와 각 제조업체 ibm, ryu가 제공하는 등의plugin을 포함한다.scheduler:dhcp 서비스와router를 각 l3에이전트에 대한 스케줄링 분배 코드를 만듭니다.서버:neutron 서버와 관련된 코드입니다.서비스s:lbaas,aas,fwaas,l3-router,metering 등 서비스의plugin과 에이전트 코드를 포함한다.
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-l3-agent:l3에이전트는 계산 노드나 네트워크 노드에 배치하여 3층 가상 네트워크의 관리를 책임진다.setup을 기준으로 합니다.cfg 파일에서 알 수 있듯이neutron-l3-에이전트의 코드 경로는neutron/agent/l3/에이전트
  • 이다.
  • neutron-openvs witch-agent: Open vSwitch Agent는 계산 노드나 네트워크 노드에 배치하여 OVS 가상 교환기를 관리한다.setup을 기준으로 합니다.cfg 파일에서 알 수 있듯이neutron-openvs witch-agent의 코드 경로는neutron/plugins/openvs witch/agent이다.ovs_neutron_agent
  • neutron-server: Neutron에서 유일한 서비스 프로세스로 사용자의 RESTful API 요청을 받고 각종agen에 나누어 처리하여 이 작업을 완성합니다.setup을 기준으로 합니다.cfg 파일에서 알 수 있듯이neutron 코드 경로는neutron/server
  • 입니다.
  • ML2Plugin: 2층 가상 네트워크를 제공하는 데 사용되며network/subnet/port 자원을 실현하는 작업입니다. 이 작업은 최종적으로 Plugin이 RPC를 통해 OpenvSwitch 에이전트를 호출하여 완성합니다.setup을 기준으로 합니다.cfg 파일에서 알 수 있듯이 코드 경로는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

    좋은 웹페이지 즐겨찾기