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.py
class 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.py
class 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的調用過程。