chandan
chandan

Reputation: 71

Creating VM instance from machine image using REST API

I am struggling to create a VM instance using machine image from the REST API.

I can create an instance using 'Try this API' from https://cloud.google.com/compute/docs/reference/rest/beta/instances/insert

{
        "name": 'demo-x2',
        "projects": 'resonant-time-282213',
        "zone" : 'asia-east1-c',
        "sourceMachineImage" : 'projects/resonant-time-282213/global/machineImages/t4-mtml-1',
        "machineType" : 'projects/resonant-time-282213/zones/asia-east1-c/machineTypes/n1-standard-8'
}

While using it inside a python code, it shows the following error in the terminal:

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://compute.googleapis.com/compute/v1/projects/resonant-time-282213/zones/asia-east1-c/instances?alt=json returned "Invalid value for field 'resource.disks': ''. No disks are specified.". Details: "Invalid value for field 'resource.disks': ''. No disks are specified.">

Which disk info is it looking for? The disk details are already in the machine image.

Upvotes: 6

Views: 1014

Answers (1)

Dominic Dodge
Dominic Dodge

Reputation: 21

It looks like this is only available in the "beta" channel right now.

So when you build your object your have to use "beta" instead of "V1" like this:

service = discovery.build('compute', 'beta', credentials=credentials)

Upvotes: 2

Related Questions