本节通过日志详细分析 Nova Pause / Resume 操作。
有时需要短时间暂停 instance ,可以通过 Pause 操作将 instance 的状态保存到宿主机的内存中。当需要恢复的时候,执行 Resume 操作,从内存中读回instance的状态,然后继续运行instance 。
Pause 和 Resume 的流程图与之前操作一样,见下图
![](https://i-blog.csdnimg.cn/blog_migrate/1fef4f4322a2cd66ca48f3c2b5d26f87.png)
Pause
root@DevStack-Controller:/opt/stack/logs# cat n-api.log | grep req-a432dade-e924-44a2-8f9d-a3d6b204bc28
2019-05-24 14:04:40.578 DEBUG nova.api.openstack.wsgi [req-a432dade-e924-44a2-8f9d-a3d6b204bc28 admin admin]
Action: 'action', calling method: <bound method PauseServerController._pause of <nova.api.openstack.compute.pause_server.PauseServerController object at 0x7fb2f82f4cd0>>, body: {"pause": null} from (pid=28282) _process_stack /opt/stack/nova/nova/api/openstack/wsgi.py:623
2019-05-24 14:04:40.579 DEBUG nova.compute.api [req-a432dade-e924-44a2-8f9d-a3d6b204bc28 admin admin] [instance: 7b56d1e5-235e-4b95-a2fe-74017f744042] Fetching instance by UUID from (pid=28282) get /opt/stack/nova/nova/compute/api.py:2397
2019-05-24 14:04:40.585 DEBUG oslo_concurrency.lockutils [req-a432dade-e924-44a2-8f9d-a3d6b204bc28 admin admin] Lock "5fd8cdfc-e20e-46da-8c1a-88e1c5ce2790" acquired by "nova.context.get_or_set_cached_cell_and_set_connections" :: waited 0.000s from (pid=28282) inner /usr/local/lib/python2.7/dist-packages/oslo_concurrency/lockutils.py:270
2019-05-24 14:04:40.585 DEBUG oslo_concurrency.lockutils [req-a432dade-e924-44a2-8f9d-a3d6b204bc28 admin admin] Lock "5fd8cdfc-e20e-46da-8c1a-88e1c5ce2790" released by "nova.context.get_or_set_cached_cell_and_set_connections" :: held 0.000s from (pid=28282) inner /usr/local/lib/python2.7/dist-packages/oslo_concurrency/lockutils.py:282
2019-05-24 14:04:40.709 DEBUG oslo_messaging._drivers.amqpdriver [req-a432dade-e924-44a2-8f9d-a3d6b204bc28 admin admin] CAST unique_id: f22f52428f7243fdab231aca20d9d0d8 exchange 'nova' topic 'compute.DevStack-Controller' from (pid=28282) _send /usr/local/lib/python2.7/dist-packages/oslo_messaging/_drivers/amqpdriver.py:550
2019-05-24 14:04:40.711 INFO nova.osapi_compute.wsgi.server [req-a432dade-e924-44a2-8f9d-a3d6b204bc28 admin admin] 10.12.31.241 "POST /v2.1/servers/7b56d1e5-235e-4b95-a2fe-74017f744042/action HTTP/1.1" status: 202 len: 337 time: 0.1686220
root@DevStack-Controller:/opt/stack/logs# cat n-cpu.log | grep req-a432dade-e924-44a2-8f9d-a3d6b204bc28 | grep -v oslo
2019-05-24 14:04:40.746 INFO nova.compute.manager [req-a432dade-e924-44a2-8f9d-a3d6b204bc28 admin admin] [instance: 7b56d1e5-235e-4b95-a2fe-74017f744042]
Pausing
2019-05-24 14:04:40.746 DEBUG nova.objects.instance [req-a432dade-e924-44a2-8f9d-a3d6b204bc28 admin admin] Lazy-loading 'flavor' on Instance uuid 7b56d1e5-235e-4b95-a2fe-74017f744042 from (pid=4613) obj_load_attr /opt/stack/nova/nova/objects/instance.py:1058
2019-05-24 14:04:40.802 DEBUG nova.compute.manager [req-a432dade-e924-44a2-8f9d-a3d6b204bc28 admin admin] [instance: 7b56d1e5-235e-4b95-a2fe-74017f744042] Checking state from (pid=4613) _get_power_state /opt/stack/nova/nova/compute/manager.py:1184
Resume (关键字 unpause)
root@DevStack-Controller:/opt/stack/logs# cat n-api.log | grep req-91fc8a59-b266-433a-81bc-9c65dbdc235f
2019-05-24 14:07:45.722 DEBUG nova.api.openstack.wsgi [req-91fc8a59-b266-433a-81bc-9c65dbdc235f admin admin]
Action: 'action', calling method: <bound method PauseServerController._unpause of <nova.api.openstack.compute.pause_server.PauseServerController object at 0x7fb2f82f4cd0>>, body: {"unpause": null} from (pid=28283) _process_stack /opt/stack/nova/nova/api/openstack/wsgi.py:623
2019-05-24 14:07:45.724 DEBUG nova.compute.api [req-91fc8a59-b266-433a-81bc-9c65dbdc235f admin admin] [instance: 7b56d1e5-235e-4b95-a2fe-74017f744042] Fetching instance by UUID from (pid=28283) get /opt/stack/nova/nova/compute/api.py:2397
2019-05-24 14:07:45.729 DEBUG oslo_concurrency.lockutils [req-91fc8a59-b266-433a-81bc-9c65dbdc235f admin admin] Lock "5fd8cdfc-e20e-46da-8c1a-88e1c5ce2790" acquired by "nova.context.get_or_set_cached_cell_and_set_connections" :: waited 0.000s from (pid=28283) inner /usr/local/lib/python2.7/dist-packages/oslo_concurrency/lockutils.py:270
2019-05-24 14:07:45.729 DEBUG oslo_concurrency.lockutils [req-91fc8a59-b266-433a-81bc-9c65dbdc235f admin admin] Lock "5fd8cdfc-e20e-46da-8c1a-88e1c5ce2790" released by "nova.context.get_or_set_cached_cell_and_set_connections" :: held 0.000s from (pid=28283) inner /usr/local/lib/python2.7/dist-packages/oslo_concurrency/lockutils.py:282
2019-05-24 14:07:45.882 DEBUG oslo_messaging._drivers.amqpdriver [req-91fc8a59-b266-433a-81bc-9c65dbdc235f admin admin] CAST unique_id: 438a376cfc8a41c8845e52080b4107b2 exchange 'nova' topic 'compute.DevStack-Controller' from (pid=28283) _send /usr/local/lib/python2.7/dist-packages/oslo_messaging/_drivers/amqpdriver.py:550
2019-05-24 14:07:45.887 INFO nova.osapi_compute.wsgi.server [req-91fc8a59-b266-433a-81bc-9c65dbdc235f admin admin] 10.12.31.241 "POST /v2.1/servers/7b56d1e5-235e-4b95-a2fe-74017f744042/action HTTP/1.1" status: 202 len: 337 time: 0.1988289
root@DevStack-Controller:/opt/stack/logs# cat n-cpu.log | grep req-91fc8a59-b266-433a-81bc-9c65dbdc235f | grep -v oslo
2019-05-24 14:07:45.923 INFO nova.compute.manager [req-91fc8a59-b266-433a-81bc-9c65dbdc235f admin admin] [instance: 7b56d1e5-235e-4b95-a2fe-74017f744042]
Unpausing
2019-05-24 14:07:45.923 DEBUG nova.objects.instance [req-91fc8a59-b266-433a-81bc-9c65dbdc235f admin admin] Lazy-loading 'flavor' on Instance uuid 7b56d1e5-235e-4b95-a2fe-74017f744042 from (pid=4613) obj_load_attr /opt/stack/nova/nova/objects/instance.py:1058
2019-05-24 14:07:45.999 DEBUG nova.virt.libvirt.guest [req-91fc8a59-b266-433a-81bc-9c65dbdc235f admin admin] [instance: 7b56d1e5-235e-4b95-a2fe-74017f744042] Failed to set time: agent not configured from (pid=4613) sync_guest_time /opt/stack/nova/nova/virt/libvirt/guest.py:177
2019-05-24 14:07:45.999 DEBUG nova.compute.manager [req-91fc8a59-b266-433a-81bc-9c65dbdc235f admin admin] [instance: 7b56d1e5-235e-4b95-a2fe-74017f744042] Checking state from (pid=4613) _get_power_state /opt/stack/nova/nova/compute/manager.py:1184