openstack e版创建instance整个流程

感谢朋友支持本博客,欢迎共同探讨交流,由于能力和时间有限,错误之处在所难免,欢迎指正!

如有转载,请保留源作者博客信息。

Better Me的博客blog.csdn.net/tantexian

如需交流,欢迎大家博客留言。

1、horizon模块:
里面的tables.py的lanch通过url映射到forms.py里面LaunchForm、然后页面传参数进去。然后调用api模块里面nova.py的server_create、
2、python-novaclient
再调用python-novaclient模块V1.1/servers.py的ServerManager类里面的create()、在调用base.py里面的_boot()封装url请求。
3、nova模块:
wsgi对于的发布模块在nova/api/openstack/compute/__init__.py文件里面。发布之后就url地址对应应关系如下:
self._list()对应底层的index()函数     
self._create()对应底层的create()函数
self._delete()对应底层的delete()函数
self._get()对应底层的show()函数
create的url对应nova/api/openstack/compute/servers.py里面的create()
在此函数里面获取image、network、flavor等参数、然后调用self.compute_api.create然后调用self._schedule_run_instance、消息队列发送rpc_method的run_instance方法、根据FLAGS.scheduler_topic配置调用scheduler模块中manager.py的run_instance。配置文件scheduler_driver = FLAGS.scheduler_driver,此处生产环境中用的是--scheduler_driver=nova.scheduler.simple.SimpleScheduler,所以:simple.py里面的schedule_run_instance方法。
driver.cast_to_compute_host将消息发到消息队列中。
compute/manage.py的run_instance方法、_run_instance、_spawn然后配置文件compute_driver = FLAGS.compute_driver的default='nova.virt.connection.get_connection',
get_connection里面 t == 'libvirt':  conn = libvirt_conn.get_connection(read_only) 接着from nova.virt.libvirt import connection as libvirt_conn
因此调用libvirt里面的spawn函数、然后生成xml文件。





1、horizon模块调用流程




2、novaclient模块调用流程
注:        resp, body = self.api.client.post(url, body=body)这句话就是发送post请求,到nova,nova里面的wsgi能够根据这个url自动匹配执行相应函数











3、nova模块调用流程
注:nova的wsgi的发布都在/nova/api/openstack/compute文件夹下面。
上面没有传递available_zone参数????


下面语句则表示调用scheduler
此处生产环境中用的是--scheduler_driver=nova.scheduler.simple.SimpleScheduler,所以:


一下为simple调度算法:
    def _schedule_instance(self, context, instance_opts, *_args, **_kwargs):
        """Picks a host that is up and has the fewest running instances."""
        elevated = context.elevated()

        availability_zone = instance_opts.get('availability_zone')
        
        zone, host = FLAGS.default_schedule_zone, None
        if availability_zone:
            zone, _x, host = availability_zone.partition(':')

        if host and context.is_admin:
            service = db.service_get_by_args(elevated, host, 'nova-compute')
            if not utils.service_is_up(service):
                raise exception.WillNotSchedule(host=host)
            return host

        results = db.service_get_all_compute_sorted(elevated)//获取最少的资源利用率的host
        in_isolation = instance_opts['image_ref'] in FLAGS.isolated_images
        check_cores = not in_isolation or not FLAGS.skip_isolated_core_check
        if zone:
            results = [(service, cores) for (service, cores) in results
                       if service['availability_zone'] == zone] //此处的availability_zone为页面传递过来
        
        requested_networks =  _kwargs['requested_networks']
        if requested_networks:
            results = [(service, cores) for (service, cores) in results
                       if service['network_ref'] in [network_uuid for (network_uuid, fixed_ip) in requested_networks]] //此处的 requested_networks 为页面传递过来

        for result in results:
            (service, instance_cores) = result
            if in_isolation and service['host'] not in FLAGS.isolated_hosts:
                # isloated images run on isolated hosts
                continue
            if service['host'] in FLAGS.isolated_hosts and not in_isolation:
                # images that aren't isolated only run on general hosts
                continue
            if (check_cores and
                instance_cores + instance_opts['vcpus'] > FLAGS.max_cores):
                msg = _("Not enough allocatable CPU cores remaining")
                raise exception.NoValidHost(reason=msg)
            if not self._isenough_subnet(elevated, service):
                continue            
            if utils.service_is_up(service) and not service['disabled']:
                return service['host']
        
        msg = _("Is the appropriate service running?")
        raise exception.NoValidHost(reason=msg)







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值