Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 1 | # 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. |
| 14 | r"""Create args. |
| 15 | |
| 16 | Defines the create arg parser that holds create specific args. |
| 17 | """ |
| 18 | |
Kevin Cheng | 9aeed4d | 2018-12-18 14:37:34 -0800 | [diff] [blame] | 19 | import argparse |
herbertxue | 36b99f1 | 2021-03-25 14:47:28 +0800 | [diff] [blame^] | 20 | import logging |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 21 | import os |
| 22 | |
| 23 | from acloud import errors |
Sam Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 24 | from acloud.create import create_common |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 25 | from acloud.internal import constants |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 26 | from acloud.internal.lib import utils |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 27 | |
herbertxue | 36b99f1 | 2021-03-25 14:47:28 +0800 | [diff] [blame^] | 28 | logger = logging.getLogger(__name__) |
herbertxue | 93630f5 | 2020-03-06 16:06:56 +0800 | [diff] [blame] | 29 | _DEFAULT_GPU = "default" |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 30 | CMD_CREATE = "create" |
| 31 | |
| 32 | |
| 33 | # TODO: Add this into main create args once create_cf/gf is deprecated. |
| 34 | def 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 Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 48 | "--serial-log-file", |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 49 | 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 Cheng | 86d43c7 | 2018-08-30 10:59:14 -0700 | [diff] [blame] | 53 | "when a device fails on boot.") |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 54 | parser.add_argument( |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 55 | "--autoconnect", |
chojoyce | e86730a | 2019-12-11 15:37:58 +0800 | [diff] [blame] | 56 | type=str, |
| 57 | nargs="?", |
chojoyce | 471d386 | 2020-01-16 15:18:12 +0800 | [diff] [blame] | 58 | const=constants.INS_KEY_VNC, |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 59 | dest="autoconnect", |
| 60 | required=False, |
chojoyce | 4e2d922 | 2020-01-03 17:04:05 +0800 | [diff] [blame] | 61 | 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 Cheng | 4a8f5cf | 2018-08-15 08:59:28 -0700 | [diff] [blame] | 70 | parser.add_argument( |
| 71 | "--no-autoconnect", |
| 72 | action="store_false", |
| 73 | dest="autoconnect", |
daviddclo | 53fd847 | 2018-12-27 16:24:06 +0800 | [diff] [blame] | 74 | required=False, |
| 75 | help="Will not automatically create ssh tunnels forwarding adb & vnc " |
| 76 | "when instance created.") |
chojoyce | 471d386 | 2020-01-16 15:18:12 +0800 | [diff] [blame] | 77 | parser.set_defaults(autoconnect=constants.INS_KEY_VNC) |
Kevin Cheng | 86d43c7 | 2018-08-30 10:59:14 -0700 | [diff] [blame] | 78 | parser.add_argument( |
chojoyce | c60fa58 | 2019-07-11 16:09:02 +0800 | [diff] [blame] | 79 | "--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 Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 86 | "--report-internal-ip", |
Kevin Cheng | 86d43c7 | 2018-08-30 10:59:14 -0700 | [diff] [blame] | 87 | action="store_true", |
| 88 | dest="report_internal_ip", |
| 89 | required=False, |
| 90 | help="Report internal ip of the created instance instead of external " |
Kevin Cheng | 1f582bc | 2018-10-02 10:37:02 -0700 | [diff] [blame] | 91 | "ip. Using the internal ip is used when connecting from another " |
Kevin Cheng | 86d43c7 | 2018-08-30 10:59:14 -0700 | [diff] [blame] | 92 | "GCE instance.") |
Kevin Cheng | c9424a8 | 2018-10-25 11:34:55 -0700 | [diff] [blame] | 93 | 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 Cheng | fab8cfc | 2019-06-27 14:01:37 -0700 | [diff] [blame] | 99 | 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.") |
cylan | 6bc90ff | 2019-07-10 13:40:56 +0800 | [diff] [blame] | 105 | 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.") |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 111 | parser.add_argument( |
herbertxue | 40e7efb | 2019-12-13 11:47:24 +0800 | [diff] [blame] | 112 | "--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( |
herbertxue | c6f0c26 | 2019-07-31 16:59:49 +0800 | [diff] [blame] | 119 | "--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( |
herbertxue | e659d15 | 2020-10-15 18:52:06 +0800 | [diff] [blame] | 135 | "--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( |
herbertxue | c6f0c26 | 2019-07-31 16:59:49 +0800 | [diff] [blame] | 153 | "--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" |
herbertxue | 03eb5d7 | 2019-09-10 14:52:10 +0800 | [diff] [blame] | 158 | " kernel build with a particular Android build (--build-id). If neither" |
| 159 | " kernel-branch nor kernel-build-id are specified, the kernel that's" |
herbertxue | c6f0c26 | 2019-07-31 16:59:49 +0800 | [diff] [blame] | 160 | " 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" |
herbertxue | 03eb5d7 | 2019-09-10 14:52:10 +0800 | [diff] [blame] | 169 | " 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," |
herbertxue | c6f0c26 | 2019-07-31 16:59:49 +0800 | [diff] [blame] | 171 | " 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( |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 179 | "--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 " |
herbertxue | 03eb5d7 | 2019-09-10 14:52:10 +0800 | [diff] [blame] | 198 | "from --build-target", |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 199 | required=False) |
herbertxue | da2619b | 2019-12-06 12:09:47 +0800 | [diff] [blame] | 200 | # TODO(146314062): Remove --multi-stage-launch after infra don't use this |
| 201 | # args. |
Cody Schuffelen | 102b3b5 | 2019-07-17 10:26:35 -0700 | [diff] [blame] | 202 | parser.add_argument( |
| 203 | "--multi-stage-launch", |
| 204 | dest="multi_stage_launch", |
herbertxue | 6e54612 | 2020-01-06 23:35:25 +0800 | [diff] [blame] | 205 | action="store_true", |
Cody Schuffelen | 102b3b5 | 2019-07-17 10:26:35 -0700 | [diff] [blame] | 206 | required=False, |
herbertxue | da2619b | 2019-12-06 12:09:47 +0800 | [diff] [blame] | 207 | default=True, |
Cody Schuffelen | 102b3b5 | 2019-07-17 10:26:35 -0700 | [diff] [blame] | 208 | help="Enable the multi-stage cuttlefish launch.") |
| 209 | parser.add_argument( |
| 210 | "--no-multi-stage-launch", |
| 211 | dest="multi_stage_launch", |
herbertxue | 6e54612 | 2020-01-06 23:35:25 +0800 | [diff] [blame] | 212 | action="store_false", |
Cody Schuffelen | 102b3b5 | 2019-07-17 10:26:35 -0700 | [diff] [blame] | 213 | required=False, |
| 214 | default=None, |
| 215 | help="Disable the multi-stage cuttlefish launch.") |
herbertxue | 6e54612 | 2020-01-06 23:35:25 +0800 | [diff] [blame] | 216 | 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.") |
herbertxue | 9a651d6 | 2020-01-08 21:58:34 +0800 | [diff] [blame] | 223 | # 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, |
herbertxue | 93630f5 | 2020-03-06 16:06:56 +0800 | [diff] [blame] | 228 | const=_DEFAULT_GPU, |
| 229 | nargs="?", |
herbertxue | 9a651d6 | 2020-01-08 21:58:34 +0800 | [diff] [blame] | 230 | dest="gpu", |
| 231 | required=False, |
| 232 | default=None, |
herbertxue | 93630f5 | 2020-03-06 16:06:56 +0800 | [diff] [blame] | 233 | 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.") |
herbertxue | ffbcbc2 | 2020-07-07 14:35:34 +0800 | [diff] [blame] | 236 | # Hide following args for users, it is only used in infra. |
herbertxue | 408dba8 | 2020-03-19 19:23:32 +0800 | [diff] [blame] | 237 | parser.add_argument( |
Hsin-Yi Chen | e0bc539 | 2020-09-08 00:48:43 +0800 | [diff] [blame] | 238 | "--local-instance-dir", |
| 239 | dest="local_instance_dir", |
| 240 | required=False, |
| 241 | help=argparse.SUPPRESS) |
| 242 | parser.add_argument( |
herbertxue | 408dba8 | 2020-03-19 19:23:32 +0800 | [diff] [blame] | 243 | "--num-avds-per-instance", |
| 244 | type=int, |
| 245 | dest="num_avds_per_instance", |
| 246 | required=False, |
| 247 | default=1, |
| 248 | help=argparse.SUPPRESS) |
herbertxue | ffbcbc2 | 2020-07-07 14:35:34 +0800 | [diff] [blame] | 249 | parser.add_argument( |
| 250 | "--zone", |
| 251 | type=str, |
| 252 | dest="zone", |
| 253 | required=False, |
| 254 | help=argparse.SUPPRESS) |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 255 | |
Kevin Cheng | 85a20f6 | 2018-10-25 11:53:11 -0700 | [diff] [blame] | 256 | # 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 Cheng | 9aeed4d | 2018-12-18 14:37:34 -0800 | [diff] [blame] | 263 | help=argparse.SUPPRESS) |
Kevin Cheng | 85a20f6 | 2018-10-25 11:53:11 -0700 | [diff] [blame] | 264 | parser.add_argument( |
Richard Fung | 97503b2 | 2019-02-06 13:43:38 -0800 | [diff] [blame] | 265 | "--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) |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 276 | 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) |
herbertxue | c6f0c26 | 2019-07-31 16:59:49 +0800 | [diff] [blame] | 294 | 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) |
herbertxue | e659d15 | 2020-10-15 18:52:06 +0800 | [diff] [blame] | 312 | 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 Cheng | 85a20f6 | 2018-10-25 11:53:11 -0700 | [diff] [blame] | 330 | |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 331 | |
| 332 | def 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 Chen | caec52f | 2020-07-16 14:59:26 +0800 | [diff] [blame] | 344 | # Use default=None to distinguish remote instance or local. The instance |
| 345 | # type will be remote if the arg is not provided. |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 346 | create_parser.add_argument( |
Sam Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 347 | "--local-instance", |
Hsin-Yi Chen | caec52f | 2020-07-16 14:59:26 +0800 | [diff] [blame] | 348 | type=_PositiveInteger, |
| 349 | const=0, |
| 350 | metavar="ID", |
Sam Chiu | 5912054 | 2019-08-15 09:32:32 +0800 | [diff] [blame] | 351 | nargs="?", |
cylan | abe0a3a | 2018-08-16 18:50:09 +0800 | [diff] [blame] | 352 | dest="local_instance", |
| 353 | required=False, |
Hsin-Yi Chen | caec52f | 2020-07-16 14:59:26 +0800 | [diff] [blame] | 354 | 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).") |
cylan | abe0a3a | 2018-08-16 18:50:09 +0800 | [diff] [blame] | 357 | create_parser.add_argument( |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 358 | "--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 Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 365 | "--avd-type", |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 366 | type=str, |
| 367 | dest="avd_type", |
| 368 | default=constants.TYPE_CF, |
Peter Collingbourne | dce6d72 | 2020-05-07 15:29:21 -0700 | [diff] [blame] | 369 | choices=[constants.TYPE_GCE, constants.TYPE_CF, constants.TYPE_GF, constants.TYPE_CHEEPS, |
| 370 | constants.TYPE_FVP], |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 371 | help="Android Virtual Device type (default %s)." % constants.TYPE_CF) |
| 372 | create_parser.add_argument( |
herbertxue | 60d70c9 | 2021-03-31 20:56:37 +0800 | [diff] [blame] | 373 | "--config", "--flavor", |
cylan | abe0a3a | 2018-08-16 18:50:09 +0800 | [diff] [blame] | 374 | type=str, |
| 375 | dest="flavor", |
herbertxue | 60d70c9 | 2021-03-31 20:56:37 +0800 | [diff] [blame] | 376 | help="The device flavor of the AVD (default %s). e.g. phone, tv, foldable." |
| 377 | % constants.FLAVOR_PHONE) |
cylan | abe0a3a | 2018-08-16 18:50:09 +0800 | [diff] [blame] | 378 | create_parser.add_argument( |
Sam Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 379 | "--local-image", |
Hsin-Yi Chen | c1f6964 | 2020-12-28 12:44:43 +0800 | [diff] [blame] | 380 | const=constants.FIND_IN_BUILD_ENV, |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 381 | type=str, |
| 382 | dest="local_image", |
| 383 | nargs="?", |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 384 | required=False, |
Kevin Cheng | 01b58bd | 2018-10-17 16:03:10 -0700 | [diff] [blame] | 385 | help="Use the locally built image for the AVD. Look for the image " |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 386 | "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") |
chojoyce | f23e7d5 | 2018-10-15 17:36:35 +0800 | [diff] [blame] | 389 | create_parser.add_argument( |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 390 | "--local-system-image", |
Hsin-Yi Chen | c1f6964 | 2020-12-28 12:44:43 +0800 | [diff] [blame] | 391 | const=constants.FIND_IN_BUILD_ENV, |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 392 | type=str, |
| 393 | dest="local_system_image", |
| 394 | nargs="?", |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 395 | 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 Chen | e76c1bf | 2019-12-23 15:15:47 +0800 | [diff] [blame] | 400 | "--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( |
chojoyce | f23e7d5 | 2018-10-15 17:36:35 +0800 | [diff] [blame] | 410 | "--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.") |
herbertxue | 7ef23b2 | 2019-02-27 09:34:24 +0800 | [diff] [blame] | 415 | 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.")) |
cylan | 2d63351 | 2019-09-09 20:33:42 +0800 | [diff] [blame] | 422 | 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.") |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 433 | create_parser.add_argument( |
herbertxue | c58d281 | 2021-01-21 15:02:27 +0800 | [diff] [blame] | 434 | "--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( |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 441 | "--host", |
| 442 | type=str, |
| 443 | dest="remote_host", |
| 444 | default=None, |
cylan | 0f61af6 | 2019-12-30 22:31:10 +0800 | [diff] [blame] | 445 | help="'cuttlefish only' Provide host name to clean up the remote host. " |
| 446 | "For example: '--host 1.1.1.1'") |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 447 | create_parser.add_argument( |
| 448 | "--host-user", |
| 449 | type=str, |
| 450 | dest="host_user", |
cylan | 0f61af6 | 2019-12-30 22:31:10 +0800 | [diff] [blame] | 451 | 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'") |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 455 | 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 Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 461 | # 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 Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 464 | "--hw-property", |
Sam Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 465 | 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.") |
herbertxue | 494891e | 2019-01-19 13:50:53 +0800 | [diff] [blame] | 478 | # 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( |
herbertxue | 494891e | 2019-01-19 13:50:53 +0800 | [diff] [blame] | 482 | "--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 Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 488 | |
Richard Fung | 8d3979e | 2019-06-12 16:00:34 -0700 | [diff] [blame] | 489 | # Arguments for cheeps type. |
| 490 | create_parser.add_argument( |
Shao-Chuan Lee | 8024411 | 2020-02-04 17:14:07 +0900 | [diff] [blame] | 491 | "--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 Fung | 8d3979e | 2019-06-12 16:00:34 -0700 | [diff] [blame] | 509 | "--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 Fung | d7d57f4 | 2020-04-09 12:58:49 -0700 | [diff] [blame] | 522 | 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 Fung | 8d3979e | 2019-06-12 16:00:34 -0700 | [diff] [blame] | 531 | |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 532 | AddCommonCreateArgs(create_parser) |
| 533 | return create_parser |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 534 | |
| 535 | |
Hsin-Yi Chen | caec52f | 2020-07-16 14:59:26 +0800 | [diff] [blame] | 536 | def _PositiveInteger(arg): |
| 537 | """Convert an argument from a string to a positive integer.""" |
| 538 | try: |
| 539 | value = int(arg) |
Hsin-Yi Chen | c1f6964 | 2020-12-28 12:44:43 +0800 | [diff] [blame] | 540 | except ValueError as e: |
| 541 | raise argparse.ArgumentTypeError(arg + " is not an integer.") from e |
Hsin-Yi Chen | caec52f | 2020-07-16 14:59:26 +0800 | [diff] [blame] | 542 | if value <= 0: |
| 543 | raise argparse.ArgumentTypeError(arg + " is not positive.") |
| 544 | return value |
| 545 | |
| 546 | |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 547 | def _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 Chen | e0bc539 | 2020-09-08 00:48:43 +0800 | [diff] [blame] | 563 | 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 Chen | c1f6964 | 2020-12-28 12:44:43 +0800 | [diff] [blame] | 567 | if not (args.local_system_image is None or |
Hsin-Yi Chen | 19d665c | 2020-12-28 18:13:22 +0800 | [diff] [blame] | 568 | args.avd_type in (constants.TYPE_CF, constants.TYPE_GF)): |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 569 | 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 Chen | e76c1bf | 2019-12-23 15:15:47 +0800 | [diff] [blame] | 578 | 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 | |
chojoyce | 4e2d922 | 2020-01-03 17:04:05 +0800 | [diff] [blame] | 583 | 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 Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 588 | |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 589 | def _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 | |
cylan | 30ab4d6 | 2020-01-06 14:01:09 +0800 | [diff] [blame] | 607 | if args.host_user != constants.GCE_USER and args.remote_host is None: |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 608 | 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 | |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 616 | def VerifyArgs(args): |
| 617 | """Verify args. |
| 618 | |
| 619 | Args: |
| 620 | args: Namespace object from argparse.parse_args. |
| 621 | |
| 622 | Raises: |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 623 | errors.UnsupportedMultiAdbPort: multi adb port doesn't support. |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 624 | errors.UnsupportedCreateArgs: When a create arg is specified but |
| 625 | unsupported for a particular avd type. |
| 626 | (e.g. --system-build-id for gf) |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 627 | """ |
herbertxue | fd15dfd | 2018-12-04 11:26:27 +0800 | [diff] [blame] | 628 | # 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: |
herbertxue | 36b99f1 | 2021-03-25 14:47:28 +0800 | [diff] [blame^] | 632 | logger.debug("Flavor[%s] isn't in default support list: %s", |
| 633 | args.flavor, constants.ALL_FLAVORS) |
| 634 | |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 635 | 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) |
herbertxue | fd15dfd | 2018-12-04 11:26:27 +0800 | [diff] [blame] | 640 | |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 641 | if args.num > 1 and args.adb_port: |
| 642 | raise errors.UnsupportedMultiAdbPort( |
| 643 | "--adb-port is not supported for multi-devices.") |
| 644 | |
herbertxue | 755ad48 | 2019-11-21 11:31:29 +0800 | [diff] [blame] | 645 | if args.num > 1 and args.local_instance is not None: |
| 646 | raise errors.UnsupportedCreateArgs( |
| 647 | "--num is not supported for local instance.") |
| 648 | |
herbertxue | 93630f5 | 2020-03-06 16:06:56 +0800 | [diff] [blame] | 649 | 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 | |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 654 | if args.adb_port: |
| 655 | utils.CheckPortFree(args.adb_port) |
| 656 | |
herbertxue | c58d281 | 2021-01-21 15:02:27 +0800 | [diff] [blame] | 657 | hw_properties = create_common.ParseKeyValuePairArgs(args.hw_property) |
Sam Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 658 | 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 Fung | 8d3979e | 2019-06-12 16:00:34 -0700 | [diff] [blame] | 663 | |
Richard Fung | d7d57f4 | 2020-04-09 12:58:49 -0700 | [diff] [blame] | 664 | 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 Lee | 8024411 | 2020-02-04 17:14:07 +0900 | [diff] [blame] | 670 | raise errors.UnsupportedCreateArgs( |
Richard Fung | d7d57f4 | 2020-04-09 12:58:49 -0700 | [diff] [blame] | 671 | "--stable-cheeps-*, --betty-image, --username and --password are " |
| 672 | "only valid with avd_type == %s" % constants.TYPE_CHEEPS) |
Richard Fung | 8d3979e | 2019-06-12 16:00:34 -0700 | [diff] [blame] | 673 | if (args.username or args.password) and not (args.username and args.password): |
| 674 | raise ValueError("--username and --password must both be set") |
chojoyce | c60fa58 | 2019-07-11 16:09:02 +0800 | [diff] [blame] | 675 | if not args.autoconnect and args.unlock_screen: |
| 676 | raise ValueError("--no-autoconnect and --unlock couldn't be " |
| 677 | "passed in together.") |
Sam Chiu | 5912054 | 2019-08-15 09:32:32 +0800 | [diff] [blame] | 678 | |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 679 | _VerifyLocalArgs(args) |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 680 | _VerifyHostArgs(args) |