Openstack Nova 二次开发之Nova-extend服务实现
主要是讲如何启动openstack nova-extend services,该服务用于Openstack 二次扩展及部分需求开发,例如 ,节点巡检,动态迁移(基于FUSE 文件系统实现,分布式系统,如MooseFS),文件注入,Nova 服务的自身修复,instances IO 控制,instances CPU 隔离技术实现等其他需求开发 第一章:如何create openstack nova-extend service a) 创建python-extend 文件 cp -fr /usr/bin/python /usr/bin/python-extend 用于启动openstack nova-extend 服务,Python 服务启动nova-extend ,socket 模块不能正常果子,具体原因在于协程分装,无法使用socket,threading等模块属性 b)创建启动程序python-extend 文件,保留在/usr/bin/ 1 2 3 4 5 6 7 #!/usr/bin/python-extend #PBRGeneratedfrom'console_scripts' import sys from nova.cmd.extend import main if __name__ = = "__main__" : sys.exit(main()) c)创建from nova.cmd.extend import main程序,调用nova.services.py 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 #vim:tabstop=4shiftwidth=4softtabstop=4 #Copyright2012IBMCorp. # #LicensedundertheApacheLicense,Version2.0(the"License");youmay #notusethisfileexceptincompliancewiththeLicense.Youmayobtain #acopyoftheLicenseat # #http://www.apache.org/licenses/LICENSE-2.0 # #Unlessrequiredbyapplicablelaworagreedtoinwriting,software #distributedundertheLicenseisdistributedonan"ASIS"BASIS,WITHOUT #WARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.Seethe #Licenseforthespecificlanguagegoverningpermissionsandlimitations #undertheLicense. """StarterscriptforNovaExtend.""" import sys from oslo.config import cfg from nova import config from nova import objects from nova.openstack.common import logaslogging from nova import service from nova import utils CONF = cfg.CONF CONF.import_opt( 'topic' , 'nova.extend.api' ,group = 'extend' ) def main(): objects.register_all() config.parse_args(sys.argv) logging.setup( "nova" ) utils.monkey_patch() server = service.Service.create(binary = 'nova-extend' , topic = CONF.extend.topic, manager = CONF.extend.manager) service.serve(server,workers = CONF.extend.workers) service.wait() d) /etc/nova.conf 配置 1 extend_manager = nova.extend.manager.ExtendManager e) 创建openstack-nova-extend 启动服务脚步 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 #!/bin/sh # #openstack-nova-extendOpenStackNovaComputeDBAccessservice # #chkconfig:-9802 #description:ImplementationofanS3-likestorageserverbasedonlocalfiles. ###BEGININITINFO #Provides: #Required-Start:$remote_fs$network$syslog #Required-Stop:$remote_fs$syslog #Default-Stop:016 #Short-Description:OpenStackNovaComputeDBAccessservice #Description:Servicetohandledatabaseaccessforcomputenodes ###ENDINITINFO . /etc/rc .d /init .d /functions suffix=extend prog=openstack-nova-$suffix exec = "/usr/bin/nova-$suffix" config= "/etc/nova/nova.conf" pidfile= "/var/run/nova/nova-$suffix.pid" logfile= "/var/log/nova/$suffix.log" [-e /etc/sysconfig/ $prog]&&. /etc/sysconfig/ $prog lockfile= /var/lock/subsys/ $prog start(){ [-x$ exec ]|| exit 5 [-f$config]|| exit 6 echo -n$ "Starting$prog:" daemon--usernova--pidfile$pidfile "$exec--logfile$logfile&>/dev/null&echo\$!>$pidfile" retval=$? echo [$retval- eq 0]&& touch $lockfile return $retval } stop(){ echo -n$ "Stopping$prog:" killproc-p$pidfile$prog retval=$? echo [$retval- eq 0]&& rm -f$lockfile return $retval } restart(){ stop start } reload(){ restart } force_reload(){ restart } rh_status(){ status-p$pidfile$prog } rh_status_q(){ rh_status> /dev/null 2>&1 } case "$1" in start) rh_status_q&& exit 0 $1 ;; stop) rh_status_q|| exit 0 $1 ;; restart) $1 ;; reload) rh_status_q|| exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q|| exit 0 restart ;; *) echo $ "Usage:$0{start|stop|status|restart|condrestart|try-restart|reload|force-reload}" exit 2 esac exit $? f) 启动openstack-nova-extend服务 1 2 3 4 5 6 7 8 9 [root@athControllercmd] #serviceopenstack-nova-extendrestart [root@athControllercmd] #tar-xzf/var/log/nova/extend.log 2014 - 08 - 04 23 : 18 : 58.325 47419 INFOnova.openstack.common.service[ - ]CaughtSIGTERM,exiting 2014 - 08 - 04 23 : 19 : 00.151 45666 INFOnova.openstack.common.periodic_task[ - ]Skippingperiodictask_periodic_update_dnsbecauseitsinterval is negative 2014 - 08 - 04 23 : 19 : 00.183 45666 AUDITnova.service[ - ]Startingextendnode(version 2013.2 . 1 - 1.el6 ) 2014 - 08 - 04 23 : 19 : 00.513 45666 INFOnova.openstack.common.rpc.common[req - d6b00731 - baaa - 47fa - bfa2 - 75f9ec4ef568 None None ]ConnectedtoAMQPserveron 192.168 . 8.180 : 5672 g) openstack-nova-extend 消息队列信息 1 2 3 4 5 6 7 8 9 [root@athControllercmd] #rabbitmqctllist_queues|grepextend extend 0 extend.athCloud. 8.180 . abs .com.cn 0 extend_fanout_6dbb351ab48445cfaadc9de37e87d68f 0 extend_fanout_e870b14296354eddba09389319a9c590 0 h) nova-manager service list 查看nova-extend服务状态 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 [root@athControllercmd] #nova-manageservicelist BinaryHostZoneStatusStateUpdated_At nova - conductorathController. 8.180 . abs .com.cninternalenabled: - ) 2014 - 08 - 04 15 : 22 : 20 nova - consoleauthathController. 8.180 . abs .com.cninternalenabled: - ) 2014 - 08 - 04 15 : 22 : 19 nova - certathController. 8.180 . abs .com.cninternalenabled: - ) 2014 - 08 - 04 15 : 22 : 20 nova - schedulerathController. 8.180 . abs .com.cninternalenabled: - ) 2014 - 08 - 04 15 : 22 : 18 nova - networkathController. 8.180 . abs .com.cninternalenabled: - ) 2014 - 08 - 04 15 : 22 : 11 nova - computeathController. 8.180 . abs .com.cnnovaenabled: - ) 2014 - 08 - 04 15 : 22 : 10 nova - consoleathController. 8.180 . abs .com.cninternalenabled: - ) 2014 - 08 - 04 15 : 22 : 17 nova - extendathController. 8.180 . abs .com.cninternalenabled: - ) 2014 - 08 - 04 15 : 22 : 10 i) 总结 openstack开发其实并不是很难,只要了解nova-compute,nova-api启动过程,参照文档基本都能实现 到此openstack Nova extend 服务启动实现完毕,下一章节将会在下周一撰写openstack nova-extend nova.extend.manager 功能实现,谢谢大家,如有不明白的地方请留言,我会在中午时间一一帮助大家解答,欢迎点评 写的不好的地方还希望大牛们指点,共同学习 本文转自 swq499809608 51CTO博客,原文链接:http://blog.51cto.com/swq499809608/1535750