java - Google API 创建实例 - 字段 'resource.machineType' 的值无效

标签 java google-compute-engine

我正在尝试使用 Google Java API 创建实例,但出现错误:

{ “代码”:400, “错误”:[{ “域”:“全局”, “消息”:“字段‘resource.machineType’的值无效:‘https://www.googleapis.com/compute/v1/projects/...snip.../zones/europe-west1-a/machineTypes/n1-standard-1’。不允许跨项目引用此资源类型。”, “原因”:“无效” } ], “消息”:“字段‘resource.machineType’的值无效:‘https://www.googleapis.com/compute/v1/projects/...snip.../zones/europe-west1-a/machineTypes/n1-standard-1’。不允许跨项目引用此资源类型。”

我使用的代码:

    Compute compute = getComputeService();

    // uri reveals: https://www.googleapis.com/compute/v1/projects/...projectid.../zones/europe-west1-a/machineTypes/n1-standard-1

    String uri = GOOGLE_BASE + this.project + "/zones/" + zone + INSTANCETYPES + type;

    Instance instance = new Instance();
    instance.setName(name);
    instance.setZone(zone);
    instance.setMachineType(uri);

    List<AttachedDisk> disks = new ArrayList<AttachedDisk>();
    AttachedDisk boot = new AttachedDisk();
    boot.setAutoDelete(false);
    boot.setType(disk.getType());
    boot.setBoot(true);
    boot.setDeviceName(disk.getName());
    disks.add(boot);

    List<NetworkInterface> interfaces = new ArrayList<NetworkInterface>();
    NetworkInterface nat = new NetworkInterface();
    nat.setName("External NAT");
    nat.setNetwork("ONE_TO_ONE_NAT");


    instance.setNetworkInterfaces(interfaces);
    instance.setDisks(disks);

    Instances.Insert request = compute.instances().insert(name, zone, instance);

    Operation result = request.execute();

最佳答案

根据 this link ,我相信您的请求应该如下所示:

Instances.Insert request = compute.instances().insert(this.project, zone, instance);

关于java - Google API 创建实例 - 字段 'resource.machineType' 的值无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25267769/

相关文章:

google-app-engine - 从 ComputeEngine 访问 DataStore

java - 如何延迟从 gwt 调用数据库?

java - hibernate 鉴别器

linux - 如何在没有段错误的情况下在 Google Compute Engine 上运行 R

mysql - 在启动默认 SQL 代理连接时更改默认 MySQL 或 PostgreSQL 端口号

docker - 如何在使用 gcloud compute instance update-container 或强制其使用默认驱动程序时设置日志驱动程序 gcplogs?

google-cloud-platform - 在 gcp 中限制用户对 VM 的访问

java - 下载并覆盖功能

java - 如何找出在 foo 循环中创建的 JRadioButton 的名称是什么

java - 按行迭代 Java RDD