Which region is a google cloudshell in?
Asked Answered
C

1

6

Given a google cloudshell, is there a way of finding out which region it is in?

Many thanks, Max

p.s. I know that I can poke around to find the IP address and geolocate it, for example this curl freegeoip.net/xml/$(curl ifconfig.co) claims that the machine is in Vaduz, Liechtenstein. However I would somewhat expect that there is something like an IP address that I can curl to get the cloudconfig and that that would contain the region and availability zone.

Catanzaro answered 1/7, 2018 at 10:16 Comment(0)
G
7

Since Cloud Shell runs as a GCP VM, you can view your assigned region by running

curl -H "Metadata-Flavor: Google" metadata/computeMetadata/v1/instance/zone

inside the Cloud Shell session. This is documented in https://cloud.google.com/compute/docs/storing-retrieving-metadata.

In general, it's worth keeping in mind that Cloud Shell is globally distributed across multiple GCP regions. When a user connects for the first time, the system assigns them to the geographically closest region that can accommodate new users. While the users cannot manually chose their region, the system does its best to pick the closest region Cloud Shell operates in. If Cloud Shell does not initially pick the closest region or if the user later connects from a location that's geographically closer to a different region, Cloud Shell will migrate the user to a closer region on session end.

Gan answered 6/7, 2018 at 0:35 Comment(6)
Awesome. Thanks. Will try it out when I arrive. As long as the region is stable for the one open session, for an hour or so, that is all I need. Whilst possible it seems unlikely that the VM would be put through a live migration in that time.Catanzaro
it would be better to be able to set it... because depending if I start it from the web console or from command line I get different regions.. US or EU...Huei
@Huei that seems odd. Once your disk is homed in a particular region, the VM will always be in the same region unless the system decides to relocate you. Are you sure that you are using the same account and checking inside the Cloud Shell VM (and not some other VM you ssh'd to)?Gan
@Gan you are wrong. If you connect from US the machine will probably be in US.. if you let it expire (30 minutes or so) and then connect to it from europe, the home will be migrated and you will have a european machine.. I did that a few times.Huei
@Gan if you like discussing this further contact me at zibri AT zibri DOT org...Huei
@Huei Yes, that's how it is supposed to work. That's what I meant when I said "unless the system decides to relocate you." The system will relocate your home dir to be closer to you to reduce latency. But it shouldn't matter whether you are connecting from web console or from the command line.Gan

© 2022 - 2024 — McMap. All rights reserved.