1.删除虚拟机时,首选调用compute api中的delete方法,然后rpc cast到compute manager 的terminate_instance--->delete_instance方法,做第一次清除操作:
def _delete_instance(self, context, instance):
"""Delete an instance on this host."""
instance_id = instance['id']
self._notify_about_instance_usage(instance, "delete.start")
self._shutdown_instance(context, instance, 'Terminating')
self._cleanup_volumes(context, instance_id)
self._instance_update(context,
instance_id,
vm_state=vm_states.DELETED,
task_state=None,
terminated_at=utils.localnow())
self.db.instance_destroy(context, instance_id)
self._notify_about_instance_usage(instance, "delete.end")
在_shutdown_instance方法中,解除与ip的关联,解除与spice端口的关联,存储相关。
删除网络调用NetworkManager的deallocate_for_instance方法,deallocate_for_instance是NetworkManager父类的一个方法,在子类中,通过deallocate_fixed_ip来实现具体的删除。在e版本中,dns和domain的drivers还没有实现。删除ip的操作首先是要解除数据库ip池中的关系,然后更新network里面的数据,_teardown_network_on_host方法。比如更新nova-br100.conf文件
def _teardown_network_on_host(self, context, network):
if not FLAGS.fake_network:
network['dhcp_server'] = self._get_dhcp_ip(context, network)
dev = self.driver.get_dev(network)
self.driver.update_dhcp(context, dev, network)
def update_dhcp(context, dev, network_ref):
conffile = _dhcp_file(dev, 'conf')
write_to_file(conffile, get_dhcp_hosts(context, network_ref))
restart_dhcp(context, dev, network_ref)
更新完成后,需要重启dhcp服务,