I'm trying to create a disk snapshot using python api client of google cloud platform, Heres what's I have tried: From views.py
if request.method == 'POST':
form = forms.SnapshotForm(request.POST)
if form.is_valid():
obj = snapy()
obj.project = form.cleaned_data['project']
obj.instance = form.cleaned_data['instance']
obj.zone = form.cleaned_data['zone']
obj.snapshot = form.cleaned_data['snap_name']
# Google Cloud stuff for Snapshot
service = discovery.build('compute', 'v1',
credentials=credentials)
project_id = obj.project
zone = obj.zone
disk = obj.instance
snapshot_body = {}
request = service.disks().createSnapshot(project=project_id, zone=zone,
disk=disk, body=snapshot_body)
response = request.execute()
pprint(response)
obj.save()
print(obj)
return HttpResponse('Good', status=200)
It returns no error but snapshot not created on gcp console. Is there something wrong I have configured? help me, please!
Here's the response:
[10/Sep/2017 08:09:46] "GET /snap/ HTTP/1.1" 200 2740
{'id': '8462873153659819689',
'insertTime': '2017-09-13T01:11:51.025-07:00',
'kind': 'compute#operation',
'name': 'operation-1505290310763-5590db641c1f8-9be2938e-9e1b974f',
'operationType': 'createSnapshot',
'progress': 0,
'selfLink': 'https://www.googleapis.com/compute/v1/projects/istiodep/zones/asia-northeast1-c/operations/operation-1505290310763-5590db641c1f8-9be2938e-9e1b974f',
'status': 'PENDING',
'targetId': '1514253394633906452',
'targetLink': 'https://www.googleapis.com/compute/v1/projects/istiodep/zones/asia-northeast1-c/disks/instance-1',
'user': '[email protected]',
'zone': 'https://www.googleapis.com/compute/v1/projects/istiodep/zones/asia-northeast1-c'
}
Snapshot object