Last active
May 20, 2020 14:45
-
-
Save zuedev/fd627a9251147345f5a9a2b66568ab9b to your computer and use it in GitHub Desktop.
gcp_unpreempter.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Compute = require("@google-cloud/compute"); | |
| const compute = new Compute(); | |
| const state = { | |
| msg: "", | |
| }; | |
| exports.init = (req, res) => { | |
| compute.getVMs().then((data) => { | |
| data[0].forEach((vm) => { | |
| vm.getMetadata().then((data) => { | |
| if (data[0].status === "TERMINATED") { | |
| vm.start(); | |
| state.msg += `${data[0].name} is terminated, starting!\n`; | |
| } else { | |
| state.msg += `${data[0].name} isn't terminated, skipping...\n`; | |
| } | |
| }); | |
| }); | |
| }); | |
| res.status(200).send("I did it owo"); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "dependencies": { | |
| "@google-cloud/compute": "^1.0.0" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment