Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Support for instance templates when creating a new compute engine instance #114

Closed
gcooney opened this issue Jun 25, 2018 · 6 comments · Fixed by #500
Closed

Support for instance templates when creating a new compute engine instance #114

gcooney opened this issue Jun 25, 2018 · 6 comments · Fixed by #500
Assignees
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

@gcooney
Copy link

gcooney commented Jun 25, 2018

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?

@JustinBeckwith 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
@JamesTheTerry
Copy link

I would very much like this feature as well.

@stephenplusplus
Copy link
Contributor

Yes, a PR would be great!

@edgarmarkosov
Copy link

When this will be available? Is there any other way to create instance from the instance template?

@JamesTheTerry
Copy link

JamesTheTerry commented Jul 12, 2018

@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);
    })
  });
}

@stephenplusplus
Copy link
Contributor

This is untested, but I believe you can try just this, where vm is our library's "VM" object:

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 google-cloud-label-sync bot added the api: compute Issues related to the googleapis/nodejs-compute API. label Jan 30, 2020
@Alw3ys
Copy link
Contributor

Alw3ys commented Sep 25, 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants