1

I am trying to automate the creation/launch of instances. I would like Google Compute Engine to launch an instance and execute a certain task for me on a couple of days of the week. Is that possible with GCE somehow?

4

1 回答 1

4

您可以使用 Compute Engine API 启动实例。

这是一个运行 App Engine cron 作业的示例应用程序,该作业删除实例: https ://github.com/GoogleCloudPlatform/compute-appengine-timeout-python

您可以使用它作为起点,并修改:

  • cron 计划按您的计划而不是每小时运行一次
  • 而不是compute.instances().delete(), call compute.instances().insert(INSTANCE),其中INSTANCE是描述您要创建的实例的 JSON 文档。

(有关 JSON doc 格式的详细信息,请参阅启动实例的文档,或在Cloud Console中填写创建实例的表单,然后单击“等效 REST”链接(在创建实例之前)。

的 API 文档instances.insert()

在 INSTANCE 文档中,您可以为Startup Scripts添加元数据条目。这是一个在实例启动后立即运行的 shell 脚本。您可以添加命令以在那里执行您的任务。

任务完成后,实例可以自行删除。(有关详细信息,请参阅此答案:如何自动退出/停止正在运行的实例

于 2013-08-02T22:54:36.147 回答