Samuel Marks
Samuel Marks

Reputation: 1878

What does `gcloud compute instances create` do? - POST https://compute.googleapis.com…

Some things are very easy to do with the gcloud CLI, like:

$ export network='default' instance='example-instance' firewall='ssh-http-icmp-fw'
$ gcloud compute networks       create "$network"
$ gcloud compute firewall-rules create "$firewall" --network "$network" \
                                                   --allow 'tcp:22,tcp:80,icmp'
$ gcloud compute instances      create "$instance" --network "$network" \
                                                   --tags 'http-server' \
                                                   --metadata \
  startup-script='#! /bin/bash
  # Installs apache and a custom homepage
  apt update
  apt -y install apache2
  cat <<EOF > /var/www/html/index.html
  <html><body><h1>Hello World</h1>
  <p>This page was created from a start up script.</p>
  </body></html>'
$ # sleep 15s
$ curl $(gcloud compute instances list --filter='name=('"$instance"')' \
                                       --format='value(EXTERNAL_IP)')

(to be exhaustive in commands, tear down with)

$ gcloud compute networks       delete -q "$network"
$ gcloud compute firewall-rules delete -q "$firewall"
$ gcloud compute instances      delete -q "$instance"

…but it's not clear what the equivalent commands are from the REST API side. Especially considering the HUGE number of options, e.g., at https://cloud.google.com/compute/docs/reference/rest/v1/instances/insert

So I was thinking to just steal whatever gcloud does internally when I write my custom REST API client for Google Cloud's Compute Engine.


Running rg I found a bunch of these lines: https://github.com/googleapis/google-auth-library-python/blob/b1a12d2/google/auth/transport/requests.py#L182

Specifically these 5 in lib/third_party:

google/auth/transport/{_aiohttp_requests.py,requests.py,_http_client.py,urllib3.py}
google_auth_httplib2/__init__.py

Below each of them I added _LOGGER.debug("With body: %s", body). But there seems to be some fancy batching going on because I almost never get that With body line 😞

Now messing with Wireshark to see what I can find, but I'm confident this is a bad rabbit hole to fall down. Ditto for https://console.cloud.google.com/home/activity.


How can I find out what body is being set by gcloud?

Upvotes: 0

Views: 418

Answers (1)

John Hanley
John Hanley

Reputation: 81416

Add the command line option --log-http to see the REST API parameters.

There is no simple answer as the CLI changes over time. New features are added, removed, etc.

Upvotes: 3

Related Questions