如何在 python 中创建本地机器磁盘或任何 VM 磁盘的快照。
我已阅读有关谷歌云快照的信息,这是 python 代码
"""
BEFORE RUNNING:
---------------
1. If not already done, enable the Compute Engine API
and check the quota for your project at
https://console.developers.google.com/apis/api/compute
2. This sample uses Application Default Credentials for authentication.
If not already done, install the gcloud CLI from
https://cloud.google.com/sdk and run
`gcloud beta auth application-default login`.
For more information, see
https://developers.google.com/identity/protocols/application-default-credentials
3. Install the Python client library for Google APIs by running
`pip install --upgrade google-api-python-client`
"""
from pprint import pprint
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
service = discovery.build('compute', 'v1', credentials=credentials)
# Project ID for this request.
project = 'my-project' # TODO: Update placeholder value.
# The name of the zone for this request.
zone = 'my-zone' # TODO: Update placeholder value.
# Name of the persistent disk to snapshot.
disk = 'my-disk' # TODO: Update placeholder value.
snapshot_body = {
# TODO: Add desired entries to the request body.
}
request = service.disks().createSnapshot(project=project, zone=zone, disk=disk, body=snapshot_body)
response = request.execute()
# TODO: Change code below to process the `response` dict:
pprint(response)
如何使用此代码创建本地磁盘的快照并将其存储在本地计算机上供以后使用?