This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Support for instance templates when creating a new compute engine instance #114
Labels
api: compute
Issues related to the googleapis/nodejs-compute API.
type: feature request
‘Nice-to-have’ improvement, new feature or different behavior or design.
Comments
JustinBeckwith
added
triage me
I really want to be triaged.
type: feature request
‘Nice-to-have’ improvement, new feature or different behavior or design.
and removed
triage me
I really want to be triaged.
labels
Jun 25, 2018
I would very much like this feature as well. |
Yes, a PR would be great! |
When this will be available? Is there any other way to create instance from the instance template? |
@edgarmarkosov Indeed there is! The following example uses a token that can be generated when this code is run within another Compute Instance. It was derived from these docs. var createInstance = () => {
const instanceName = 'instance-number-1';
const zoneString = 'us-central1-c';
const projectID = 'some-project-id';
const instanceTemplate = 'secret-x-project';
return new Promise(resolve => {
console.log('Creating:', instanceName)
axios({
method: 'get',
url: 'http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token',
headers: {
'Metadata-Flavor': 'Google'
}
})
.then(res => {
const token = res.data.access_token;
axios({
method: 'post',
url: `https://www.googleapis.com/compute/v1/projects/${projectID}/zones/${zoneString}/instances?sourceInstanceTemplate=https://www.googleapis.com/compute/v1/projects/${projectID}/global/instanceTemplates/${instanceTemplate}`,
headers: {
'Authorization': `Bearer ${token}`
},
data: {
"name": instanceName
}
})
.then(res => {
console.log(res)
console.log('\n\n')
console.log(res.data)
console.log(`${instanceName} has been created from the ${instanceTemplate}`)
resolve(res.data)
})
.catch(err => {
console.log(err)
reject(err);
})
})
.catch(err => {
console.log(err)
reject(err);
})
});
} |
This is untested, but I believe you can try just this, where const projectID = 'some-project-id';
const instanceTemplate = 'secret-x-project';
vm.request({
method: 'POST',
uri: '',
qs: {
sourceInstanceTemplate: `https://www.googleapis.com/compute/v1/projects/${projectID}/global/instanceTemplates/${instanceTemplate}`
},
json: {
name: instanceName,
}
}, (err, resp) => {
// ...
}); |
google-cloud-label-sync
bot
added
the
api: compute
Issues related to the googleapis/nodejs-compute API.
label
Jan 30, 2020
Any updates, will this ever be implemented? |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
api: compute
Issues related to the googleapis/nodejs-compute API.
type: feature request
‘Nice-to-have’ improvement, new feature or different behavior or design.
Unless I'm misreading the code and docs, it looks like the library doesn't support passing in an instance template when creating a new VM. Any interest in a PR to add it?
The text was updated successfully, but these errors were encountered: