Unable to create disk from snapshot using google cloud engine API
<p>I'm trying to create a disk from a snapshot using google cloud python API:</p>

<pre><code>def createDisk(compute, project, zone):
  config = {
    'name': disk_name
  }

  return compute.disks().insert(
    project=project,
    zone=zone,
    sourceSnapshot='global/snapshots/' + snap_name,
    body=config).execute()
</code></pre>

<p>But it throws:</p>

<pre><code>TypeError: Got an unexpected keyword argument "sourceSnapshot"
</code></pre>

<p>According to the <a href="https://cloud.google.com/compute/docs/reference/latest/disks/insert" rel="nofollow">docs</a> it should be possible:</p>

<blockquote>
  <p>Creates a persistent disk in the specified project using the data in the request. You can create a disk with a sourceImage, a sourceSnapshot, or create an empty 500 GB data disk by omitting all properties. You can also create a disk that is larger than the default size by specifying the sizeGb property.</p>
</blockquote>

<p>I need it to automate an image creation which I want to base on the 'dummy' instance. The image should then be used to create a disk which in turn will be used in the instance template for the auto scaling.</p>

<p>Any tips on that one? Is it possible? If no, the <code>sourceSnapshot</code> reference be in the docs is really misleading?</p>

<p>Thank you in advance.</p>

<p>It came out that <code>sourceSnapshot</code> should be part of the body request, not an argument. So that would work:</p>

<pre><code>def createDisk(compute, project, zone):
  config = {
    'name': disk_name,
    'sourceSnapshot': 'global/snapshots/' + snap_name,
  }

  return compute.disks().insert(
    project=project,
    zone=zone,
    body=config).execute()
</code></pre>

python google-cloud-platform