openstack e版怎么创建instance
这期内容当中小编将会给大家带来有关 openstack e版怎么创建instance,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
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)
上述就是小编为大家分享的 openstack e版怎么创建instance了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。