blob: 70c2df49eea41a4033547bb0d896b84b9516c26b [file] [log] [blame]
Kevin Cheng3087af52018-08-13 13:26:50 -07001# Copyright 2018 - The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14r"""Create args.
15
16Defines the create arg parser that holds create specific args.
17"""
18
Kevin Cheng9aeed4d2018-12-18 14:37:34 -080019import argparse
herbertxue36b99f12021-03-25 14:47:28 +080020import logging
herbertxue2625b042018-08-16 23:28:20 +080021import os
22
23from acloud import errors
Sam Chiuc64f3432018-08-17 11:19:06 +080024from acloud.create import create_common
Kevin Cheng3087af52018-08-13 13:26:50 -070025from acloud.internal import constants
herbertxue6ef54a52019-05-02 11:38:58 +080026from acloud.internal.lib import utils
Kevin Cheng3087af52018-08-13 13:26:50 -070027
herbertxue36b99f12021-03-25 14:47:28 +080028logger = logging.getLogger(__name__)
herbertxue93630f52020-03-06 16:06:56 +080029_DEFAULT_GPU = "default"
Kevin Cheng3087af52018-08-13 13:26:50 -070030CMD_CREATE = "create"
31
32
33# TODO: Add this into main create args once create_cf/gf is deprecated.
34def AddCommonCreateArgs(parser):
35 """Adds arguments common to create parsers.
36
37 Args:
38 parser: ArgumentParser object, used to parse flags.
39 """
40 parser.add_argument(
41 "--num",
42 type=int,
43 dest="num",
44 required=False,
45 default=1,
46 help="Number of instances to create.")
47 parser.add_argument(
Sam Chiue669ef72018-10-16 16:23:37 +080048 "--serial-log-file",
Kevin Cheng3087af52018-08-13 13:26:50 -070049 type=str,
50 dest="serial_log_file",
51 required=False,
52 help="Path to a *tar.gz file where serial logs will be saved "
Kevin Cheng86d43c72018-08-30 10:59:14 -070053 "when a device fails on boot.")
Kevin Cheng3087af52018-08-13 13:26:50 -070054 parser.add_argument(
Kevin Cheng3087af52018-08-13 13:26:50 -070055 "--autoconnect",
chojoycee86730a2019-12-11 15:37:58 +080056 type=str,
57 nargs="?",
chojoyce471d3862020-01-16 15:18:12 +080058 const=constants.INS_KEY_VNC,
Kevin Cheng3087af52018-08-13 13:26:50 -070059 dest="autoconnect",
60 required=False,
chojoyce4e2d9222020-01-03 17:04:05 +080061 choices=[constants.INS_KEY_VNC, constants.INS_KEY_ADB,
62 constants.INS_KEY_WEBRTC],
63 help="Determines to establish a tunnel forwarding adb/vnc and "
64 "launch VNC/webrtc. Establish a tunnel forwarding adb and vnc "
65 "then launch vnc if --autoconnect vnc is provided. Establish a "
66 "tunnel forwarding adb if --autoconnect adb is provided. "
67 "Establish a tunnel forwarding adb and auto-launch on the browser "
68 "if --autoconnect webrtc is provided. For local goldfish "
69 "instance, create a window.")
Kevin Cheng4a8f5cf2018-08-15 08:59:28 -070070 parser.add_argument(
71 "--no-autoconnect",
72 action="store_false",
73 dest="autoconnect",
daviddclo53fd8472018-12-27 16:24:06 +080074 required=False,
75 help="Will not automatically create ssh tunnels forwarding adb & vnc "
76 "when instance created.")
chojoyce471d3862020-01-16 15:18:12 +080077 parser.set_defaults(autoconnect=constants.INS_KEY_VNC)
Kevin Cheng86d43c72018-08-30 10:59:14 -070078 parser.add_argument(
chojoycec60fa582019-07-11 16:09:02 +080079 "--unlock",
80 action="store_true",
81 dest="unlock_screen",
82 required=False,
83 default=False,
84 help="This can unlock screen after invoke vnc client.")
85 parser.add_argument(
Sam Chiue669ef72018-10-16 16:23:37 +080086 "--report-internal-ip",
Kevin Cheng86d43c72018-08-30 10:59:14 -070087 action="store_true",
88 dest="report_internal_ip",
89 required=False,
90 help="Report internal ip of the created instance instead of external "
Kevin Cheng1f582bc2018-10-02 10:37:02 -070091 "ip. Using the internal ip is used when connecting from another "
Kevin Cheng86d43c72018-08-30 10:59:14 -070092 "GCE instance.")
Kevin Chengc9424a82018-10-25 11:34:55 -070093 parser.add_argument(
94 "--network",
95 type=str,
96 dest="network",
97 required=False,
98 help="Set the network the GCE instance will utilize.")
Kevin Chengfab8cfc2019-06-27 14:01:37 -070099 parser.add_argument(
100 "--skip-pre-run-check",
101 action="store_true",
102 dest="skip_pre_run_check",
103 required=False,
104 help="Skip the pre-run check.")
cylan6bc90ff2019-07-10 13:40:56 +0800105 parser.add_argument(
106 "--boot-timeout",
107 dest="boot_timeout_secs",
108 type=int,
109 required=False,
110 help="The maximum time in seconds used to wait for the AVD to boot.")
herbertxue23b2a962019-07-24 22:39:20 +0800111 parser.add_argument(
herbertxue40e7efb2019-12-13 11:47:24 +0800112 "--wait-for-ins-stable",
113 dest="ins_timeout_secs",
114 type=int,
115 required=False,
116 help="The maximum time in seconds used to wait for the instance boot "
117 "up. The default value to wait for instance up time is 300 secs.")
118 parser.add_argument(
herbertxuec6f0c262019-07-31 16:59:49 +0800119 "--build-target",
120 type=str,
121 dest="build_target",
122 help="Android build target, e.g. aosp_cf_x86_phone-userdebug, "
123 "or short names: phone, tablet, or tablet_mobile.")
124 parser.add_argument(
125 "--branch",
126 type=str,
127 dest="branch",
128 help="Android branch, e.g. mnc-dev or git_mnc-dev")
129 parser.add_argument(
130 "--build-id",
131 type=str,
132 dest="build_id",
133 help="Android build id, e.g. 2145099, P2804227")
134 parser.add_argument(
herbertxuee659d152020-10-15 18:52:06 +0800135 "--bootloader-branch",
136 type=str,
137 dest="bootloader_branch",
138 help="'cuttlefish only' Branch to consume the bootloader from.",
139 required=False)
140 parser.add_argument(
141 "--bootloader-build-id",
142 type=str,
143 dest="bootloader_build_id",
144 help="'cuttlefish only' Bootloader build id, e.g. P2804227",
145 required=False)
146 parser.add_argument(
147 "--bootloader-build-target",
148 type=str,
149 dest="bootloader_build_target",
150 help="'cuttlefish only' Bootloader build target.",
151 required=False)
152 parser.add_argument(
herbertxuec6f0c262019-07-31 16:59:49 +0800153 "--kernel-build-id",
154 type=str,
155 dest="kernel_build_id",
156 required=False,
157 help="Android kernel build id, e.g. 4586590. This is to test a new"
herbertxue03eb5d72019-09-10 14:52:10 +0800158 " kernel build with a particular Android build (--build-id). If neither"
159 " kernel-branch nor kernel-build-id are specified, the kernel that's"
herbertxuec6f0c262019-07-31 16:59:49 +0800160 " bundled with the Android build would be used.")
161 parser.add_argument(
162 "--kernel-branch",
163 type=str,
164 dest="kernel_branch",
165 required=False,
166 help="Android kernel build branch name, e.g."
167 " kernel-common-android-4.14. This is to test a new kernel build with a"
168 " particular Android build (--build-id). If specified without"
herbertxue03eb5d72019-09-10 14:52:10 +0800169 " specifying kernel-build-id, the last green build in the branch will"
170 " be used. If neither kernel-branch nor kernel-build-id are specified,"
herbertxuec6f0c262019-07-31 16:59:49 +0800171 " the kernel that's bundled with the Android build would be used.")
172 parser.add_argument(
173 "--kernel-build-target",
174 type=str,
175 dest="kernel_build_target",
176 default="kernel",
177 help="Kernel build target, specify if different from 'kernel'")
178 parser.add_argument(
herbertxue23b2a962019-07-24 22:39:20 +0800179 "--system-branch",
180 type=str,
181 dest="system_branch",
182 help="'cuttlefish only' Branch to consume the system image (system.img) "
183 "from, will default to what is defined by --branch. "
184 "That feature allows to (automatically) test various combinations "
185 "of vendor.img (CF, e.g.) and system images (GSI, e.g.). ",
186 required=False)
187 parser.add_argument(
188 "--system-build-id",
189 type=str,
190 dest="system_build_id",
191 help="'cuttlefish only' System image build id, e.g. 2145099, P2804227",
192 required=False)
193 parser.add_argument(
194 "--system-build-target",
195 type=str,
196 dest="system_build_target",
197 help="'cuttlefish only' System image build target, specify if different "
herbertxue03eb5d72019-09-10 14:52:10 +0800198 "from --build-target",
herbertxue23b2a962019-07-24 22:39:20 +0800199 required=False)
herbertxueda2619b2019-12-06 12:09:47 +0800200 # TODO(146314062): Remove --multi-stage-launch after infra don't use this
201 # args.
Cody Schuffelen102b3b52019-07-17 10:26:35 -0700202 parser.add_argument(
203 "--multi-stage-launch",
204 dest="multi_stage_launch",
herbertxue6e546122020-01-06 23:35:25 +0800205 action="store_true",
Cody Schuffelen102b3b52019-07-17 10:26:35 -0700206 required=False,
herbertxueda2619b2019-12-06 12:09:47 +0800207 default=True,
Cody Schuffelen102b3b52019-07-17 10:26:35 -0700208 help="Enable the multi-stage cuttlefish launch.")
209 parser.add_argument(
210 "--no-multi-stage-launch",
211 dest="multi_stage_launch",
herbertxue6e546122020-01-06 23:35:25 +0800212 action="store_false",
Cody Schuffelen102b3b52019-07-17 10:26:35 -0700213 required=False,
214 default=None,
215 help="Disable the multi-stage cuttlefish launch.")
herbertxue6e546122020-01-06 23:35:25 +0800216 parser.add_argument(
217 "--no-pull-log",
218 dest="no_pull_log",
219 action="store_true",
220 required=False,
221 default=None,
222 help="Disable auto download logs when AVD booting up failed.")
herbertxue9a651d62020-01-08 21:58:34 +0800223 # TODO(147335651): Add gpu in user config.
224 # TODO(147335651): Support "--gpu" without giving any value.
225 parser.add_argument(
226 "--gpu",
227 type=str,
herbertxue93630f52020-03-06 16:06:56 +0800228 const=_DEFAULT_GPU,
229 nargs="?",
herbertxue9a651d62020-01-08 21:58:34 +0800230 dest="gpu",
231 required=False,
232 default=None,
herbertxue93630f52020-03-06 16:06:56 +0800233 help="GPU accelerator to use if any. e.g. nvidia-tesla-k80. For local "
234 "instances, this arg without assigning any value is to enable "
235 "local gpu support.")
herbertxueffbcbc22020-07-07 14:35:34 +0800236 # Hide following args for users, it is only used in infra.
herbertxue408dba82020-03-19 19:23:32 +0800237 parser.add_argument(
Hsin-Yi Chene0bc5392020-09-08 00:48:43 +0800238 "--local-instance-dir",
239 dest="local_instance_dir",
240 required=False,
241 help=argparse.SUPPRESS)
242 parser.add_argument(
herbertxue408dba82020-03-19 19:23:32 +0800243 "--num-avds-per-instance",
244 type=int,
245 dest="num_avds_per_instance",
246 required=False,
247 default=1,
248 help=argparse.SUPPRESS)
herbertxueffbcbc22020-07-07 14:35:34 +0800249 parser.add_argument(
250 "--zone",
251 type=str,
252 dest="zone",
253 required=False,
254 help=argparse.SUPPRESS)
Kevin Cheng3087af52018-08-13 13:26:50 -0700255
Kevin Cheng85a20f62018-10-25 11:53:11 -0700256 # TODO(b/118439885): Old arg formats to support transition, delete when
257 # transistion is done.
258 parser.add_argument(
259 "--serial_log_file",
260 type=str,
261 dest="serial_log_file",
262 required=False,
Kevin Cheng9aeed4d2018-12-18 14:37:34 -0800263 help=argparse.SUPPRESS)
Kevin Cheng85a20f62018-10-25 11:53:11 -0700264 parser.add_argument(
Richard Fung97503b22019-02-06 13:43:38 -0800265 "--build_id",
266 type=str,
267 dest="build_id",
268 required=False,
269 help=argparse.SUPPRESS)
270 parser.add_argument(
271 "--build_target",
272 type=str,
273 dest="build_target",
274 required=False,
275 help=argparse.SUPPRESS)
herbertxue23b2a962019-07-24 22:39:20 +0800276 parser.add_argument(
277 "--system_branch",
278 type=str,
279 dest="system_branch",
280 required=False,
281 help=argparse.SUPPRESS)
282 parser.add_argument(
283 "--system_build_id",
284 type=str,
285 dest="system_build_id",
286 required=False,
287 help=argparse.SUPPRESS)
288 parser.add_argument(
289 "--system_build_target",
290 type=str,
291 dest="system_build_target",
292 required=False,
293 help=argparse.SUPPRESS)
herbertxuec6f0c262019-07-31 16:59:49 +0800294 parser.add_argument(
295 "--kernel_build_id",
296 type=str,
297 dest="kernel_build_id",
298 required=False,
299 help=argparse.SUPPRESS)
300 parser.add_argument(
301 "--kernel_branch",
302 type=str,
303 dest="kernel_branch",
304 required=False,
305 help=argparse.SUPPRESS)
306 parser.add_argument(
307 "--kernel_build_target",
308 type=str,
309 dest="kernel_build_target",
310 default="kernel",
311 help=argparse.SUPPRESS)
herbertxuee659d152020-10-15 18:52:06 +0800312 parser.add_argument(
313 "--bootloader_branch",
314 type=str,
315 dest="bootloader_branch",
316 help=argparse.SUPPRESS,
317 required=False)
318 parser.add_argument(
319 "--bootloader_build_id",
320 type=str,
321 dest="bootloader_build_id",
322 help=argparse.SUPPRESS,
323 required=False)
324 parser.add_argument(
325 "--bootloader_build_target",
326 type=str,
327 dest="bootloader_build_target",
328 help=argparse.SUPPRESS,
329 required=False)
Kevin Cheng85a20f62018-10-25 11:53:11 -0700330
Kevin Cheng3087af52018-08-13 13:26:50 -0700331
332def GetCreateArgParser(subparser):
333 """Return the create arg parser.
334
335 Args:
336 subparser: argparse.ArgumentParser that is attached to main acloud cmd.
337
338 Returns:
339 argparse.ArgumentParser with create options defined.
340 """
341 create_parser = subparser.add_parser(CMD_CREATE)
342 create_parser.required = False
343 create_parser.set_defaults(which=CMD_CREATE)
Hsin-Yi Chencaec52f2020-07-16 14:59:26 +0800344 # Use default=None to distinguish remote instance or local. The instance
345 # type will be remote if the arg is not provided.
Kevin Cheng3087af52018-08-13 13:26:50 -0700346 create_parser.add_argument(
Sam Chiue669ef72018-10-16 16:23:37 +0800347 "--local-instance",
Hsin-Yi Chencaec52f2020-07-16 14:59:26 +0800348 type=_PositiveInteger,
349 const=0,
350 metavar="ID",
Sam Chiu59120542019-08-15 09:32:32 +0800351 nargs="?",
cylanabe0a3a2018-08-16 18:50:09 +0800352 dest="local_instance",
353 required=False,
Hsin-Yi Chencaec52f2020-07-16 14:59:26 +0800354 help="Create a local AVD instance using the resources associated with "
355 "the ID. Choose an unused ID automatically if the value is "
356 "not specified (primarily for infra usage).")
cylanabe0a3a2018-08-16 18:50:09 +0800357 create_parser.add_argument(
herbertxue6ef54a52019-05-02 11:38:58 +0800358 "--adb-port", "-p",
359 type=int,
360 default=None,
361 dest="adb_port",
362 required=False,
363 help="Specify port for adb forwarding.")
364 create_parser.add_argument(
Sam Chiue669ef72018-10-16 16:23:37 +0800365 "--avd-type",
Kevin Cheng3087af52018-08-13 13:26:50 -0700366 type=str,
367 dest="avd_type",
368 default=constants.TYPE_CF,
Peter Collingbournedce6d722020-05-07 15:29:21 -0700369 choices=[constants.TYPE_GCE, constants.TYPE_CF, constants.TYPE_GF, constants.TYPE_CHEEPS,
370 constants.TYPE_FVP],
Kevin Cheng3087af52018-08-13 13:26:50 -0700371 help="Android Virtual Device type (default %s)." % constants.TYPE_CF)
372 create_parser.add_argument(
herbertxue60d70c92021-03-31 20:56:37 +0800373 "--config", "--flavor",
cylanabe0a3a2018-08-16 18:50:09 +0800374 type=str,
375 dest="flavor",
herbertxue60d70c92021-03-31 20:56:37 +0800376 help="The device flavor of the AVD (default %s). e.g. phone, tv, foldable."
377 % constants.FLAVOR_PHONE)
cylanabe0a3a2018-08-16 18:50:09 +0800378 create_parser.add_argument(
Sam Chiue669ef72018-10-16 16:23:37 +0800379 "--local-image",
Hsin-Yi Chenc1f69642020-12-28 12:44:43 +0800380 const=constants.FIND_IN_BUILD_ENV,
herbertxue2625b042018-08-16 23:28:20 +0800381 type=str,
382 dest="local_image",
383 nargs="?",
herbertxue2625b042018-08-16 23:28:20 +0800384 required=False,
Kevin Cheng01b58bd2018-10-17 16:03:10 -0700385 help="Use the locally built image for the AVD. Look for the image "
Sam Chiu96172ae2019-01-31 14:30:30 +0800386 "artifact in $ANDROID_PRODUCT_OUT if no args value is provided."
387 "e.g --local-image or --local-image /path/to/dir or --local-image "
388 "/path/to/file")
chojoycef23e7d52018-10-15 17:36:35 +0800389 create_parser.add_argument(
Hsin-Yi Chen2a609332019-10-07 19:39:52 +0800390 "--local-system-image",
Hsin-Yi Chenc1f69642020-12-28 12:44:43 +0800391 const=constants.FIND_IN_BUILD_ENV,
Hsin-Yi Chen2a609332019-10-07 19:39:52 +0800392 type=str,
393 dest="local_system_image",
394 nargs="?",
Hsin-Yi Chen2a609332019-10-07 19:39:52 +0800395 required=False,
396 help="Use the locally built system images for the AVD. Look for the "
397 "images in $ANDROID_PRODUCT_OUT if no args value is provided. "
398 "e.g., --local-system-image or --local-system-image /path/to/dir")
399 create_parser.add_argument(
Hsin-Yi Chene76c1bf2019-12-23 15:15:47 +0800400 "--local-tool",
401 type=str,
402 dest="local_tool",
403 action="append",
404 default=[],
405 required=False,
406 help="Use the tools in the specified directory to create local "
407 "instances. The directory structure follows $ANDROID_HOST_OUT or "
408 "$ANDROID_EMULATOR_PREBUILTS.")
409 create_parser.add_argument(
chojoycef23e7d52018-10-15 17:36:35 +0800410 "--image-download-dir",
411 type=str,
412 dest="image_download_dir",
413 required=False,
414 help="Define remote image download directory, e.g. /usr/local/dl.")
herbertxue7ef23b22019-02-27 09:34:24 +0800415 create_parser.add_argument(
416 "--yes", "-y",
417 action="store_true",
418 dest="no_prompt",
419 required=False,
420 help=("Automatic yes to prompts. Assume 'yes' as answer to all prompts "
421 "and run non-interactively."))
cylan2d633512019-09-09 20:33:42 +0800422 create_parser.add_argument(
423 "--reuse-gce",
424 type=str,
425 const=constants.SELECT_ONE_GCE_INSTANCE,
426 nargs="?",
427 dest="reuse_gce",
428 required=False,
429 help="'cuttlefish only' This can help users use their own instance. "
430 "Reusing specific gce instance if --reuse-gce [instance_name] is "
431 "provided. Select one gce instance to reuse if --reuse-gce is "
432 "provided.")
cyland43f2932019-11-26 17:37:28 +0800433 create_parser.add_argument(
herbertxuec58d2812021-01-21 15:02:27 +0800434 "--gce-metadata",
435 type=str,
436 dest="gce_metadata",
437 default=None,
438 help="'GCE instance only' Record data into GCE instance metadata with "
439 "key-value pair format. e.g. id:12,name:unknown.")
440 create_parser.add_argument(
cyland43f2932019-11-26 17:37:28 +0800441 "--host",
442 type=str,
443 dest="remote_host",
444 default=None,
cylan0f61af62019-12-30 22:31:10 +0800445 help="'cuttlefish only' Provide host name to clean up the remote host. "
446 "For example: '--host 1.1.1.1'")
cyland43f2932019-11-26 17:37:28 +0800447 create_parser.add_argument(
448 "--host-user",
449 type=str,
450 dest="host_user",
cylan0f61af62019-12-30 22:31:10 +0800451 default=constants.GCE_USER,
452 help="'remote host only' Provide host user for logging in to the host. "
453 "The default value is vsoc-01. For example: '--host 1.1.1.1 --host-user "
454 "vsoc-02'")
cyland43f2932019-11-26 17:37:28 +0800455 create_parser.add_argument(
456 "--host-ssh-private-key-path",
457 type=str,
458 dest="host_ssh_private_key_path",
459 default=None,
460 help="'remote host only' Provide host key for login on on this host.")
Sam Chiuc64f3432018-08-17 11:19:06 +0800461 # User should not specify --spec and --hw_property at the same time.
462 hw_spec_group = create_parser.add_mutually_exclusive_group()
463 hw_spec_group.add_argument(
Sam Chiue669ef72018-10-16 16:23:37 +0800464 "--hw-property",
Sam Chiuc64f3432018-08-17 11:19:06 +0800465 type=str,
466 dest="hw_property",
467 required=False,
468 help="Supported HW properties and example values: %s" %
469 constants.HW_PROPERTIES_CMD_EXAMPLE)
470 hw_spec_group.add_argument(
471 "--spec",
472 type=str,
473 dest="spec",
474 required=False,
475 choices=constants.SPEC_NAMES,
476 help="The name of a pre-configured device spec that we are "
477 "going to use.")
herbertxue494891e2019-01-19 13:50:53 +0800478 # Arguments for goldfish type.
479 # TODO(b/118439885): Verify args that are used in wrong avd_type.
480 # e.g. $acloud create --avd-type cuttlefish --emulator-build-id
481 create_parser.add_argument(
herbertxue494891e2019-01-19 13:50:53 +0800482 "--emulator-build-id",
483 type=int,
484 dest="emulator_build_id",
485 required=False,
486 help="'goldfish only' Emulator build used to run the images. "
487 "e.g. 4669466.")
Kevin Cheng3087af52018-08-13 13:26:50 -0700488
Richard Fung8d3979e2019-06-12 16:00:34 -0700489 # Arguments for cheeps type.
490 create_parser.add_argument(
Shao-Chuan Lee80244112020-02-04 17:14:07 +0900491 "--stable-cheeps-host-image-name",
492 type=str,
493 dest="stable_cheeps_host_image_name",
494 required=False,
495 default=None,
496 help=("'cheeps only' The Cheeps host image from which instances are "
497 "launched. If specified here, the value set in Acloud config "
498 "file will be overridden."))
499 create_parser.add_argument(
500 "--stable-cheeps-host-image-project",
501 type=str,
502 dest="stable_cheeps_host_image_project",
503 required=False,
504 default=None,
505 help=("'cheeps only' The project hosting the specified Cheeps host "
506 "image. If specified here, the value set in Acloud config file "
507 "will be overridden."))
508 create_parser.add_argument(
Richard Fung8d3979e2019-06-12 16:00:34 -0700509 "--user",
510 type=str,
511 dest="username",
512 required=False,
513 default=None,
514 help="'cheeps only' username to log in to Chrome OS as.")
515 create_parser.add_argument(
516 "--password",
517 type=str,
518 dest="password",
519 required=False,
520 default=None,
521 help="'cheeps only' password to log in to Chrome OS with.")
Richard Fungd7d57f42020-04-09 12:58:49 -0700522 create_parser.add_argument(
523 "--betty-image",
524 type=str,
525 dest="cheeps_betty_image",
526 required=False,
527 default=None,
528 help=("'cheeps only' The L1 betty version to use. Only makes sense "
529 "when launching a controller image with "
530 "stable-cheeps-host-image"))
Richard Fung8d3979e2019-06-12 16:00:34 -0700531
Kevin Cheng3087af52018-08-13 13:26:50 -0700532 AddCommonCreateArgs(create_parser)
533 return create_parser
herbertxue2625b042018-08-16 23:28:20 +0800534
535
Hsin-Yi Chencaec52f2020-07-16 14:59:26 +0800536def _PositiveInteger(arg):
537 """Convert an argument from a string to a positive integer."""
538 try:
539 value = int(arg)
Hsin-Yi Chenc1f69642020-12-28 12:44:43 +0800540 except ValueError as e:
541 raise argparse.ArgumentTypeError(arg + " is not an integer.") from e
Hsin-Yi Chencaec52f2020-07-16 14:59:26 +0800542 if value <= 0:
543 raise argparse.ArgumentTypeError(arg + " is not positive.")
544 return value
545
546
Hsin-Yi Chen2a609332019-10-07 19:39:52 +0800547def _VerifyLocalArgs(args):
548 """Verify args starting with --local.
549
550 Args:
551 args: Namespace object from argparse.parse_args.
552
553 Raises:
554 errors.CheckPathError: Image path doesn't exist.
555 errors.UnsupportedCreateArgs: The specified avd type does not support
556 --local-system-image.
557 errors.UnsupportedLocalInstanceId: Local instance ID is invalid.
558 """
559 if args.local_image and not os.path.exists(args.local_image):
560 raise errors.CheckPathError(
561 "Specified path doesn't exist: %s" % args.local_image)
562
Hsin-Yi Chene0bc5392020-09-08 00:48:43 +0800563 if args.local_instance_dir and not os.path.exists(args.local_instance_dir):
564 raise errors.CheckPathError(
565 "Specified path doesn't exist: %s" % args.local_instance_dir)
566
Hsin-Yi Chenc1f69642020-12-28 12:44:43 +0800567 if not (args.local_system_image is None or
Hsin-Yi Chen19d665c2020-12-28 18:13:22 +0800568 args.avd_type in (constants.TYPE_CF, constants.TYPE_GF)):
Hsin-Yi Chen2a609332019-10-07 19:39:52 +0800569 raise errors.UnsupportedCreateArgs("%s instance does not support "
570 "--local-system-image" %
571 args.avd_type)
572
573 if (args.local_system_image and
574 not os.path.exists(args.local_system_image)):
575 raise errors.CheckPathError(
576 "Specified path doesn't exist: %s" % args.local_system_image)
577
Hsin-Yi Chene76c1bf2019-12-23 15:15:47 +0800578 for tool_dir in args.local_tool:
579 if not os.path.exists(tool_dir):
580 raise errors.CheckPathError(
581 "Specified path doesn't exist: %s" % tool_dir)
582
chojoyce4e2d9222020-01-03 17:04:05 +0800583 if args.autoconnect == constants.INS_KEY_WEBRTC:
584 if args.avd_type != constants.TYPE_CF:
585 raise errors.UnsupportedCreateArgs(
586 "'--autoconnect webrtc' only support cuttlefish.")
587
Hsin-Yi Chen2a609332019-10-07 19:39:52 +0800588
cyland43f2932019-11-26 17:37:28 +0800589def _VerifyHostArgs(args):
590 """Verify args starting with --host.
591
592 Args:
593 args: Namespace object from argparse.parse_args.
594
595 Raises:
596 errors.UnsupportedCreateArgs: When a create arg is specified but
597 unsupported for remote host mode.
598 """
599 if args.remote_host and args.local_instance is not None:
600 raise errors.UnsupportedCreateArgs(
601 "--host is not supported for local instance.")
602
603 if args.remote_host and args.num > 1:
604 raise errors.UnsupportedCreateArgs(
605 "--num is not supported for remote host.")
606
cylan30ab4d62020-01-06 14:01:09 +0800607 if args.host_user != constants.GCE_USER and args.remote_host is None:
cyland43f2932019-11-26 17:37:28 +0800608 raise errors.UnsupportedCreateArgs(
609 "--host-user only support for remote host.")
610
611 if args.host_ssh_private_key_path and args.remote_host is None:
612 raise errors.UnsupportedCreateArgs(
613 "--host-ssh-private-key-path only support for remote host.")
614
615
herbertxue2625b042018-08-16 23:28:20 +0800616def VerifyArgs(args):
617 """Verify args.
618
619 Args:
620 args: Namespace object from argparse.parse_args.
621
622 Raises:
herbertxue6ef54a52019-05-02 11:38:58 +0800623 errors.UnsupportedMultiAdbPort: multi adb port doesn't support.
herbertxue23b2a962019-07-24 22:39:20 +0800624 errors.UnsupportedCreateArgs: When a create arg is specified but
625 unsupported for a particular avd type.
626 (e.g. --system-build-id for gf)
herbertxue2625b042018-08-16 23:28:20 +0800627 """
herbertxuefd15dfd2018-12-04 11:26:27 +0800628 # Verify that user specified flavor name is in support list.
629 # We don't use argparse's builtin validation because we need to be able to
630 # tell when a user doesn't specify a flavor.
631 if args.flavor and args.flavor not in constants.ALL_FLAVORS:
herbertxue36b99f12021-03-25 14:47:28 +0800632 logger.debug("Flavor[%s] isn't in default support list: %s",
633 args.flavor, constants.ALL_FLAVORS)
634
herbertxue23b2a962019-07-24 22:39:20 +0800635 if args.avd_type != constants.TYPE_CF:
636 if args.system_branch or args.system_build_id or args.system_build_target:
637 raise errors.UnsupportedCreateArgs(
638 "--system-* args are not supported for AVD type: %s"
639 % args.avd_type)
herbertxuefd15dfd2018-12-04 11:26:27 +0800640
herbertxue6ef54a52019-05-02 11:38:58 +0800641 if args.num > 1 and args.adb_port:
642 raise errors.UnsupportedMultiAdbPort(
643 "--adb-port is not supported for multi-devices.")
644
herbertxue755ad482019-11-21 11:31:29 +0800645 if args.num > 1 and args.local_instance is not None:
646 raise errors.UnsupportedCreateArgs(
647 "--num is not supported for local instance.")
648
herbertxue93630f52020-03-06 16:06:56 +0800649 if args.local_instance is None and args.gpu == _DEFAULT_GPU:
650 raise errors.UnsupportedCreateArgs(
651 "Please assign one gpu model for GCE instance. Reference: "
652 "https://cloud.google.com/compute/docs/gpus")
653
herbertxue6ef54a52019-05-02 11:38:58 +0800654 if args.adb_port:
655 utils.CheckPortFree(args.adb_port)
656
herbertxuec58d2812021-01-21 15:02:27 +0800657 hw_properties = create_common.ParseKeyValuePairArgs(args.hw_property)
Sam Chiuc64f3432018-08-17 11:19:06 +0800658 for key in hw_properties:
659 if key not in constants.HW_PROPERTIES:
660 raise errors.InvalidHWPropertyError(
661 "[%s] is an invalid hw property, supported values are:%s. "
662 % (key, constants.HW_PROPERTIES))
Richard Fung8d3979e2019-06-12 16:00:34 -0700663
Richard Fungd7d57f42020-04-09 12:58:49 -0700664 cheeps_only_flags = [args.stable_cheeps_host_image_name,
665 args.stable_cheeps_host_image_project,
666 args.username,
667 args.password,
668 args.cheeps_betty_image]
669 if args.avd_type != constants.TYPE_CHEEPS and any(cheeps_only_flags):
Shao-Chuan Lee80244112020-02-04 17:14:07 +0900670 raise errors.UnsupportedCreateArgs(
Richard Fungd7d57f42020-04-09 12:58:49 -0700671 "--stable-cheeps-*, --betty-image, --username and --password are "
672 "only valid with avd_type == %s" % constants.TYPE_CHEEPS)
Richard Fung8d3979e2019-06-12 16:00:34 -0700673 if (args.username or args.password) and not (args.username and args.password):
674 raise ValueError("--username and --password must both be set")
chojoycec60fa582019-07-11 16:09:02 +0800675 if not args.autoconnect and args.unlock_screen:
676 raise ValueError("--no-autoconnect and --unlock couldn't be "
677 "passed in together.")
Sam Chiu59120542019-08-15 09:32:32 +0800678
Hsin-Yi Chen2a609332019-10-07 19:39:52 +0800679 _VerifyLocalArgs(args)
cyland43f2932019-11-26 17:37:28 +0800680 _VerifyHostArgs(args)