0
votes

When running Google Compute Engine I get unexpected results, different from gcutil, when querying images and kernels. Notably I do not get any results.

With gcutil I get the expected result of:

$ gcutil --project MYPROJECT listimages

+----------------------------------------------------------------+----------------------------------------------------------------+----------------------------------------------+-------------+--------+
|                              name                              |                          description                           |                    kernel                    | deprecation | status |
+----------------------------------------------------------------+----------------------------------------------------------------+----------------------------------------------+-------------+--------+
| projects/centos-cloud/global/images/centos-6-v20130731         | SCSI-enabled CentOS 6; Created Wed, 31 Jul 2013 00:00:00 +0000 | projects/google/global/kernels/gce-v20130603 |             | READY  |
| projects/debian-cloud/global/images/debian-6-squeeze-v20130723 | Debian GNU/Linux 6.0.7 (squeeze) built on 2013-07-23           | projects/google/global/kernels/gce-v20130603 |             | READY  |
| projects/debian-cloud/global/images/debian-7-wheezy-v20130723  | Debian GNU/Linux 7.1 (wheezy) built on 2013-07-23              | projects/google/global/kernels/gce-v20130603 |             | READY  |
+----------------------------------------------------------------+----------------------------------------------------------------+----------------------------------------------+-------------+--------+

But when I use the web API or the Python API with something like this (abbreviated, but basically straight from the examples):

def _service():
    flow = flow_from_clientsecrets(CLIENT_SECRETS, scope=GCE_SCOPE)
    storage = Storage(OAUTH2_STORAGE)
    credentials = storage.get()
    if credentials is None or credentials.invalid:
        credentials = run(flow, storage)
    http = httplib2.Http()
    auth_http = credentials.authorize(http)
    gce_service = build('compute', API_VERSION)
    return gce_service, credentials, auth_http

if __name__ == "__main__":
    gce_service, credentials, auth_http = _service()
    request = gce_service.images().list(project="MYPROJECT", filter=None)
    response = request.execute(http=auth_http)
    pprint(response)

Both the Web and Python API return something like this:

{
 "kind": "compute#imageList",
 "selfLink": "https://www.googleapis.com/compute/v1beta15/projects/MYPROJECT/global/images",
 "id": "projects/MYPROJECt/global/images"
}

i.e. missing the items that one expects in the response.

What might I be doing wrong here?

2

2 Answers

1
votes

The google (and public) provided images and kernels are stored in a different project. The idea is that these aren't yours, per se, but instead are published by google (or debian or centos).

You can list kernels with gcutil listkernels --project=google. The equivalent with code is to replace MYPROJECT with google.

For images, you can use centos-cloud for CentOS images and debian-cloud for debian images.

gcutil automatically integrates from common projects for ease of use.

1
votes

Example app from Google https://developers.google.com/compute/docs/api/python_guide#listinginstances lists images correctly. Not sure how code works. You define function _service(opts) with one arguments and then on line 13 you call it with no arguments gce_service, credentials, auth_http = _service()

Please provide working code.