Nova结构

来源:互联网 发布:debian ubuntu 对比 编辑:程序博客网 时间:2024/05/17 03:42

Juno中Nova结构


                      Client                         |                       API-------------------                         |                  |            Compute<-->Queue<->Scheduler    |                         |         |        |                      Conductor-->DB<--------
API            :Nova的HTTP接口。
Scheduler:从可用池中选择最合适的计算节点来创建新的虚拟机实例。
Conductor:为数据库的访问提供一层安全保障。
Client        :简化RESTful API使用所提供的API封装novaclient,负责将用户请求转换为标准的HTTP请求。


源码状况

理解Nova的代码主要从其源码的setup.cfg文件来分析。

其中,setup.cfg中的[entry_points]为Nova提供的各个服务的入口点。

[entry_points]...console_scripts =    nova-all = nova.cmd.all:main    nova-api = nova.cmd.api:main    nova-api-ec2 = nova.cmd.api_ec2:main    nova-api-metadata = nova.cmd.api_metadata:main    nova-api-os-compute = nova.cmd.api_os_compute:main    nova-cells = nova.cmd.cells:main    nova-cert = nova.cmd.cert:main    nova-compute = nova.cmd.compute:main    nova-conductor = nova.cmd.conductor:main    nova-console = nova.cmd.console:main    nova-consoleauth = nova.cmd.consoleauth:main    nova-dhcpbridge = nova.cmd.dhcpbridge:main    nova-idmapshift = nova.cmd.idmapshift:main    nova-manage = nova.cmd.manage:main    nova-network = nova.cmd.network:main    nova-novncproxy = nova.cmd.novncproxy:main    nova-objectstore = nova.cmd.objectstore:main    nova-rootwrap = oslo_rootwrap.cmd:main    nova-rootwrap-daemon = oslo_rootwrap.cmd:daemon    nova-scheduler = nova.cmd.scheduler:main    nova-serialproxy = nova.cmd.serialproxy:main    nova-spicehtml5proxy = nova.cmd.spicehtml5proxy:main    nova-xvpvncproxy = nova.cmd.xvpvncproxy:main

这其中的主要服务如下所示:
  • nova-all : 启动所有Nova服务的辅助脚本,API服务作为WSGI服务器启动。
  • nova-api: RESTful API服务,其提供nova-api-ec2,nova-api-metadata,nova-api-os-compute三种API服务,根据/etc/nova/nova.conf的enabled_apis选项来设置启动这些服务。
  • nova-api-ec2: Amazon EC2 API支持。
  • nova-api-metadata: 接受虚拟机实例metadata(元数据)相关的请求,目前由Neutron完成,只在nova-network中使用。
  • nova-api-os-compute: OpenStack API服务。
  • nova-baremetal-manage: Baremetal是使用户可以像管理虚拟机一样管理物理机,目前由Ironic服务来做。
  • nova-cell: Cell模块启用后,OpenStack环境中的主机被划分成组,称为Cell。Cell可以被配置成树形结构,OpenStack云环境通过添加子Cell的方式进行拓展。nova-cell负责各个Cell之间的通信。
  • nova-compute: compute服务
  • nova-conductor: conductor服务
  • nova-console: 允许用户通过代理访问虚拟机实例的控制台,已经被nova-xvpnvncproxy取代
  • nova-dhcpbridge: 管理nova-network的DHCPbridge。
  • nova-manage: 提供很多与Nova的维护和管理相关的功能,如用户创建、VPN管理。
  • nova-network: 提供网络服务,已被Neutron取代。
  • nova-novncproxy:提供novncproxy代理支持用户通过vnc访问虚拟机。这涉及几个Nova服务,nova-consoleauth提供认证授权,nova-novncproxy支持基于浏览器的vnc客户端,nova-xvpnvncserver用于支持基于Java的vnc客户端。
  • nova-objectstore:兼容Amazon EC2的存储接口。
  • nova-rootwrap:用于在OpenStack运行过程中以root身份运行某些shell命令。
  • nova-scheduler: Scheduler服务。
另外,[entry_points]中的另一个主要命名空间nova.api.v*.extensions,每一项都对应一个API,Nova API启动时会根据这些进行加载,从而OpenStack部署时可以进行灵活的配置。
nova.api.v21.extensions =    access_ips = nova.api.openstack.compute.access_ips:AccessIPs    admin_actions = nova.api.openstack.compute.admin_actions:AdminActions    admin_password = nova.api.openstack.compute.admin_password:AdminPassword    agents = nova.api.openstack.compute.agents:Agents    aggregates = nova.api.openstack.compute.aggregates:Aggregates    assisted_volume_snapshots = nova.api.openstack.compute.assisted_volume_snapshots:AssistedVolumeSnapshots    attach_interfaces = nova.api.openstack.compute.attach_interfaces:AttachInterfaces    availability_zone = nova.api.openstack.compute.availability_zone:AvailabilityZone    baremetal_nodes = nova.api.openstack.compute.baremetal_nodes:BareMetalNodes    block_device_mapping = nova.api.openstack.compute.block_device_mapping:BlockDeviceMapping    cells = nova.api.openstack.compute.cells:Cells    certificates = nova.api.openstack.compute.certificates:Certificates    cloudpipe = nova.api.openstack.compute.cloudpipe:Cloudpipe    config_drive = nova.api.openstack.compute.config_drive:ConfigDrive    console_auth_tokens = nova.api.openstack.compute.console_auth_tokens:ConsoleAuthTokens    console_output = nova.api.openstack.compute.console_output:ConsoleOutput    consoles = nova.api.openstack.compute.consoles:Consoles    create_backup = nova.api.openstack.compute.create_backup:CreateBackup    deferred_delete = nova.api.openstack.compute.deferred_delete:DeferredDelete    disk_config = nova.api.openstack.compute.disk_config:DiskConfig    evacuate = nova.api.openstack.compute.evacuate:Evacuate    extended_availability_zone = nova.api.openstack.compute.extended_availability_zone:ExtendedAvailabilityZone    extended_server_attributes = nova.api.openstack.compute.extended_server_attributes:ExtendedServerAttributes...

Nova中的RPC

Nova中各个服务之间的通信使用了基于AMQP实现的RPC机制。其中,nova-compute、nova-conductor、nova-scheduler在启动时会注册一个RPC Server,而nova-api因为Nova内部并没有服务会调用它提供的接口,所以无需注册。
如下代码:
class ComputeAPI(object):...    def add_fixed_ip_to_instance(self, ctxt, instance, network_id):        version = '4.0'        #获取目标机的RPC client        cctxt = self.client.prepare(server=_compute_host(None, instance),                version=version)        #cast用于异步形式,而call用于同步方式。 add_fixed_ip_to_instance为RPC调用的函数名,后面的参数将作为参数传入此函数        #从而完成远程调用        cctxt.cast(ctxt, 'add_fixed_ip_to_instance',                   instance=instance, network_id=network_id)

类ComputeAPI中的函数即为Compute服务提供给RPC调用的接口,如:
#nova/conductor/tasks/live_migrate.pyclass LiveMigrationTask(base.TaskBase):    def __init__(self, context, instance, destination,                 block_migration, disk_over_commit, migration, compute_rpcapi,                 servicegroup_api, scheduler_client):        super(LiveMigrationTask, self).__init__(context, instance)        self.destination = destination        self.block_migration = block_migration        self.disk_over_commit = disk_over_commit        self.migration = migration        self.source = instance.host        self.migrate_data = None         self.compute_rpcapi = compute_rpcapi                ...    def _execute(self):        pelf._check_instance_is_active()        self._check_host_is_up(self.source)         if not self.destination:            self.destination = self._find_destination()            self.migration.dest_compute = self.destination            self.migration.save()        else:            self._check_requested_destination()         # TODO(johngarbutt) need to move complexity out of compute manager        # TODO(johngarbutt) disk_over_commit?        return self.compute_rpcapi.live_migration(self.context,                host=self.source,                instance=self.instance,                dest=self.destination,                block_migration=self.block_migration,                migration=self.migration,                migrate_data=self.migrate_data)

类ComputeAPI只是暴露给其他服务的RPC调用接口,Compute服务的RPC接收请求后,真正完成任务的是nova.compute.manager模块
# nova/compute/manager.pyclass ComputeManager(manager.Manager):    target = messaging.Target(version='4.4') def live_migration(self, context, dest, instance, block_migration,                       migration, migrate_data):        """Executing live migration....
从ComputeAPI到ComputeManager的过程为RPC的调用过程。




0 0