Add in option to report internal IP (--report_internal_ip).
--report_internal_ip will report the internal IP instead of the external
IP. This is needed when someone is connecting to the AVD GCE instance from
another GCE instance.
Note: I ignored pylint duplicate code errors since common_operations,
create_cuttlefish_action, and create_goldfish_action are so similar. The
create work will refactor out the common code into 1 place so it's safe
to ignore for now.
Bug: 113535553
Test: ./run_tests.sh and acloud create
m acloud_test && acloud_test
Change-Id: I6ac840048eb0854f7dcdc223b846826e266b0ad5
diff --git a/internal/lib/gcompute_client.py b/internal/lib/gcompute_client.py
index 6e8a9b0..451cc7f 100755
--- a/internal/lib/gcompute_client.py
+++ b/internal/lib/gcompute_client.py
@@ -26,6 +26,7 @@
generic, and only knows how to talk to Compute Engine APIs.
"""
# pylint: disable=too-many-lines
+import collections
import copy
import functools
import logging
@@ -47,6 +48,8 @@
"initializeParams": {},
}
+IP = collections.namedtuple("IP", ["external", "internal"])
+
class OperationScope(object):
"""Represents operation scope enum."""
@@ -1313,13 +1316,12 @@
zone: String, name of the zone.
Returns:
- string, IP of the instance.
+ NamedTuple of (internal, external) IP of the instance.
"""
- # TODO(fdeng): This is for accessing external IP.
- # We should handle internal IP as well when the script is running
- # on a GCE instance in the same network of |instance|.
instance = self.GetInstance(instance, zone)
- return instance["networkInterfaces"][0]["accessConfigs"][0]["natIP"]
+ internal_ip = instance["networkInterfaces"][0]["networkIP"]
+ external_ip = instance["networkInterfaces"][0]["accessConfigs"][0]["natIP"]
+ return IP(internal=internal_ip, external=external_ip)
def SetCommonInstanceMetadata(self, body):
"""Set project-wide metadata.