Skip to content

Simpler Metadata querying from inside the VM #1115

@lorennorman

Description

@lorennorman

Hello!

I would like to use gcloud-node on a VM to fetch its Metadata. I expected this to be simple, since the CLI way of grabbing the Metadata is a simple CURL to a magic URL. My expectation would be that gcloud-node wraps that nicely for me already. Unfortunately, this is not the case.

Instead, the docs say:

var gcloud = require('gcloud')({
  keyFilename: '/path/to/keyfile.json',
  projectId: 'grape-spaceship-123'
});

var gce = gcloud.compute();

var zone = gce.zone('zone-name');

var vm = zone.vm('vm-name');

var metadata = vm.getMetadata(); // Finally!

Whoa, whoa, whoa, I'm already on the VM in question, do I really need to know Project ID, Zone, and VM Name just to get back to square one?

How about some kind of factory method for grabbing the current VM, such as:

var vm = gcloud.getCurrentVM();

...that does whatever magic is needed to figure out where it is running? (Or even better maybe just getLocalMetadata()?)

Just a friendly suggestion! I spent a day trying to figure out "the right way" to do this and I am ultimately falling back to the HTTP method, wanted to put this here in case it is helpful for someone else or adds some usability to the project.

Thank you!

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions