Merge "[LSC] Add LOCAL_LICENSE_KINDS to tools/acloud"
diff --git a/create/avd_spec.py b/create/avd_spec.py
index 794446e..af61f4b 100644
--- a/create/avd_spec.py
+++ b/create/avd_spec.py
@@ -125,6 +125,7 @@
         self._bootloader_build_info = None
         self._hw_property = None
         self._remote_host = None
+        self._gce_metadata = None
         self._host_user = None
         self._host_ssh_private_key_path = None
         # Create config instance for android_build_client to query build api.
@@ -230,7 +231,7 @@
         Raises:
             error.MalformedHWPropertyError: If hw_property_str is malformed.
         """
-        hw_dict = create_common.ParseHWPropertyArgs(hw_property_str)
+        hw_dict = create_common.ParseKeyValuePairArgs(hw_property_str)
         arg_hw_properties = {}
         for key, value in hw_dict.items():
             # Parsing HW properties int to avdspec.
@@ -317,6 +318,7 @@
         self._serial_log_file = args.serial_log_file
         self._emulator_build_id = args.emulator_build_id
         self._gpu = args.gpu
+        self._gce_metadata = create_common.ParseKeyValuePairArgs(args.gce_metadata)
 
         self._stable_cheeps_host_image_name = args.stable_cheeps_host_image_name
         self._stable_cheeps_host_image_project = args.stable_cheeps_host_image_project
@@ -908,3 +910,8 @@
     def no_pull_log(self):
         """Return no_pull_log."""
         return self._no_pull_log
+
+    @property
+    def gce_metadata(self):
+        """Return gce_metadata."""
+        return self._gce_metadata
diff --git a/create/create_args.py b/create/create_args.py
index 40cf44e..ac359a9 100644
--- a/create/create_args.py
+++ b/create/create_args.py
@@ -429,6 +429,13 @@
         "provided. Select one gce instance to reuse if --reuse-gce is "
         "provided.")
     create_parser.add_argument(
+        "--gce-metadata",
+        type=str,
+        dest="gce_metadata",
+        default=None,
+        help="'GCE instance only' Record data into GCE instance metadata with "
+        "key-value pair format. e.g. id:12,name:unknown.")
+    create_parser.add_argument(
         "--host",
         type=str,
         dest="remote_host",
@@ -646,7 +653,7 @@
     if args.adb_port:
         utils.CheckPortFree(args.adb_port)
 
-    hw_properties = create_common.ParseHWPropertyArgs(args.hw_property)
+    hw_properties = create_common.ParseKeyValuePairArgs(args.hw_property)
     for key in hw_properties:
         if key not in constants.HW_PROPERTIES:
             raise errors.InvalidHWPropertyError(
diff --git a/create/create_common.py b/create/create_common.py
index ff56965..e18e58b 100644
--- a/create/create_common.py
+++ b/create/create_common.py
@@ -29,7 +29,7 @@
 logger = logging.getLogger(__name__)
 
 
-def ParseHWPropertyArgs(dict_str, item_separator=",", key_value_separator=":"):
+def ParseKeyValuePairArgs(dict_str, item_separator=",", key_value_separator=":"):
     """Helper function to initialize a dict object from string.
 
     e.g.
@@ -47,9 +47,9 @@
     Raises:
         error.MalformedDictStringError: If dict_str is malformed.
     """
-    hw_dict = {}
+    args_dict = {}
     if not dict_str:
-        return hw_dict
+        return args_dict
 
     for item in dict_str.split(item_separator):
         if key_value_separator not in item:
@@ -59,9 +59,9 @@
         if not value or not key:
             raise errors.MalformedDictStringError(
                 "Missing key or value in %s, expecting form of 'a:b'" % item)
-        hw_dict[key.strip()] = value.strip()
+        args_dict[key.strip()] = value.strip()
 
-    return hw_dict
+    return args_dict
 
 
 def GetCvdHostPackage():
diff --git a/create/create_common_test.py b/create/create_common_test.py
index a18f561..0cfaea7 100644
--- a/create/create_common_test.py
+++ b/create/create_common_test.py
@@ -48,23 +48,23 @@
 
     # pylint: disable=protected-access
     def testProcessHWPropertyWithInvalidArgs(self):
-        """Test ParseHWPropertyArgs with invalid args."""
+        """Test ParseKeyValuePairArgs with invalid args."""
         # Checking wrong property value.
         args_str = "cpu:3,disk:"
         with self.assertRaises(errors.MalformedDictStringError):
-            create_common.ParseHWPropertyArgs(args_str)
+            create_common.ParseKeyValuePairArgs(args_str)
 
         # Checking wrong property format.
         args_str = "cpu:3,disk"
         with self.assertRaises(errors.MalformedDictStringError):
-            create_common.ParseHWPropertyArgs(args_str)
+            create_common.ParseKeyValuePairArgs(args_str)
 
     def testParseHWPropertyStr(self):
-        """Test ParseHWPropertyArgs."""
+        """Test ParseKeyValuePairArgs."""
         expected_dict = {"cpu": "2", "resolution": "1080x1920", "dpi": "240",
                          "memory": "4g", "disk": "4g"}
         args_str = "cpu:2,resolution:1080x1920,dpi:240,memory:4g,disk:4g"
-        result_dict = create_common.ParseHWPropertyArgs(args_str)
+        result_dict = create_common.ParseKeyValuePairArgs(args_str)
         self.assertTrue(expected_dict == result_dict)
 
     def testGetCvdHostPackage(self):
diff --git a/internal/lib/cvd_compute_client_multi_stage.py b/internal/lib/cvd_compute_client_multi_stage.py
index 4b3f6cf..3a79bac 100644
--- a/internal/lib/cvd_compute_client_multi_stage.py
+++ b/internal/lib/cvd_compute_client_multi_stage.py
@@ -480,6 +480,9 @@
                 avd_spec.hw_property[constants.HW_X_RES],
                 avd_spec.hw_property[constants.HW_Y_RES],
                 avd_spec.hw_property[constants.HW_ALIAS_DPI]))
+            if avd_spec.gce_metadata:
+                for key, value in avd_spec.gce_metadata.items():
+                    metadata[key] = value
 
         disk_args = self._GetDiskArgs(
             instance, image_name, image_project, boot_disk_size_gb)