blob: 671556c57e21d71c1ace8edba0b19baf8f6ee6de [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
herbertxue2625b042018-08-16 23:28:20 +080020import os
21
22from acloud import errors
Sam Chiuc64f3432018-08-17 11:19:06 +080023from acloud.create import create_common
Kevin Cheng3087af52018-08-13 13:26:50 -070024from acloud.internal import constants
herbertxue6ef54a52019-05-02 11:38:58 +080025from acloud.internal.lib import utils
Kevin Cheng3087af52018-08-13 13:26:50 -070026
27
herbertxue93630f52020-03-06 16:06:56 +080028_DEFAULT_GPU = "default"
Kevin Cheng3087af52018-08-13 13:26:50 -070029CMD_CREATE = "create"
30
31
32# TODO: Add this into main create args once create_cf/gf is deprecated.
33def AddCommonCreateArgs(parser):
34 """Adds arguments common to create parsers.
35
36 Args:
37 parser: ArgumentParser object, used to parse flags.
38 """
39 parser.add_argument(
40 "--num",
41 type=int,
42 dest="num",
43 required=False,
44 default=1,
45 help="Number of instances to create.")
46 parser.add_argument(
Sam Chiue669ef72018-10-16 16:23:37 +080047 "--serial-log-file",
Kevin Cheng3087af52018-08-13 13:26:50 -070048 type=str,
49 dest="serial_log_file",
50 required=False,
51 help="Path to a *tar.gz file where serial logs will be saved "
Kevin Cheng86d43c72018-08-30 10:59:14 -070052 "when a device fails on boot.")
Kevin Cheng3087af52018-08-13 13:26:50 -070053 parser.add_argument(
Kevin Cheng3087af52018-08-13 13:26:50 -070054 "--autoconnect",
chojoycee86730a2019-12-11 15:37:58 +080055 type=str,
56 nargs="?",
chojoyce471d3862020-01-16 15:18:12 +080057 const=constants.INS_KEY_VNC,
Kevin Cheng3087af52018-08-13 13:26:50 -070058 dest="autoconnect",
59 required=False,
chojoyce4e2d9222020-01-03 17:04:05 +080060 choices=[constants.INS_KEY_VNC, constants.INS_KEY_ADB,
61 constants.INS_KEY_WEBRTC],
62 help="Determines to establish a tunnel forwarding adb/vnc and "
63 "launch VNC/webrtc. Establish a tunnel forwarding adb and vnc "
64 "then launch vnc if --autoconnect vnc is provided. Establish a "
65 "tunnel forwarding adb if --autoconnect adb is provided. "
66 "Establish a tunnel forwarding adb and auto-launch on the browser "
67 "if --autoconnect webrtc is provided. For local goldfish "
68 "instance, create a window.")
Kevin Cheng4a8f5cf2018-08-15 08:59:28 -070069 parser.add_argument(
70 "--no-autoconnect",
71 action="store_false",
72 dest="autoconnect",
daviddclo53fd8472018-12-27 16:24:06 +080073 required=False,
74 help="Will not automatically create ssh tunnels forwarding adb & vnc "
75 "when instance created.")
chojoyce471d3862020-01-16 15:18:12 +080076 parser.set_defaults(autoconnect=constants.INS_KEY_VNC)
Kevin Cheng86d43c72018-08-30 10:59:14 -070077 parser.add_argument(
chojoycec60fa582019-07-11 16:09:02 +080078 "--unlock",
79 action="store_true",
80 dest="unlock_screen",
81 required=False,
82 default=False,
83 help="This can unlock screen after invoke vnc client.")
84 parser.add_argument(
Sam Chiue669ef72018-10-16 16:23:37 +080085 "--report-internal-ip",
Kevin Cheng86d43c72018-08-30 10:59:14 -070086 action="store_true",
87 dest="report_internal_ip",
88 required=False,
89 help="Report internal ip of the created instance instead of external "
Kevin Cheng1f582bc2018-10-02 10:37:02 -070090 "ip. Using the internal ip is used when connecting from another "
Kevin Cheng86d43c72018-08-30 10:59:14 -070091 "GCE instance.")
Kevin Chengc9424a82018-10-25 11:34:55 -070092 parser.add_argument(
93 "--network",
94 type=str,
95 dest="network",
96 required=False,
97 help="Set the network the GCE instance will utilize.")
Kevin Chengfab8cfc2019-06-27 14:01:37 -070098 parser.add_argument(
99 "--skip-pre-run-check",
100 action="store_true",
101 dest="skip_pre_run_check",
102 required=False,
103 help="Skip the pre-run check.")
cylan6bc90ff2019-07-10 13:40:56 +0800104 parser.add_argument(
105 "--boot-timeout",
106 dest="boot_timeout_secs",
107 type=int,
108 required=False,
109 help="The maximum time in seconds used to wait for the AVD to boot.")
herbertxue23b2a962019-07-24 22:39:20 +0800110 parser.add_argument(
herbertxue40e7efb2019-12-13 11:47:24 +0800111 "--wait-for-ins-stable",
112 dest="ins_timeout_secs",
113 type=int,
114 required=False,
115 help="The maximum time in seconds used to wait for the instance boot "
116 "up. The default value to wait for instance up time is 300 secs.")
117 parser.add_argument(
herbertxuec6f0c262019-07-31 16:59:49 +0800118 "--build-target",
119 type=str,
120 dest="build_target",
121 help="Android build target, e.g. aosp_cf_x86_phone-userdebug, "
122 "or short names: phone, tablet, or tablet_mobile.")
123 parser.add_argument(
124 "--branch",
125 type=str,
126 dest="branch",
127 help="Android branch, e.g. mnc-dev or git_mnc-dev")
128 parser.add_argument(
129 "--build-id",
130 type=str,
131 dest="build_id",
132 help="Android build id, e.g. 2145099, P2804227")
133 parser.add_argument(
134 "--kernel-build-id",
135 type=str,
136 dest="kernel_build_id",
137 required=False,
138 help="Android kernel build id, e.g. 4586590. This is to test a new"
herbertxue03eb5d72019-09-10 14:52:10 +0800139 " kernel build with a particular Android build (--build-id). If neither"
140 " kernel-branch nor kernel-build-id are specified, the kernel that's"
herbertxuec6f0c262019-07-31 16:59:49 +0800141 " bundled with the Android build would be used.")
142 parser.add_argument(
143 "--kernel-branch",
144 type=str,
145 dest="kernel_branch",
146 required=False,
147 help="Android kernel build branch name, e.g."
148 " kernel-common-android-4.14. This is to test a new kernel build with a"
149 " particular Android build (--build-id). If specified without"
herbertxue03eb5d72019-09-10 14:52:10 +0800150 " specifying kernel-build-id, the last green build in the branch will"
151 " be used. If neither kernel-branch nor kernel-build-id are specified,"
herbertxuec6f0c262019-07-31 16:59:49 +0800152 " the kernel that's bundled with the Android build would be used.")
153 parser.add_argument(
154 "--kernel-build-target",
155 type=str,
156 dest="kernel_build_target",
157 default="kernel",
158 help="Kernel build target, specify if different from 'kernel'")
159 parser.add_argument(
herbertxue23b2a962019-07-24 22:39:20 +0800160 "--system-branch",
161 type=str,
162 dest="system_branch",
163 help="'cuttlefish only' Branch to consume the system image (system.img) "
164 "from, will default to what is defined by --branch. "
165 "That feature allows to (automatically) test various combinations "
166 "of vendor.img (CF, e.g.) and system images (GSI, e.g.). ",
167 required=False)
168 parser.add_argument(
169 "--system-build-id",
170 type=str,
171 dest="system_build_id",
172 help="'cuttlefish only' System image build id, e.g. 2145099, P2804227",
173 required=False)
174 parser.add_argument(
175 "--system-build-target",
176 type=str,
177 dest="system_build_target",
178 help="'cuttlefish only' System image build target, specify if different "
herbertxue03eb5d72019-09-10 14:52:10 +0800179 "from --build-target",
herbertxue23b2a962019-07-24 22:39:20 +0800180 required=False)
herbertxueda2619b2019-12-06 12:09:47 +0800181 # TODO(146314062): Remove --multi-stage-launch after infra don't use this
182 # args.
Cody Schuffelen102b3b52019-07-17 10:26:35 -0700183 parser.add_argument(
184 "--multi-stage-launch",
185 dest="multi_stage_launch",
herbertxue6e546122020-01-06 23:35:25 +0800186 action="store_true",
Cody Schuffelen102b3b52019-07-17 10:26:35 -0700187 required=False,
herbertxueda2619b2019-12-06 12:09:47 +0800188 default=True,
Cody Schuffelen102b3b52019-07-17 10:26:35 -0700189 help="Enable the multi-stage cuttlefish launch.")
190 parser.add_argument(
191 "--no-multi-stage-launch",
192 dest="multi_stage_launch",
herbertxue6e546122020-01-06 23:35:25 +0800193 action="store_false",
Cody Schuffelen102b3b52019-07-17 10:26:35 -0700194 required=False,
195 default=None,
196 help="Disable the multi-stage cuttlefish launch.")
herbertxue6e546122020-01-06 23:35:25 +0800197 parser.add_argument(
198 "--no-pull-log",
199 dest="no_pull_log",
200 action="store_true",
201 required=False,
202 default=None,
203 help="Disable auto download logs when AVD booting up failed.")
herbertxue9a651d62020-01-08 21:58:34 +0800204 # TODO(147335651): Add gpu in user config.
205 # TODO(147335651): Support "--gpu" without giving any value.
206 parser.add_argument(
207 "--gpu",
208 type=str,
herbertxue93630f52020-03-06 16:06:56 +0800209 const=_DEFAULT_GPU,
210 nargs="?",
herbertxue9a651d62020-01-08 21:58:34 +0800211 dest="gpu",
212 required=False,
213 default=None,
herbertxue93630f52020-03-06 16:06:56 +0800214 help="GPU accelerator to use if any. e.g. nvidia-tesla-k80. For local "
215 "instances, this arg without assigning any value is to enable "
216 "local gpu support.")
herbertxue408dba82020-03-19 19:23:32 +0800217 # Hide this arg for users, it is only used in infra.
218 parser.add_argument(
219 "--num-avds-per-instance",
220 type=int,
221 dest="num_avds_per_instance",
222 required=False,
223 default=1,
224 help=argparse.SUPPRESS)
Kevin Cheng3087af52018-08-13 13:26:50 -0700225
Kevin Cheng85a20f62018-10-25 11:53:11 -0700226 # TODO(b/118439885): Old arg formats to support transition, delete when
227 # transistion is done.
228 parser.add_argument(
229 "--serial_log_file",
230 type=str,
231 dest="serial_log_file",
232 required=False,
Kevin Cheng9aeed4d2018-12-18 14:37:34 -0800233 help=argparse.SUPPRESS)
Kevin Cheng85a20f62018-10-25 11:53:11 -0700234 parser.add_argument(
Richard Fung97503b22019-02-06 13:43:38 -0800235 "--build_id",
236 type=str,
237 dest="build_id",
238 required=False,
239 help=argparse.SUPPRESS)
240 parser.add_argument(
241 "--build_target",
242 type=str,
243 dest="build_target",
244 required=False,
245 help=argparse.SUPPRESS)
herbertxue23b2a962019-07-24 22:39:20 +0800246 parser.add_argument(
247 "--system_branch",
248 type=str,
249 dest="system_branch",
250 required=False,
251 help=argparse.SUPPRESS)
252 parser.add_argument(
253 "--system_build_id",
254 type=str,
255 dest="system_build_id",
256 required=False,
257 help=argparse.SUPPRESS)
258 parser.add_argument(
259 "--system_build_target",
260 type=str,
261 dest="system_build_target",
262 required=False,
263 help=argparse.SUPPRESS)
herbertxuec6f0c262019-07-31 16:59:49 +0800264 parser.add_argument(
265 "--kernel_build_id",
266 type=str,
267 dest="kernel_build_id",
268 required=False,
269 help=argparse.SUPPRESS)
270 parser.add_argument(
271 "--kernel_branch",
272 type=str,
273 dest="kernel_branch",
274 required=False,
275 help=argparse.SUPPRESS)
276 parser.add_argument(
277 "--kernel_build_target",
278 type=str,
279 dest="kernel_build_target",
280 default="kernel",
281 help=argparse.SUPPRESS)
Kevin Cheng85a20f62018-10-25 11:53:11 -0700282
Kevin Cheng3087af52018-08-13 13:26:50 -0700283
284def GetCreateArgParser(subparser):
285 """Return the create arg parser.
286
287 Args:
288 subparser: argparse.ArgumentParser that is attached to main acloud cmd.
289
290 Returns:
291 argparse.ArgumentParser with create options defined.
292 """
293 create_parser = subparser.add_parser(CMD_CREATE)
294 create_parser.required = False
295 create_parser.set_defaults(which=CMD_CREATE)
Sam Chiu59120542019-08-15 09:32:32 +0800296 # Use default=0 to distinguish remote instance or local. The instance type
297 # will be remote if arg --local-instance is not provided.
Kevin Cheng3087af52018-08-13 13:26:50 -0700298 create_parser.add_argument(
Sam Chiue669ef72018-10-16 16:23:37 +0800299 "--local-instance",
Sam Chiu59120542019-08-15 09:32:32 +0800300 type=int,
301 const=1,
302 nargs="?",
cylanabe0a3a2018-08-16 18:50:09 +0800303 dest="local_instance",
304 required=False,
Sam Chiu59120542019-08-15 09:32:32 +0800305 help="Create a local AVD instance with the option to specify the local "
306 "instance ID (primarily for infra usage).")
cylanabe0a3a2018-08-16 18:50:09 +0800307 create_parser.add_argument(
herbertxue6ef54a52019-05-02 11:38:58 +0800308 "--adb-port", "-p",
309 type=int,
310 default=None,
311 dest="adb_port",
312 required=False,
313 help="Specify port for adb forwarding.")
314 create_parser.add_argument(
Sam Chiue669ef72018-10-16 16:23:37 +0800315 "--avd-type",
Kevin Cheng3087af52018-08-13 13:26:50 -0700316 type=str,
317 dest="avd_type",
318 default=constants.TYPE_CF,
Richard Fung97503b22019-02-06 13:43:38 -0800319 choices=[constants.TYPE_GCE, constants.TYPE_CF, constants.TYPE_GF, constants.TYPE_CHEEPS],
Kevin Cheng3087af52018-08-13 13:26:50 -0700320 help="Android Virtual Device type (default %s)." % constants.TYPE_CF)
321 create_parser.add_argument(
cylanabe0a3a2018-08-16 18:50:09 +0800322 "--flavor",
323 type=str,
324 dest="flavor",
cylanabe0a3a2018-08-16 18:50:09 +0800325 help="The device flavor of the AVD (default %s)." % constants.FLAVOR_PHONE)
326 create_parser.add_argument(
Sam Chiue669ef72018-10-16 16:23:37 +0800327 "--local-image",
herbertxue2625b042018-08-16 23:28:20 +0800328 type=str,
329 dest="local_image",
330 nargs="?",
331 default="",
332 required=False,
Kevin Cheng01b58bd2018-10-17 16:03:10 -0700333 help="Use the locally built image for the AVD. Look for the image "
Sam Chiu96172ae2019-01-31 14:30:30 +0800334 "artifact in $ANDROID_PRODUCT_OUT if no args value is provided."
335 "e.g --local-image or --local-image /path/to/dir or --local-image "
336 "/path/to/file")
chojoycef23e7d52018-10-15 17:36:35 +0800337 create_parser.add_argument(
Hsin-Yi Chen2a609332019-10-07 19:39:52 +0800338 "--local-system-image",
339 type=str,
340 dest="local_system_image",
341 nargs="?",
342 default="",
343 required=False,
344 help="Use the locally built system images for the AVD. Look for the "
345 "images in $ANDROID_PRODUCT_OUT if no args value is provided. "
346 "e.g., --local-system-image or --local-system-image /path/to/dir")
347 create_parser.add_argument(
Hsin-Yi Chene76c1bf2019-12-23 15:15:47 +0800348 "--local-tool",
349 type=str,
350 dest="local_tool",
351 action="append",
352 default=[],
353 required=False,
354 help="Use the tools in the specified directory to create local "
355 "instances. The directory structure follows $ANDROID_HOST_OUT or "
356 "$ANDROID_EMULATOR_PREBUILTS.")
357 create_parser.add_argument(
chojoycef23e7d52018-10-15 17:36:35 +0800358 "--image-download-dir",
359 type=str,
360 dest="image_download_dir",
361 required=False,
362 help="Define remote image download directory, e.g. /usr/local/dl.")
herbertxue7ef23b22019-02-27 09:34:24 +0800363 create_parser.add_argument(
364 "--yes", "-y",
365 action="store_true",
366 dest="no_prompt",
367 required=False,
368 help=("Automatic yes to prompts. Assume 'yes' as answer to all prompts "
369 "and run non-interactively."))
cylan2d633512019-09-09 20:33:42 +0800370 create_parser.add_argument(
371 "--reuse-gce",
372 type=str,
373 const=constants.SELECT_ONE_GCE_INSTANCE,
374 nargs="?",
375 dest="reuse_gce",
376 required=False,
377 help="'cuttlefish only' This can help users use their own instance. "
378 "Reusing specific gce instance if --reuse-gce [instance_name] is "
379 "provided. Select one gce instance to reuse if --reuse-gce is "
380 "provided.")
cyland43f2932019-11-26 17:37:28 +0800381 create_parser.add_argument(
382 "--host",
383 type=str,
384 dest="remote_host",
385 default=None,
cylan0f61af62019-12-30 22:31:10 +0800386 help="'cuttlefish only' Provide host name to clean up the remote host. "
387 "For example: '--host 1.1.1.1'")
cyland43f2932019-11-26 17:37:28 +0800388 create_parser.add_argument(
389 "--host-user",
390 type=str,
391 dest="host_user",
cylan0f61af62019-12-30 22:31:10 +0800392 default=constants.GCE_USER,
393 help="'remote host only' Provide host user for logging in to the host. "
394 "The default value is vsoc-01. For example: '--host 1.1.1.1 --host-user "
395 "vsoc-02'")
cyland43f2932019-11-26 17:37:28 +0800396 create_parser.add_argument(
397 "--host-ssh-private-key-path",
398 type=str,
399 dest="host_ssh_private_key_path",
400 default=None,
401 help="'remote host only' Provide host key for login on on this host.")
Sam Chiuc64f3432018-08-17 11:19:06 +0800402 # User should not specify --spec and --hw_property at the same time.
403 hw_spec_group = create_parser.add_mutually_exclusive_group()
404 hw_spec_group.add_argument(
Sam Chiue669ef72018-10-16 16:23:37 +0800405 "--hw-property",
Sam Chiuc64f3432018-08-17 11:19:06 +0800406 type=str,
407 dest="hw_property",
408 required=False,
409 help="Supported HW properties and example values: %s" %
410 constants.HW_PROPERTIES_CMD_EXAMPLE)
411 hw_spec_group.add_argument(
412 "--spec",
413 type=str,
414 dest="spec",
415 required=False,
416 choices=constants.SPEC_NAMES,
417 help="The name of a pre-configured device spec that we are "
418 "going to use.")
herbertxue494891e2019-01-19 13:50:53 +0800419 # Arguments for goldfish type.
420 # TODO(b/118439885): Verify args that are used in wrong avd_type.
421 # e.g. $acloud create --avd-type cuttlefish --emulator-build-id
422 create_parser.add_argument(
herbertxue494891e2019-01-19 13:50:53 +0800423 "--emulator-build-id",
424 type=int,
425 dest="emulator_build_id",
426 required=False,
427 help="'goldfish only' Emulator build used to run the images. "
428 "e.g. 4669466.")
Kevin Cheng3087af52018-08-13 13:26:50 -0700429
Richard Fung8d3979e2019-06-12 16:00:34 -0700430 # Arguments for cheeps type.
431 create_parser.add_argument(
Shao-Chuan Lee80244112020-02-04 17:14:07 +0900432 "--stable-cheeps-host-image-name",
433 type=str,
434 dest="stable_cheeps_host_image_name",
435 required=False,
436 default=None,
437 help=("'cheeps only' The Cheeps host image from which instances are "
438 "launched. If specified here, the value set in Acloud config "
439 "file will be overridden."))
440 create_parser.add_argument(
441 "--stable-cheeps-host-image-project",
442 type=str,
443 dest="stable_cheeps_host_image_project",
444 required=False,
445 default=None,
446 help=("'cheeps only' The project hosting the specified Cheeps host "
447 "image. If specified here, the value set in Acloud config file "
448 "will be overridden."))
449 create_parser.add_argument(
Richard Fung8d3979e2019-06-12 16:00:34 -0700450 "--user",
451 type=str,
452 dest="username",
453 required=False,
454 default=None,
455 help="'cheeps only' username to log in to Chrome OS as.")
456 create_parser.add_argument(
457 "--password",
458 type=str,
459 dest="password",
460 required=False,
461 default=None,
462 help="'cheeps only' password to log in to Chrome OS with.")
463
Kevin Cheng3087af52018-08-13 13:26:50 -0700464 AddCommonCreateArgs(create_parser)
465 return create_parser
herbertxue2625b042018-08-16 23:28:20 +0800466
467
Hsin-Yi Chen2a609332019-10-07 19:39:52 +0800468def _VerifyLocalArgs(args):
469 """Verify args starting with --local.
470
471 Args:
472 args: Namespace object from argparse.parse_args.
473
474 Raises:
475 errors.CheckPathError: Image path doesn't exist.
476 errors.UnsupportedCreateArgs: The specified avd type does not support
477 --local-system-image.
478 errors.UnsupportedLocalInstanceId: Local instance ID is invalid.
479 """
480 if args.local_image and not os.path.exists(args.local_image):
481 raise errors.CheckPathError(
482 "Specified path doesn't exist: %s" % args.local_image)
483
484 # TODO(b/133211308): Support TYPE_CF.
485 if args.local_system_image != "" and args.avd_type != constants.TYPE_GF:
486 raise errors.UnsupportedCreateArgs("%s instance does not support "
487 "--local-system-image" %
488 args.avd_type)
489
490 if (args.local_system_image and
491 not os.path.exists(args.local_system_image)):
492 raise errors.CheckPathError(
493 "Specified path doesn't exist: %s" % args.local_system_image)
494
495 if args.local_instance is not None and args.local_instance < 1:
496 raise errors.UnsupportedLocalInstanceId("Local instance id can not be "
497 "less than 1. Actually passed:%d"
498 % args.local_instance)
499
Hsin-Yi Chene76c1bf2019-12-23 15:15:47 +0800500 for tool_dir in args.local_tool:
501 if not os.path.exists(tool_dir):
502 raise errors.CheckPathError(
503 "Specified path doesn't exist: %s" % tool_dir)
504
chojoyce4e2d9222020-01-03 17:04:05 +0800505 if args.autoconnect == constants.INS_KEY_WEBRTC:
506 if args.avd_type != constants.TYPE_CF:
507 raise errors.UnsupportedCreateArgs(
508 "'--autoconnect webrtc' only support cuttlefish.")
509
Hsin-Yi Chen2a609332019-10-07 19:39:52 +0800510
cyland43f2932019-11-26 17:37:28 +0800511def _VerifyHostArgs(args):
512 """Verify args starting with --host.
513
514 Args:
515 args: Namespace object from argparse.parse_args.
516
517 Raises:
518 errors.UnsupportedCreateArgs: When a create arg is specified but
519 unsupported for remote host mode.
520 """
521 if args.remote_host and args.local_instance is not None:
522 raise errors.UnsupportedCreateArgs(
523 "--host is not supported for local instance.")
524
525 if args.remote_host and args.num > 1:
526 raise errors.UnsupportedCreateArgs(
527 "--num is not supported for remote host.")
528
cylan30ab4d62020-01-06 14:01:09 +0800529 if args.host_user != constants.GCE_USER and args.remote_host is None:
cyland43f2932019-11-26 17:37:28 +0800530 raise errors.UnsupportedCreateArgs(
531 "--host-user only support for remote host.")
532
533 if args.host_ssh_private_key_path and args.remote_host is None:
534 raise errors.UnsupportedCreateArgs(
535 "--host-ssh-private-key-path only support for remote host.")
536
537
herbertxue2625b042018-08-16 23:28:20 +0800538def VerifyArgs(args):
539 """Verify args.
540
541 Args:
542 args: Namespace object from argparse.parse_args.
543
544 Raises:
herbertxuefd15dfd2018-12-04 11:26:27 +0800545 errors.UnsupportedFlavor: Flavor doesn't support.
herbertxue6ef54a52019-05-02 11:38:58 +0800546 errors.UnsupportedMultiAdbPort: multi adb port doesn't support.
herbertxue23b2a962019-07-24 22:39:20 +0800547 errors.UnsupportedCreateArgs: When a create arg is specified but
548 unsupported for a particular avd type.
549 (e.g. --system-build-id for gf)
herbertxue2625b042018-08-16 23:28:20 +0800550 """
herbertxuefd15dfd2018-12-04 11:26:27 +0800551 # Verify that user specified flavor name is in support list.
552 # We don't use argparse's builtin validation because we need to be able to
553 # tell when a user doesn't specify a flavor.
554 if args.flavor and args.flavor not in constants.ALL_FLAVORS:
555 raise errors.UnsupportedFlavor(
556 "Flavor[%s] isn't in support list: %s" % (args.flavor,
557 constants.ALL_FLAVORS))
herbertxue23b2a962019-07-24 22:39:20 +0800558 if args.avd_type != constants.TYPE_CF:
559 if args.system_branch or args.system_build_id or args.system_build_target:
560 raise errors.UnsupportedCreateArgs(
561 "--system-* args are not supported for AVD type: %s"
562 % args.avd_type)
herbertxuefd15dfd2018-12-04 11:26:27 +0800563
herbertxue6ef54a52019-05-02 11:38:58 +0800564 if args.num > 1 and args.adb_port:
565 raise errors.UnsupportedMultiAdbPort(
566 "--adb-port is not supported for multi-devices.")
567
herbertxue755ad482019-11-21 11:31:29 +0800568 if args.num > 1 and args.local_instance is not None:
569 raise errors.UnsupportedCreateArgs(
570 "--num is not supported for local instance.")
571
herbertxue93630f52020-03-06 16:06:56 +0800572 if args.local_instance is None and args.gpu == _DEFAULT_GPU:
573 raise errors.UnsupportedCreateArgs(
574 "Please assign one gpu model for GCE instance. Reference: "
575 "https://cloud.google.com/compute/docs/gpus")
576
herbertxue6ef54a52019-05-02 11:38:58 +0800577 if args.adb_port:
578 utils.CheckPortFree(args.adb_port)
579
Sam Chiuc64f3432018-08-17 11:19:06 +0800580 hw_properties = create_common.ParseHWPropertyArgs(args.hw_property)
581 for key in hw_properties:
582 if key not in constants.HW_PROPERTIES:
583 raise errors.InvalidHWPropertyError(
584 "[%s] is an invalid hw property, supported values are:%s. "
585 % (key, constants.HW_PROPERTIES))
Richard Fung8d3979e2019-06-12 16:00:34 -0700586
Shao-Chuan Lee80244112020-02-04 17:14:07 +0900587 if args.avd_type != constants.TYPE_CHEEPS and (
588 args.stable_cheeps_host_image_name or
589 args.stable_cheeps_host_image_project or
590 args.username or args.password):
591 raise errors.UnsupportedCreateArgs(
592 "--stable-cheeps-*, --username and --password are only valid with "
593 "avd_type == %s" % constants.TYPE_CHEEPS)
Richard Fung8d3979e2019-06-12 16:00:34 -0700594 if (args.username or args.password) and not (args.username and args.password):
595 raise ValueError("--username and --password must both be set")
chojoycec60fa582019-07-11 16:09:02 +0800596 if not args.autoconnect and args.unlock_screen:
597 raise ValueError("--no-autoconnect and --unlock couldn't be "
598 "passed in together.")
Sam Chiu59120542019-08-15 09:32:32 +0800599
Hsin-Yi Chen2a609332019-10-07 19:39:52 +0800600 _VerifyLocalArgs(args)
cyland43f2932019-11-26 17:37:28 +0800601 _VerifyHostArgs(args)