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

时间:2014-08-12 15:03:29

标签: java google-compute-engine

我正在尝试使用Google Java API创建实例但是我收到错误:

{   “代码”:400,   “错误”:[{     “域名”:“全球”,     “message”:“字段'resource.machineType'的值无效:'https://www.googleapis.com/compute/v1/projects/...snip.../zones/europe-west1-a/machineTypes/n1-standard-1'。不允许使用此资源类型的跨项目引用。”,     “理由”:“无效”   }],   “message”:“字段'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();

1 个答案:

答案 0 :(得分:0)

根据this link,我认为您的请求应如下所示:

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