Google Cloud-Compute Engine,使用实例模板插入实例

Mawiguk0

我想通过Java google-api-client使用InstanceTemplate创建一个实例。执行完该操作后,新实例将在GCP的Compute Engine前端中显示,即创建beein。10-15秒后,实例消失。GCP-Compute Engine虚拟机实例概述

按照参考手册,我无法理解为什么我的代码无法正常工作。
https://cloud.google.com/compute/docs/reference/rest/v1/instances/insert

Compute.Instances.Insert insert = compute
                    .instances()
                    .insert("{{project-id}}","europe-west1-c",instance)
                    .setSourceInstanceTemplate("/compute/v1/projects/{{project-id}}/global/instanceTemplates/instance-template-1")
                    .setZone("europe-west1-c")
                    .setProject("{{project-id}}");
            Operation op = insert.execute();

实例对象如下所示:

Instance instance = new Instance();
instance.setName(instanceName);
instance.setMachineType("zones/europe-west1-c/machineTypes/g1-small");

Gradle依赖

compile 'com.google.api-client:google-api-client:1.31.2'  
compile group: 'com.google.apis', name: 'google-api-services-compute', version: 'v1-rev235-1.25.0'

来自GCP的日志:

{
  "protoPayload": {
    "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
    "status": {
      "code": 3,
      "message": "INVALID_PARAMETER"
    },
    "authenticationInfo": {
      "principalEmail": "compute-dev-me@{{project-id}}.iam.gserviceaccount.com"
    },
    "requestMetadata": {
      "callerIp": "12.34.56.78",
      "callerSuppliedUserAgent": "redacted/0.1 Google-API-Java-Client/1.31.2 Google-HTTP-Java-Client/1.37.0 (gzip),gzip(gfe)"
    },
    "serviceName": "compute.googleapis.com",
    "methodName": "v1.compute.instances.insert",
    "resourceName": "projects/{{project-id}}/zones/europe-west1-c/instances/test-mit-richtig",
    "request": {
      "@type": "type.googleapis.com/compute.instances.insert"
    }
  },
  "insertId": "-duwg4fde7a2",
  "resource": {
    "type": "gce_instance",
    "labels": {
      "instance_id": "redacted-number",
      "zone": "europe-west1-c",
      "project_id": "{{project-id}}"
    }
  },
  "timestamp": "2021-02-xxTxx:xx:xx.565227Z",
  "severity": "ERROR",
  "logName": "projects/{{project-id}}/logs/cloudaudit.googleapis.com%2Factivity",
  "operation": {
    "id": "operation-1613xxxx41-xxxxxxxx-xxxxxxxx-xxxxxxx",
    "producer": "compute.googleapis.com",
    "last": true
  },
  "receiveTimestamp": "2021-02-xxTxx:xx:xx.569578819Z"
}
迪伦

查看提供的日志后,您将收到无效参数错误代码。在参数中,按如下所示设置实例名称:

instance.setName(instanceName);

GCE实例具有命名约定,其中名称必须以小写字母开头,后跟一串字符或连字符,并且不能以连字符结尾。在您的情况下,您的代码中有一个大写的n(实例N ame)。进行如下设置可以解决该问题:

instance.setName(instancename);

我在您的日志中注意到的另一件事是,如果您尚未对项目ID进行编辑,则项目ID会显示为{{project-id}}(如果这样做是一种很好的做法,但是您应指定代码的经过编辑的部分以帮助了解日志)。

-----在评论后编辑-----

在Google Cloud Platform上检查活动标签后,我们看到它是由服务帐户权限引起的。

在以下链接中,您可以找到有关创建和启用服务帐户的信息

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Google Cloud Compute Engine上运行python脚本

Google Compute Engine-克隆实例

重命名Google Compute Engine VM实例

从Jenkins Rsync到Google Compute Engine实例

Google Compute Engine:增加实例的内存/ CPU

如何以root用户身份登录Google Cloud Compute Engine?

无法访问Google Cloud Compute实例外部IP

如何移植Google Compute Engine实例?

推送后如何使用BitBucket管道更新Google Cloud Compute Engine实例?

SSH到Google Compute Engine实例失败

无法删除Google Cloud Platform上的Compute Engine实例

在Google Cloud Compute Engine上运行python脚本

如何将Google Cloud App Engine Web应用程序链接到Google Compute Engine VM实例?

Google Cloud Compute Engine VM因未知原因停止了?

Google Compute Engine实例的GUI

允许Google Cloud Compute Engine实例将文件写入Google存储桶-Python

Google Cloud Compute Engine上的xgboost超慢

如何仅在一个或两个特定的Google Cloud Compute Engine实例上授予“编辑”角色?

GKE与Google Cloud上的Compute Engine之间的专用连接

在Google Cloud Compute实例启动时启动python脚本

Google Cloud Compute Engine VM实例组始终自动修复为最大实例数

在区域之间移动Google Cloud Compute实例

如何查看Google Cloud Compute Engine日志

在Google Compute Engine上将Google Cloud SQL与Wordpress连接

实时更新Google Compute Engine实例类型

Google Compute Engine VM实例访问权限

限制 Google Cloud Platform Compute 上的实例大小

在 Compute Engine 上安装 Google Cloud SDK:权限被拒绝错误

使用 REST API 显示应用于 Google Cloud Platform Compute Engine 实例的访客策略