【问题标题】:What does `gcloud compute instances create` do? - POST https://compute.googleapis.com…`gcloud 计算实例创建`做什么? - 发布 https://compute.googleapis.com…
【发布时间】:2021-08-05 16:09:16
【问题描述】:

使用gcloud CLI 可以很容易地完成一些事情,例如:

$ 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)')

(在命令中详尽无遗,拆除)

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

…但不清楚 REST API 端的等效命令是什么。特别是考虑到大量的选项,例如,https://cloud.google.com/compute/docs/reference/rest/v1/instances/insert

所以当我为 Google Cloud 的 Compute Engine 编写自定义 REST API 客户端时,我想窃取 gcloud 在内部所做的一切。


运行rg 我发现了一堆这样的行: https://github.com/googleapis/google-auth-library-python/blob/b1a12d2/google/auth/transport/requests.py#L182

特别是lib/third_party中的这5个:

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

我在每个人的下方添加了_LOGGER.debug("With body: %s", body)。但似乎有一些fancy batching 正在进行,因为我几乎从来没有得到那条With body 行????

现在正在与 Wireshark 搞混,看看我能找到什么,但我相信这是一个糟糕的兔子洞。 https://console.cloud.google.com/home/activity 同上。


我怎样才能知道gcloud设置的body是什么?

【问题讨论】:

  • 它完全按照所说的进行。
  • @MartinZeitler 是的,但是使用什么参数? - 我如何复制它,比如curl
  • 到底为什么curlgcloud 显然不是 HTTP 资源。
  • @MartinZeitler - 这只是一个例子。我正在用 C 写一个 gcloud compute 等价物。gcloud compute 所做的就是调用 cloud.google.com/compute/docs/reference/rest/v1。这个问题是询问他们在调用中设置了哪些参数和正文;以及如何推断。
  • 添加命令行选项 --log-http 以查看 REST API 参数。由于 CLI 会随着时间而变化,因此没有简单的答案。添加、删除新功能等。

标签: google-cloud-platform google-compute-engine reverse-engineering gcloud google-cloud-sdk


【解决方案1】:

添加命令行选项 --log-http 以查看 REST API 参数。

没有简单的答案,因为 CLI 会随着时间而变化。添加、删除新功能等。

【讨论】:

    猜你喜欢
    • 2020-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多