我正在将Node.js客户端库用于Google Compute Engine API,通过将现有磁盘附加到该虚拟机来创建新的VM。但是在以下代码下运行时,出现DURATION START END
----------- -------------------- --------------------
+0 00:20:00 8/4/2016 1:40:00 8/4/2016 2:00:00
错误。有人可以帮忙吗?预先感谢!
WITH calculated_values AS (
SELECT DT,
MEASUREMENT,
THRESHOLD,
row_number() OVER (ORDER BY dt) - row_number() OVER (PARTITION BY CASE WHEN MEASUREMENT > THRESHOLD THEN 1 ELSE 0 END ORDER BY dt) rn,
CASE WHEN MEASUREMENT > THRESHOLD THEN 1 ELSE 0 END threshold_flag
FROM measurements)
SELECT cast(numtodsinterval(MAX(dt)-MIN(dt), 'DAY') AS INTERVAL DAY(0) TO SECOND(0)) AS duration,
MIN(dt) AS "START",
MAX(dt) AS "END"
FROM calculated_values
WHERE threshold_flag > 0
GROUP BY rn;
答案 0 :(得分:2)
我知道您请求了nodejs库解决方案,但这将同时起作用。
const exec = require('child-process-promise').exec;
var create_vm = (zone, vmname, diskname) => {
const cmd = `gcloud compute instances create ${vmname} ` +
`--zone=${zone} ` +
`--disk=name=${diskname}`
return exec(cmd);
};
create_vm('us-central1-c', 'my-instance', 'some-disk-in-us-central1-c')
.then(console.log)
.catch(console.error);
当然,您也可以通过这种方式创建启动盘,并根据需要添加任意数量的选项。有关创建实例的选项,请查看here。
答案 1 :(得分:2)
管理用于GCE API的Node.js客户端库的有用人员承认https://cloud.google.com/nodejs/docs/reference/compute/0.10.x/Zone#createVM处的文档不正确。我通过将原始JSON传递到zone.createVM方法来完成这项工作,如下所示:
zone.createVM('debian-http', {
disks: [{
boot: true,
source: 'https://www.googleapis.com/compute/v1/projects/[project-id]/zones/us-central1-f/disks/debian-http'
}],
http: true,
machineType: 'f1-micro'
})
可以在https://cloud.google.com/compute/docs/reference/rest/v1/instances/insert上找到disks属性的更多配置选项。有关该错误的更多信息,请访问https://github.com/googleapis/nodejs-compute/issues/107。希望这对其他人有帮助!