首页 > 网络 > 云计算 >

世界杯外围投注官网

2016-10-15

最近工作的主要内容是在dashboard中启动虚拟机的时候加一个cache静态划分的功能,是在隔离区还是在共享区,这就需要对整个虚拟机的启动流程世界杯外围投注网站非常熟悉,并且还要适当的改前端。Mitaka版Openstack虚拟机启动流程。

最近工作的主要内容是在dashboard中启动虚拟机的时候加一个cache静态划分的功能,是在隔离区还是在共享区,这就需要对整个虚拟机的启动流程世界杯外围投注网站非常熟悉,并且还要适当的改前端。但是在看源码包括实践的过程发现了一件很神奇的时候,网上的教程大多是IceHose版本的,其启动虚拟机走的是正常的workflow中的handle函数,但是也不知道是我们装的Mitaka版本OpenStack有问题还是怎么样,起虚拟机偏偏不走那里,第一天遇到这个问题的时候我就给hcch师兄说我见鬼了。。 但好在,用了三天时间调出来了,同时也记录一下Mitaka版本的虚拟机启动的流程。

1. Dashboard中


1. /usr/share/openstack-dashboard/openstack_dashboard/dashboards/project/instances/workflows/create_instance.py

是关于创建虚拟机的workflow,但是不走LaunchInstance中的handle进行处理

class LaunchInstance(workflows.Workflow):
    slug = "launch_instance"
    name = _("Launch Instance")
    finalize_button_name = _("Launch")
    success_message = _(&世界杯外围投注官网39;Launched %(count)s named "%(name)s".&世界杯外围投注官网39;)
    failure_message = _(&世界杯外围投注官网39;Unable to launch %(count)s named "%(name)s".&世界杯外围投注官网39;)
    success_url = "horizon:project:instances:index"
    multipart = True
    default_steps = (SelectProjectUser,    
                     SetInstanceDetails,
                     SetAccessControls,
                     SetNetwork,
                     SetNetworkPorts,
                     PostCreationStep,
                     SetAdvanced)

这里面定义了7个Steps,每个Steps中都有对应的表单显示。其中每个标签卡显示的具体内容和相应的html和js相对应。

具体的js和html的文件放在以下目录

/usr/share/openstack-dashboard/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance

2. /usr/share/openstack-dashboard/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-model.service.js

当在dashboard中把创建虚拟机的表单填写好后,所有的数据都通过这个js文件中的 createInstance() 函数进行请求的进一步发送

function createInstance() {
      var finalSpec = angular.copy(model.newInstanceSpec);
      cleanNullProperties(finalSpec);
      setFinalSpecBootsource(finalSpec);
      setFinalSpecFlavor(finalSpec);
      setFinalSpecNetworks(finalSpec);
      setFinalSpecPorts(finalSpec);
      setFinalSpecKeyPairs(finalSpec);
      setFinalSpecSecurityGroups(finalSpec);
      setFinalSpecMetadata(finalSpec);
      return novaAPI.createServer(finalSpec).then(successMessage);     
    }

3. /usr/share/openstack-dashboard/openstack_dashboard/static/app/core/openstack-service-api/nova.service.js

第二步中的请求发送到这个js文件中的 createServer(newServer) 函数中,其中newServer参数中放了创建虚拟机的参数

    function createServer(newServer) {
      return apiService.post(&世界杯外围投注官网39;/api/nova/servers/&世界杯外围投注官网39;, newServer)    世界杯外围投注官网 向api/rest/nova.py 发请求
        .error(function () {
          toastService.add(&世界杯外围投注官网39;error&世界杯外围投注官网39;, gettext(&世界杯外围投注官网39;Unable to create the server.&世界杯外围投注官网39;));
        });
    }

4. /usr/share/openstack-dashboard/openstack_dashboard/api/rest/nova.py

请求发送到了 Servers 类下的 Post 函数中,其中所有的参数在request中

@rest_utils.ajax(data_required=True)
    def post(self, request):
        try:
            args = (
                request,
                request.DATA[&世界杯外围投注官网39;name&世界杯外围投注官网39;],
                request.DATA[&世界杯外围投注官网39;source_id&世界杯外围投注官网39;],
                request.DATA[&世界杯外围投注官网39;flavor_id&世界杯外围投注官网39;],
                request.DATA[&世界杯外围投注官网39;key_name&世界杯外围投注官网39;],
                request.DATA[&世界杯外围投注官网39;user_data&世界杯外围投注官网39;],
                request.DATA[&世界杯外围投注官网39;security_groups&世界杯外围投注官网39;],
            )
        except KeyError as e:
            raise rest_utils.AjaxError(400, &世界杯外围投注官网39;missing required parameter &世界杯外围投注官网39;
                                            "&世界杯外围投注官网39;%s&世界杯外围投注官网39;" % e.args[0])
        kw = {}
        for name in self._optional_create:
            if name in request.DATA:
                kw[name] = request.DATA[name]
        new = api.nova.server_create(*args, **kw)
        return rest_utils.CreatedResponse(
            &世界杯外围投注官网39;/api/nova/servers/%s&世界杯外围投注官网39; % utils_http.urlquote(new.id),
            new.to_dict()
        )

5. /usr/share/openstack-dashboard/openstack_dashboard/api/nova.py

通过 server_create 函数调用novaclient

def server_create(request, name, image, flavor, key_name, user_data,
                  security_groups, block_device_mapping=None,
                  block_device_mapping_v2=None, nics=None,
                  availability_zone=None, instance_count=1, admin_pass=None,
                  disk_config=None, config_drive=None, meta=None):
    return Server(novaclient(request).servers.create(
        name, image, flavor, userdata=user_data,
        security_groups=security_groups,
        key_name=key_name, block_device_mapping=block_device_mapping,
        block_device_mapping_v2=block_device_mapping_v2,
        nics=nics, availability_zone=availability_zone,
        min_count=instance_count, admin_pass=admin_pass,
        disk_config=disk_config, config_drive=config_drive,
        meta=meta), request)

2. novaclient中


1. /usr/lib/python2.7/site-packages/novaclient/v2/servers.py

ServerManager下的create函数接受来自dashboard的请求

def create(self, name, image, flavor, meta=None, files=None,
               reservation_id=None, min_count=None,
               max_count=None, security_groups=None, userdata=None,
               key_name=None, availability_zone=None,
               block_device_mapping=None, block_device_mapping_v2=None,
               nics=None, scheduler_hints=None,
               config_drive=None, disk_config=None, admin_pass=None,
               access_ip_v4=None, access_ip_v6=None, **kwargs):
        世界杯外围投注官网 中间省略掉。。
        return self._boot(resource_url, response_key, *boot_args,
                          **boot_kwargs)

接下来在这个文件中调用 _boot 函数

    def _boot(self, resource_url, response_key, name, image, flavor,
              meta=None, files=None, userdata=None,
              reservation_id=None, return_raw=False, min_count=None,
              max_count=None, security_groups=None, key_name=None,
              availability_zone=None, block_device_mapping=None,
              block_device_mapping_v2=None, nics=None, scheduler_hints=None,
              config_drive=None, admin_pass=None, disk_config=None,
              access_ip_v4=None, access_ip_v6=None, description=None,
              **kwargs):
        """
        Create (boot) a new server.
        """
        世界杯外围投注官网 中间是各种参数初始化,略过。。
        return self._create(resource_url, body, response_key,
                            return_raw=return_raw, **kwargs)

2. /usr/lib/python2.7/site-packages/novaclient/base.py

从这以下到novaclient结束,都不会设计世界杯外围投注网站的修改,因此只写到这里,具体调用的文件会列出来,但不再贴世界杯外围投注网站了

    def _create(self, url, body, response_key, return_raw=False, **kwargs):
        self.run_hooks(&世界杯外围投注官网39;modify_body_for_create&世界杯外围投注官网39;, body, **kwargs)
        resp, body = self.api.client.post(url, body=body)     
        世界杯外围投注官网 在这里继续往下走,调用下一步的函数
        if return_raw:
            return self.convert_into_with_meta(body[response_key], resp)

3. /usr/lib/python2.7/site-packages/novaclient/client.py

好吧,本来是不想继续往下写关于novaclient的了,但是在nova那边发现我从novaclient传到nova的参数居然丢了!丢了! 肯定就是在下面我没接触到的步骤丢了,只能继续往下看世界杯外围投注网站了。

顺序是这样的 HTTPClient.post -> HTTPClient._cs_request -> HTTPClient._time_request -> HTTPClient.request

    def post(self, url, **kwargs):
        return self._cs_request(url, &世界杯外围投注官网39;POST&世界杯外围投注官网39;, **kwargs)
    def _cs_request(self, url, method, **kwargs):
        世界杯外围投注官网 前面的省略
        try:
            kwargs.setdefault(&世界杯外围投注官网39;headers&世界杯外围投注官网39;, {})[&世界杯外围投注官网39;X-Auth-Token&世界杯外围投注官网39;] = self.auth_token
            if self.projectid:
                kwargs[&世界杯外围投注官网39;headers&世界杯外围投注官网39;][&世界杯外围投注官网39;X-Auth-Project-Id&世界杯外围投注官网39;] = self.projectid
            resp, body = self._time_request(url, method, **kwargs)   世界杯外围投注官网 在这里继续发请求
            return resp, body
        except exceptions.Unauthorized as e:
            世界杯外围投注官网 略过,。。
    def _time_request(self, url, method, **kwargs):
        with utils.record_time(self.times, self.timings, method, url):
            resp, body = self.request(url, method, **kwargs)
        return resp, body

好吧,很无奈,最后发现,参数传到nova当中,其参数并不在body里,而是在req的body里面,当时怎么那么傻没打出来看看。。。

3. Nova


1. /usr/lib/python2.7/site-packages/nova/api/openstack/compute/servers.py

    def create(self, req, body):
        """Creates a new server for a given user."""
        世界杯外围投注官网其他的地方都省略
            世界杯外围投注官网创建虚拟机
            (instances, resv_id) = self.compute_api.create(context,
                            inst_type,
                            image_uuid,
                            display_name=name,
                            display_description=description,
                            availability_zone=availability_zone,
                            forced_host=host, forced_node=node,
                            metadata=server_dict.get(&世界杯外围投注官网39;metadata&世界杯外围投注官网39;, {}),
                            admin_password=password,
                            requested_networks=requested_networks,
                            check_server_group_quota=True,
                            **create_kwargs)

2. /usr/lib/python2.7/site-packages/nova/compute/api.py

    @hooks.add_hook("create_instance")
    def create(self, context, instance_type, 
               image_href, kernel_id=None, ramdisk_id=None,
               min_count=None, max_count=None,
               display_name=None, display_description=None,
               key_name=None, key_data=None, security_group=None,
               availability_zone=None, forced_host=None, forced_node=None,
               user_data=None, metadata=None, injected_files=None,
               admin_password=None, block_device_mapping=None,
               access_ip_v4=None, access_ip_v6=None, requested_networks=None,
               config_drive=None, auto_disk_config=None, scheduler_hints=None,
               legacy_bdm=True, shutdown_terminate=False,
               check_server_group_quota=False):
        世界杯外围投注官网 中间略过。。。
        世界杯外围投注官网 跳到这个文件的_create_instance函数
        return self._create_instance(
                       context, instance_type, 
                       image_href, kernel_id, ramdisk_id,
                       min_count, max_count,
                       display_name, display_description,
                       key_name, key_data, security_group,
                       availability_zone, user_data, metadata,
                       injected_files, admin_password,
                       access_ip_v4, access_ip_v6,
                       requested_networks, config_drive,
                       block_device_mapping, auto_disk_config,
                       filter_properties=filter_properties,
                       legacy_bdm=legacy_bdm,
                       shutdown_terminate=shutdown_terminate,
                       check_server_group_quota=check_server_group_quota)
    def _create_instance(self, context, instance_type, 
               image_href, kernel_id, ramdisk_id,
               min_count, max_count,
               display_name, display_description,
               key_name, key_data, security_groups,
               availability_zone, user_data, metadata, injected_files,
               admin_password, access_ip_v4, access_ip_v6,
               requested_networks, config_drive,
               block_device_mapping, auto_disk_config, filter_properties,
               reservation_id=None, legacy_bdm=True, shutdown_terminate=False,
               check_server_group_quota=False):
        """Verify all the input parameters regardless of the provisioning
        strategy being performed and schedule the instance(s) for
        creation.
        """
        世界杯外围投注官网 中间略去。。
        世界杯外围投注官网 跳转到 nova/conductor/api.py
        self.compute_task_api.build_instances(context,
                instances=instances, image=boot_meta,
                filter_properties=filter_properties,
                admin_password=admin_password,
                injected_files=injected_files,
                requested_networks=requested_networks,
                security_groups=security_groups,
                block_device_mapping=block_device_mapping,
                legacy_bdm=False)
        return (instances, reservation_id)

3. /usr/lib/python2.7/site-packages/nova/conductor/api.py

ComputeTaskAPI.build_instances

def build_instances(self, context, instances, image, filter_properties,
            admin_password, injected_files, requested_networks,
            security_groups, block_device_mapping, legacy_bdm=True):
        self.conductor_compute_rpcapi.build_instances(context,
                instances=instances, image=image,
                filter_properties=filter_properties,
                admin_password=admin_password, injected_files=injected_files,
                requested_networks=requested_networks,
                security_groups=security_groups,
                block_device_mapping=block_device_mapping,
                legacy_bdm=legacy_bdm)

4. /usr/lib/python2.7/site-packages/nova/conductor/rpcapi.py

ComputeTaskAPI.build_instances

def build_instances(self, context, instances, image, filter_properties,
            admin_password, injected_files, requested_networks,
            security_groups, block_device_mapping, legacy_bdm=True):
        世界杯外围投注官网 中间略过。。
        cctxt = self.client.prepare(version=version)
        世界杯外围投注官网 将跳转至,/usr/lib/python2.7/site-packages/oslo_messaging/rpc/client.py
        cctxt.cast(context, &世界杯外围投注官网39;build_instances&世界杯外围投注官网39;, **kw)

5. /usr/lib/python2.7/site-packages/oslo_messaging/rpc/client.py

RPCClient.cast() —> _CallContext.cast()

    def cast(self, ctxt, method, **kwargs):
        self.prepare().cast(ctxt, method, **kwargs)
    def cast(self, ctxt, method, **kwargs):
        """Invoke a method and return immediately. See RPCClient.cast()."""
        msg = self._make_message(ctxt, method, kwargs)
        ctxt = self.serializer.serialize_context(ctxt)
        if self.version_cap:
            self._check_version_cap(msg.get(&世界杯外围投注官网39;version&世界杯外围投注官网39;))
        try:
            self.transport._send(self.target, ctxt, msg, retry=self.retry)
        except driver_base.TransportDriverError as ex:
            raise ClientSendError(self.target, ex)

6. 中间各种过程不贴世界杯外围投注网站

_CallContext.cast() —> site-packages/oslo_messaging/transport.py Transport._send() —> site-packages/oslo_messaging/_drivers/impl_zmq.py ZmqDriver.send()

7. /usr/lib/python2.7/site-packages/nova/conductor/manager.py

ComputeTaskManager.build_instances

    def build_instances(self, context, instances, image, filter_properties,
            admin_password, injected_files, requested_networks,
            security_groups, block_device_mapping=None, legacy_bdm=True):
        世界杯外围投注官网 中间的省略。。
            世界杯外围投注官网 此处调用的是 nova/compute/rpcapi.py  --->  build_and_run_instance()
            self.compute_rpcapi.build_and_run_instance(context,
                    instance=instance, host=host[&世界杯外围投注官网39;host&世界杯外围投注官网39;], image=image,
                    request_spec=request_spec,
                    filter_properties=local_filter_props,
                    admin_password=admin_password,
                    injected_files=injected_files,
                    requested_networks=requested_networks,
                    security_groups=security_groups,
                    block_device_mapping=bdms, node=host[&世界杯外围投注官网39;nodename&世界杯外围投注官网39;],
                    limits=host[&世界杯外围投注官网39;limits&世界杯外围投注官网39;])

8. /usr/lib/python2.7/site-packages/nova/computer/rpcapi.py

ComputeAPI.build_and_run_instance()

    def build_and_run_instance(self, ctxt, instance, host, image, request_spec,
            filter_properties, admin_password=None, injected_files=None,
            requested_networks=None, security_groups=None,
            block_device_mapping=None, node=None, limits=None):
        version = &世界杯外围投注官网39;4.0&世界杯外围投注官网39;
        cctxt = self.client.prepare(server=host, version=version)
        世界杯外围投注官网 此处又重复了第5、6步的内容,下面这点不再重复的写。
        cctxt.cast(ctxt, &世界杯外围投注官网39;build_and_run_instance&世界杯外围投注官网39;, instance=instance,
                image=image, request_spec=request_spec,
                filter_properties=filter_properties,
                admin_password=admin_password,
                injected_files=injected_files,
                requested_networks=requested_networks,
                security_groups=security_groups,
                block_device_mapping=block_device_mapping, node=node,
                limits=limits)

未完待续。。。

相关文章
最新文章
热点推荐