Get and Set common instance metadata via API

101 views
Skip to first unread message

Electrosis Music

unread,
Sep 22, 2017, 6:42:06 PM9/22/17
to Google Cloud Developers
Hello all,

I need to be able to read and set values in the common instance metadata that is shared by all instances using the java API. I can already easily set this in a browser, but I need to be able to do it via API.


Would I need to download another API library for this, or can this be done with the API above?

Also, I've tried java code below, but it seems to clear all metadata entries and doesn't replace them with new ones. Also, there doesn't seem to be a way to read the metadata values from API. 

Metadata m = new Metadata();

m.put("test", "1");

computeClient.projects().setCommonInstanceMetadata(projectID, m).buildHttpRequest();


Any help you can offer would be appreciated.


nau...@google.com

unread,
Sep 22, 2017, 7:49:30 PM9/22/17
to Google Cloud Developers
Hello, 

You can use the JAVA API as given in this setMetadata method example to set the instance metadata [1]. You can find the JAVA client library it uses here in this link [2].

To read the instance metadata, you can use "Instances: get" [3] method API along with the specified Instance resources. 

[1] https://cloud.google.com/compute/docs/reference/latest/instances/setMetadata
[2] https://developers.google.com/api-client-library/java/apis/compute/v1
[3] https://cloud.google.com/compute/docs/reference/beta/instances/get
Reply all
Reply to author
Forward
0 new messages