简体   繁体   English

如何从Google Cloud Function中的快照创建磁盘-Node.js

[英]How to create disk from snapshot in google cloud function - node js

I have been struggling to find a solution for this particular problem. 我一直在努力寻找针对此特定问题的解决方案。 I've gone through almost all the documentation of gcloud/compute node module which is used in google cloud functions . 我已经遍历了google cloud functions使用的gcloud/compute node模块的几乎所有文档。

Now my challenge is to create a new disk from an existing snapshot in google cloud function . 现在,我面临的挑战是从google cloud function的现有snapshot创建新disk

I have used below code to create a disk. 我已使用以下代码创建磁盘。 As they haven't provided any example to create a disk from a snapshot . 因为他们还没有提供任何从snapshot创建disk示例。 Following cloud function creates a new disk named disk1 which is entirely fresh and new disk. 随后的cloud function创建一个名为disk1的新disk ,该disk完全是新磁盘。 I don't want that. 我不要 I want to create a disk from an existing snapshot which has some data and setup in it. 我想从现有snapshot创建一个磁盘,其中包含一些数据和设置。

 exports.tempFunction = (req, res) => { // Example input: {"message": "Hello!"} const Compute = require(`@google-cloud/compute`); const compute = new Compute(); const zone = compute.zone('us-central1-a'); const disk = zone.disk('disk1'); const config = { // ... //os:'ubuntu' }; disk.create(config, function(err, disk, operation, apiResponse) { // `disk` is a Disk object. // `operation` is an Operation object that can be used to check the // status of the request. console.log(err); console.log(disk); console.log(operation); console.log(apiResponse); res.status(200).send("success"); }); }; 

Any help in this regard is highly appreciated. 在这方面的任何帮助都将受到高度赞赏。

PS I also tried using cloud APIs. PS我也尝试过使用云API。 But as I want only to use the cloud functions and I am unable to figure out that how do I get access token for gcloud to use inside cloud functions 但是由于我只想使用cloud functions ,所以我无法弄清楚如何获取gcloud访问令牌以在cloud functions内部使用

The disk creation [1] can be customized by setting the disk resource fields [2] in the config object. 可以通过在config对象中设置磁盘资源字段[2]来定制磁盘创建[1] In this case, set the sourceSnapshot field in the config to the existing snapshot partial or full URL. 在这种情况下,请将配置中的sourceSnapshot字段设置为现有快照的部分或完整URL。 The code should look like this: 该代码应如下所示:

 exports.tempFunction = (req, res) => { // Example input: {"message": "Hello!"} const Compute = require(`@google-cloud/compute`); const compute = new Compute(); const zone = compute.zone('us-central1-a'); const disk = zone.disk('disk1'); const config = { sourceSnapshot: "projects/{YOUR-PROJECT}/global/snapshots/{YOUR_SNAPSHOT}" }; disk.create(config, function(err, disk, operation, apiResponse) { // `disk` is a Disk object. // `operation` is an Operation object that can be used to check the // status of the request. console.log(err); console.log(disk); console.log(operation); console.log(apiResponse); res.status(200).send("success"); }); }; 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase 函数 - 如何从云 function 返回文档快照? - Firebase Functions - How to return a document snapshot from a cloud function? 自定义 Object 用于 Node.js 中的 Cloud Firestore 在快照中运行。数据不是 function 错误 - Custom Object for Cloud Firestore in Node.js runs in snapshot.data is not a function error 使用node.js为Google云端存储创建已签名的网址,以便从浏览器直接上传 - Create signed URLs for Google Cloud Storage with node.js for direct upload from browser 使用 node.js 从 Google Cloud 函数中的 IncomingMessage 对象读取正文 - Read Body from IncomingMessage Object in a Google Cloud Function with node.js 如何使用复杂的 JSON Webhook 中的 Node JS Cloud Function 写入 Cloud Firestore? - How to write to the Cloud Firestore using Node JS Cloud Function from Complex JSON Webhook? 从 Firebase Cloud Function 在 Google Cloud Bucket 中创建文件 - Create File in Google Cloud Bucket from Firebase Cloud Function 如何从异步函数响应创建Node.js模块? - How to create a Node.js module from Asynchronous Function response? 如何从 Node.js 中的 function 访问 Cloud Function 的返回值 Map? - How can I access return value of Map from function in Node.js for Cloud Function? 如何使用 node.js 客户端库以编程方式从 google-cloud-automl 获取模型 ID - How to programmatically get model id from google-cloud-automl with node.js client library 如何使用 google-cloud 和 node js 从 firebase 存储中检索图像并将其显示在网页上 - how to retrieve image from firebase storage and display it on a webpage using google-cloud and node js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM