You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi guys, I did not find discussion forum or group so I'm asking here.
I have an VM instance in google cloud and I need to create many clones of the instance. So I created snapshot of instance's disk in Google Cloud Console. The console allows to create new instance based on snapshot, but I need to do it via GCloud Java API, how can I do that?
On StackOverflow you can use the gcloud-java tag.
In general to see usage examples for gcloud-java you can have a look at our gcloud-java-examples module.
A detailed example of gcloud-java-compute features can be found in ComputeExample.java.
In CreateAddressDiskAndInstance.java you have an example of how to create an Instance after creating an Address and a Disk. You can follow that example and change the way the disk is created to create it from your Snapshot:
If you are not interested in creating a static address for your instance you can skip that part and create the instance as follows (notice that I remove the code to set the access configurations for the NetworkInterface):
Marco, do you have example for access configuration? I need external ephemeral IP for my VM, but cannot do this.
I found the following example, but it does not work.
I believe that the default network interface for an instance is called nic0 (notice the missing "-"). You can verify this by checking compute.getInstance(instanceId). The following code should work:
Activity
mziccard commentedon May 26, 2016
Hi @ukman,
On StackOverflow you can use the gcloud-java tag.
In general to see usage examples for
gcloud-javayou can have a look at our gcloud-java-examples module.A detailed example of
gcloud-java-computefeatures can be found in ComputeExample.java.In CreateAddressDiskAndInstance.java you have an example of how to create an Instance after creating an Address and a Disk. You can follow that example and change the way the disk is created to create it from your Snapshot:
If you are not interested in creating a static address for your instance you can skip that part and create the instance as follows (notice that I remove the code to set the access configurations for the NetworkInterface):
Hope this helps.
ukman commentedon May 26, 2016
Marco, thanks a lot, it works!
mziccard commentedon May 26, 2016
Glad to here this. Please do not hesitate to contact us if you need help. Bug reports are more than welcome :)
ukman commentedon Jun 2, 2016
Marco, do you have example for access configuration? I need external ephemeral IP for my VM, but cannot do this.
I found the following example, but it does not work.
mziccard commentedon Jun 2, 2016
Hi @ukman,
I believe that the default network interface for an instance is called
nic0(notice the missing "-"). You can verify this by checkingcompute.getInstance(instanceId). The following code should work:Notice that you can also assign an ephemeral address at creation time (to spare one extra RPC call) with something like:
Please let me know if this fixed your issue.
ukman commentedon Jun 2, 2016
It works! Thanks!
ashokreddy2 commentedon Dec 5, 2018
Hi mziccard,
Could you please share code to create google cloud instance using java core code by authenticating google cloud client id and secrect?
If possible pls send complete expample to create vm from image using java code.
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
chore(main): release 3.3.0 (#1025)
feat: Add Agent Assist Summarization API (https://cloud.google.com/ag…
3 remaining items
deps: update dependency com.google.cloud:google-cloud-pubsub to v1.12…
chore(main): release 3.7.6 (googleapis#1029)
deps: update dependency com.google.cloud:google-cloud-core to v2.8.27 (…
chore(main): release 2.9.0 (#1026)
chore(main): release 0.129.7-SNAPSHOT (#1026)
chore(main): release 2.14.2-SNAPSHOT (#1026)
chore(deps): update dependency protobuf to v4 (#1026)
chore(deps): update dependency protobuf to v4 (#1026)
fix(java): initialize classes at build-time to address native image 2…
chore(main): release 2.7.12 (googleapis#1027)
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
docs(sample): Add sample for Native Image support in Pub/Sub (#1026)
docs(sample): Add sample for Native Image support in Pub/Sub (#1026)
chore: change branch master to main (googleapis#1026)