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 | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 20 | import os |
| 21 | |
| 22 | from acloud import errors |
Sam Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 23 | from acloud.create import create_common |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 24 | from acloud.internal import constants |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 25 | from acloud.internal.lib import utils |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 26 | |
| 27 | |
herbertxue | 93630f5 | 2020-03-06 16:06:56 +0800 | [diff] [blame] | 28 | _DEFAULT_GPU = "default" |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 29 | CMD_CREATE = "create" |
| 30 | |
| 31 | |
| 32 | # TODO: Add this into main create args once create_cf/gf is deprecated. |
| 33 | def 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 Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 47 | "--serial-log-file", |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 48 | 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 Cheng | 86d43c7 | 2018-08-30 10:59:14 -0700 | [diff] [blame] | 52 | "when a device fails on boot.") |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 53 | parser.add_argument( |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 54 | "--autoconnect", |
chojoyce | e86730a | 2019-12-11 15:37:58 +0800 | [diff] [blame] | 55 | type=str, |
| 56 | nargs="?", |
chojoyce | 471d386 | 2020-01-16 15:18:12 +0800 | [diff] [blame] | 57 | const=constants.INS_KEY_VNC, |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 58 | dest="autoconnect", |
| 59 | required=False, |
chojoyce | 4e2d922 | 2020-01-03 17:04:05 +0800 | [diff] [blame] | 60 | 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 Cheng | 4a8f5cf | 2018-08-15 08:59:28 -0700 | [diff] [blame] | 69 | parser.add_argument( |
| 70 | "--no-autoconnect", |
| 71 | action="store_false", |
| 72 | dest="autoconnect", |
daviddclo | 53fd847 | 2018-12-27 16:24:06 +0800 | [diff] [blame] | 73 | required=False, |
| 74 | help="Will not automatically create ssh tunnels forwarding adb & vnc " |
| 75 | "when instance created.") |
chojoyce | 471d386 | 2020-01-16 15:18:12 +0800 | [diff] [blame] | 76 | parser.set_defaults(autoconnect=constants.INS_KEY_VNC) |
Kevin Cheng | 86d43c7 | 2018-08-30 10:59:14 -0700 | [diff] [blame] | 77 | parser.add_argument( |
chojoyce | c60fa58 | 2019-07-11 16:09:02 +0800 | [diff] [blame] | 78 | "--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 Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 85 | "--report-internal-ip", |
Kevin Cheng | 86d43c7 | 2018-08-30 10:59:14 -0700 | [diff] [blame] | 86 | action="store_true", |
| 87 | dest="report_internal_ip", |
| 88 | required=False, |
| 89 | help="Report internal ip of the created instance instead of external " |
Kevin Cheng | 1f582bc | 2018-10-02 10:37:02 -0700 | [diff] [blame] | 90 | "ip. Using the internal ip is used when connecting from another " |
Kevin Cheng | 86d43c7 | 2018-08-30 10:59:14 -0700 | [diff] [blame] | 91 | "GCE instance.") |
Kevin Cheng | c9424a8 | 2018-10-25 11:34:55 -0700 | [diff] [blame] | 92 | 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 Cheng | fab8cfc | 2019-06-27 14:01:37 -0700 | [diff] [blame] | 98 | 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.") |
cylan | 6bc90ff | 2019-07-10 13:40:56 +0800 | [diff] [blame] | 104 | 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.") |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 110 | parser.add_argument( |
herbertxue | 40e7efb | 2019-12-13 11:47:24 +0800 | [diff] [blame] | 111 | "--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( |
herbertxue | c6f0c26 | 2019-07-31 16:59:49 +0800 | [diff] [blame] | 118 | "--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" |
herbertxue | 03eb5d7 | 2019-09-10 14:52:10 +0800 | [diff] [blame] | 139 | " kernel build with a particular Android build (--build-id). If neither" |
| 140 | " kernel-branch nor kernel-build-id are specified, the kernel that's" |
herbertxue | c6f0c26 | 2019-07-31 16:59:49 +0800 | [diff] [blame] | 141 | " 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" |
herbertxue | 03eb5d7 | 2019-09-10 14:52:10 +0800 | [diff] [blame] | 150 | " 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," |
herbertxue | c6f0c26 | 2019-07-31 16:59:49 +0800 | [diff] [blame] | 152 | " 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( |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 160 | "--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 " |
herbertxue | 03eb5d7 | 2019-09-10 14:52:10 +0800 | [diff] [blame] | 179 | "from --build-target", |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 180 | required=False) |
herbertxue | da2619b | 2019-12-06 12:09:47 +0800 | [diff] [blame] | 181 | # TODO(146314062): Remove --multi-stage-launch after infra don't use this |
| 182 | # args. |
Cody Schuffelen | 102b3b5 | 2019-07-17 10:26:35 -0700 | [diff] [blame] | 183 | parser.add_argument( |
| 184 | "--multi-stage-launch", |
| 185 | dest="multi_stage_launch", |
herbertxue | 6e54612 | 2020-01-06 23:35:25 +0800 | [diff] [blame] | 186 | action="store_true", |
Cody Schuffelen | 102b3b5 | 2019-07-17 10:26:35 -0700 | [diff] [blame] | 187 | required=False, |
herbertxue | da2619b | 2019-12-06 12:09:47 +0800 | [diff] [blame] | 188 | default=True, |
Cody Schuffelen | 102b3b5 | 2019-07-17 10:26:35 -0700 | [diff] [blame] | 189 | help="Enable the multi-stage cuttlefish launch.") |
| 190 | parser.add_argument( |
| 191 | "--no-multi-stage-launch", |
| 192 | dest="multi_stage_launch", |
herbertxue | 6e54612 | 2020-01-06 23:35:25 +0800 | [diff] [blame] | 193 | action="store_false", |
Cody Schuffelen | 102b3b5 | 2019-07-17 10:26:35 -0700 | [diff] [blame] | 194 | required=False, |
| 195 | default=None, |
| 196 | help="Disable the multi-stage cuttlefish launch.") |
herbertxue | 6e54612 | 2020-01-06 23:35:25 +0800 | [diff] [blame] | 197 | 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.") |
herbertxue | 9a651d6 | 2020-01-08 21:58:34 +0800 | [diff] [blame] | 204 | # 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, |
herbertxue | 93630f5 | 2020-03-06 16:06:56 +0800 | [diff] [blame] | 209 | const=_DEFAULT_GPU, |
| 210 | nargs="?", |
herbertxue | 9a651d6 | 2020-01-08 21:58:34 +0800 | [diff] [blame] | 211 | dest="gpu", |
| 212 | required=False, |
| 213 | default=None, |
herbertxue | 93630f5 | 2020-03-06 16:06:56 +0800 | [diff] [blame] | 214 | 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.") |
herbertxue | 408dba8 | 2020-03-19 19:23:32 +0800 | [diff] [blame^] | 217 | # 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 Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 225 | |
Kevin Cheng | 85a20f6 | 2018-10-25 11:53:11 -0700 | [diff] [blame] | 226 | # 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 Cheng | 9aeed4d | 2018-12-18 14:37:34 -0800 | [diff] [blame] | 233 | help=argparse.SUPPRESS) |
Kevin Cheng | 85a20f6 | 2018-10-25 11:53:11 -0700 | [diff] [blame] | 234 | parser.add_argument( |
Richard Fung | 97503b2 | 2019-02-06 13:43:38 -0800 | [diff] [blame] | 235 | "--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) |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 246 | 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) |
herbertxue | c6f0c26 | 2019-07-31 16:59:49 +0800 | [diff] [blame] | 264 | 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 Cheng | 85a20f6 | 2018-10-25 11:53:11 -0700 | [diff] [blame] | 282 | |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 283 | |
| 284 | def 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 Chiu | 5912054 | 2019-08-15 09:32:32 +0800 | [diff] [blame] | 296 | # Use default=0 to distinguish remote instance or local. The instance type |
| 297 | # will be remote if arg --local-instance is not provided. |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 298 | create_parser.add_argument( |
Sam Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 299 | "--local-instance", |
Sam Chiu | 5912054 | 2019-08-15 09:32:32 +0800 | [diff] [blame] | 300 | type=int, |
| 301 | const=1, |
| 302 | nargs="?", |
cylan | abe0a3a | 2018-08-16 18:50:09 +0800 | [diff] [blame] | 303 | dest="local_instance", |
| 304 | required=False, |
Sam Chiu | 5912054 | 2019-08-15 09:32:32 +0800 | [diff] [blame] | 305 | help="Create a local AVD instance with the option to specify the local " |
| 306 | "instance ID (primarily for infra usage).") |
cylan | abe0a3a | 2018-08-16 18:50:09 +0800 | [diff] [blame] | 307 | create_parser.add_argument( |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 308 | "--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 Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 315 | "--avd-type", |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 316 | type=str, |
| 317 | dest="avd_type", |
| 318 | default=constants.TYPE_CF, |
Richard Fung | 97503b2 | 2019-02-06 13:43:38 -0800 | [diff] [blame] | 319 | choices=[constants.TYPE_GCE, constants.TYPE_CF, constants.TYPE_GF, constants.TYPE_CHEEPS], |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 320 | help="Android Virtual Device type (default %s)." % constants.TYPE_CF) |
| 321 | create_parser.add_argument( |
cylan | abe0a3a | 2018-08-16 18:50:09 +0800 | [diff] [blame] | 322 | "--flavor", |
| 323 | type=str, |
| 324 | dest="flavor", |
cylan | abe0a3a | 2018-08-16 18:50:09 +0800 | [diff] [blame] | 325 | help="The device flavor of the AVD (default %s)." % constants.FLAVOR_PHONE) |
| 326 | create_parser.add_argument( |
Sam Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 327 | "--local-image", |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 328 | type=str, |
| 329 | dest="local_image", |
| 330 | nargs="?", |
| 331 | default="", |
| 332 | required=False, |
Kevin Cheng | 01b58bd | 2018-10-17 16:03:10 -0700 | [diff] [blame] | 333 | 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] | 334 | "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") |
chojoyce | f23e7d5 | 2018-10-15 17:36:35 +0800 | [diff] [blame] | 337 | create_parser.add_argument( |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 338 | "--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 Chen | e76c1bf | 2019-12-23 15:15:47 +0800 | [diff] [blame] | 348 | "--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( |
chojoyce | f23e7d5 | 2018-10-15 17:36:35 +0800 | [diff] [blame] | 358 | "--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.") |
herbertxue | 7ef23b2 | 2019-02-27 09:34:24 +0800 | [diff] [blame] | 363 | 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.")) |
cylan | 2d63351 | 2019-09-09 20:33:42 +0800 | [diff] [blame] | 370 | 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.") |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 381 | create_parser.add_argument( |
| 382 | "--host", |
| 383 | type=str, |
| 384 | dest="remote_host", |
| 385 | default=None, |
cylan | 0f61af6 | 2019-12-30 22:31:10 +0800 | [diff] [blame] | 386 | help="'cuttlefish only' Provide host name to clean up the remote host. " |
| 387 | "For example: '--host 1.1.1.1'") |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 388 | create_parser.add_argument( |
| 389 | "--host-user", |
| 390 | type=str, |
| 391 | dest="host_user", |
cylan | 0f61af6 | 2019-12-30 22:31:10 +0800 | [diff] [blame] | 392 | 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'") |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 396 | 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 Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 402 | # 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 Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 405 | "--hw-property", |
Sam Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 406 | 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.") |
herbertxue | 494891e | 2019-01-19 13:50:53 +0800 | [diff] [blame] | 419 | # 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( |
herbertxue | 494891e | 2019-01-19 13:50:53 +0800 | [diff] [blame] | 423 | "--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 Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 429 | |
Richard Fung | 8d3979e | 2019-06-12 16:00:34 -0700 | [diff] [blame] | 430 | # Arguments for cheeps type. |
| 431 | create_parser.add_argument( |
Shao-Chuan Lee | 8024411 | 2020-02-04 17:14:07 +0900 | [diff] [blame] | 432 | "--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 Fung | 8d3979e | 2019-06-12 16:00:34 -0700 | [diff] [blame] | 450 | "--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 Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 464 | AddCommonCreateArgs(create_parser) |
| 465 | return create_parser |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 466 | |
| 467 | |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 468 | def _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 Chen | e76c1bf | 2019-12-23 15:15:47 +0800 | [diff] [blame] | 500 | 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 | |
chojoyce | 4e2d922 | 2020-01-03 17:04:05 +0800 | [diff] [blame] | 505 | 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 Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 510 | |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 511 | def _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 | |
cylan | 30ab4d6 | 2020-01-06 14:01:09 +0800 | [diff] [blame] | 529 | if args.host_user != constants.GCE_USER and args.remote_host is None: |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 530 | 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 | |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 538 | def VerifyArgs(args): |
| 539 | """Verify args. |
| 540 | |
| 541 | Args: |
| 542 | args: Namespace object from argparse.parse_args. |
| 543 | |
| 544 | Raises: |
herbertxue | fd15dfd | 2018-12-04 11:26:27 +0800 | [diff] [blame] | 545 | errors.UnsupportedFlavor: Flavor doesn't support. |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 546 | errors.UnsupportedMultiAdbPort: multi adb port doesn't support. |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 547 | errors.UnsupportedCreateArgs: When a create arg is specified but |
| 548 | unsupported for a particular avd type. |
| 549 | (e.g. --system-build-id for gf) |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 550 | """ |
herbertxue | fd15dfd | 2018-12-04 11:26:27 +0800 | [diff] [blame] | 551 | # 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)) |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 558 | 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) |
herbertxue | fd15dfd | 2018-12-04 11:26:27 +0800 | [diff] [blame] | 563 | |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 564 | if args.num > 1 and args.adb_port: |
| 565 | raise errors.UnsupportedMultiAdbPort( |
| 566 | "--adb-port is not supported for multi-devices.") |
| 567 | |
herbertxue | 755ad48 | 2019-11-21 11:31:29 +0800 | [diff] [blame] | 568 | if args.num > 1 and args.local_instance is not None: |
| 569 | raise errors.UnsupportedCreateArgs( |
| 570 | "--num is not supported for local instance.") |
| 571 | |
herbertxue | 93630f5 | 2020-03-06 16:06:56 +0800 | [diff] [blame] | 572 | 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 | |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 577 | if args.adb_port: |
| 578 | utils.CheckPortFree(args.adb_port) |
| 579 | |
Sam Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 580 | 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 Fung | 8d3979e | 2019-06-12 16:00:34 -0700 | [diff] [blame] | 586 | |
Shao-Chuan Lee | 8024411 | 2020-02-04 17:14:07 +0900 | [diff] [blame] | 587 | 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 Fung | 8d3979e | 2019-06-12 16:00:34 -0700 | [diff] [blame] | 594 | if (args.username or args.password) and not (args.username and args.password): |
| 595 | raise ValueError("--username and --password must both be set") |
chojoyce | c60fa58 | 2019-07-11 16:09:02 +0800 | [diff] [blame] | 596 | if not args.autoconnect and args.unlock_screen: |
| 597 | raise ValueError("--no-autoconnect and --unlock couldn't be " |
| 598 | "passed in together.") |
Sam Chiu | 5912054 | 2019-08-15 09:32:32 +0800 | [diff] [blame] | 599 | |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 600 | _VerifyLocalArgs(args) |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 601 | _VerifyHostArgs(args) |