blob: e3e8196c874f93fd37e535d3e3e9ec0a90122fa2 [file] [log] [blame]
Keun Soo Yimb293fdb2016-09-21 16:03:44 -07001#!/usr/bin/env python
2#
3# Copyright 2016 - The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Fang Dengfed6a6f2017-03-01 18:27:28 -080016r"""Cloud Android Driver.
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070017
18This CLI manages google compute engine project for android devices.
19
20- Prerequisites:
21 See: go/acloud-manual
22
23- Configuration:
24 The script takes a required configuration file, which should look like
25 <Start of the file>
26 # If using service account
27 service_account_name: "your_account@developer.gserviceaccount.com"
28 service_account_private_key_path: "/path/to/your-project.p12"
xingdai8a00d462018-07-30 14:24:48 -070029 # Or
30 service_account_json_private_key_path: "/path/to/your-project.json"
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070031
32 # If using OAuth2 authentication flow
33 client_id: <client id created in the project>
34 client_secret: <client secret for the client id>
35
36 # Optional
Fang Deng69498c32017-03-02 14:29:30 -080037 ssh_private_key_path: "~/.ssh/acloud_rsa"
38 ssh_public_key_path: "~/.ssh/acloud_rsa.pub"
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070039 orientation: "portrait"
40 resolution: "800x1280x32x213"
41 network: "default"
42 machine_type: "n1-standard-1"
43 extra_data_disk_size_gb: 10 # 4G or 10G
44
45 # Required
46 project: "your-project"
47 zone: "us-central1-f"
48 storage_bucket_name: "your_google_storage_bucket_name"
49 <End of the file>
50
51 Save it at /path/to/acloud.config
52
53- Example calls:
54 - Create two instances:
Kevin Chengb5963882018-05-09 00:06:27 -070055 $ acloud.par create_cf
56 --build_target aosp_cf_x86_phone-userdebug \
Fang Dengfed6a6f2017-03-01 18:27:28 -080057 --build_id 3744001 --num 2 --config_file /path/to/acloud.config \
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070058 --report_file /tmp/acloud_report.json --log_file /tmp/acloud.log
59
60 - Delete two instances:
61 $ acloud.par delete --instance_names
Fang Dengfed6a6f2017-03-01 18:27:28 -080062 ins-b638cdba-3744001-gce-x86-phone-userdebug-fastbuild3c-linux
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070063 --config_file /path/to/acloud.config
64 --report_file /tmp/acloud_report.json --log_file /tmp/acloud.log
65"""
66import argparse
67import getpass
68import logging
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070069import sys
70
Kevin Chengf4137c62018-05-22 16:06:58 -070071# Needed to silence oauth2client.
Sam Chiu29d858f2018-08-14 20:06:25 +080072# This is a workaround to get rid of below warning message:
73# 'No handlers could be found for logger "oauth2client.contrib.multistore_file'
74# TODO(b/112803893): Remove this code once bug is fixed.
75OAUTH2_LOGGER = logging.getLogger('oauth2client.contrib.multistore_file')
76OAUTH2_LOGGER.setLevel(logging.CRITICAL)
77OAUTH2_LOGGER.addHandler(logging.FileHandler("/dev/null"))
Kevin Chengb5963882018-05-09 00:06:27 -070078
Kevin Chengf4137c62018-05-22 16:06:58 -070079# pylint: disable=wrong-import-position
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070080from acloud.internal import constants
81from acloud.public import acloud_common
82from acloud.public import config
83from acloud.public import device_driver
84from acloud.public import errors
Kevin Chengb5963882018-05-09 00:06:27 -070085from acloud.public.actions import create_cuttlefish_action
86from acloud.public.actions import create_goldfish_action
Kevin Cheng3087af52018-08-13 13:26:50 -070087from acloud.create import create
88from acloud.create import create_args
Kevin Chengee6030f2018-06-26 10:55:30 -070089from acloud.setup import setup
90from acloud.setup import setup_args
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070091
Sam Chiu29d858f2018-08-14 20:06:25 +080092LOGGING_FMT = "%(asctime)s |%(levelname)s| %(name)s:%(lineno)s| %(message)s"
93ACLOUD_LOGGER = "acloud"
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070094
95# Commands
Kevin Chengb5963882018-05-09 00:06:27 -070096CMD_CREATE_CUTTLEFISH = "create_cf"
97CMD_CREATE_GOLDFISH = "create_gf"
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070098CMD_DELETE = "delete"
99CMD_CLEANUP = "cleanup"
Fang Deng69498c32017-03-02 14:29:30 -0800100CMD_SSHKEY = "project_sshkey"
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700101
102
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700103# pylint: disable=too-many-statements
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700104def _ParseArgs(args):
105 """Parse args.
106
107 Args:
108 args: Argument list passed from main.
109
110 Returns:
111 Parsed args.
112 """
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700113 usage = ",".join([
Kevin Chengab0b36b2018-08-02 14:38:30 -0700114 CMD_CLEANUP,
Kevin Chengab0b36b2018-08-02 14:38:30 -0700115 CMD_CREATE_CUTTLEFISH,
116 CMD_CREATE_GOLDFISH,
117 CMD_DELETE,
118 CMD_SSHKEY,
Kevin Cheng3087af52018-08-13 13:26:50 -0700119 create_args.CMD_CREATE,
Kevin Chengee6030f2018-06-26 10:55:30 -0700120 setup_args.CMD_SETUP,
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700121 ])
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700122 parser = argparse.ArgumentParser(
123 description=__doc__,
124 formatter_class=argparse.RawDescriptionHelpFormatter,
Kevin Cheng7ff74be2018-05-23 14:18:55 -0700125 usage="acloud {" + usage + "} ...")
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700126 subparsers = parser.add_subparsers()
127 subparser_list = []
128
129 # Command "create"
Kevin Cheng3087af52018-08-13 13:26:50 -0700130 subparser_list.append(create_args.GetCreateArgParser(subparsers))
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700131
Kevin Chengb5963882018-05-09 00:06:27 -0700132 # Command "create_cf", create cuttlefish instances
133 create_cf_parser = subparsers.add_parser(CMD_CREATE_CUTTLEFISH)
134 create_cf_parser.required = False
135 create_cf_parser.set_defaults(which=CMD_CREATE_CUTTLEFISH)
136 create_cf_parser.add_argument(
137 "--build_target",
138 type=str,
139 dest="build_target",
140 help="Android build target, should be a cuttlefish target name.")
141 create_cf_parser.add_argument(
142 "--branch",
143 type=str,
144 dest="branch",
145 help="Android branch, e.g. git_master")
146 create_cf_parser.add_argument(
147 "--build_id",
148 type=str,
149 dest="build_id",
150 help="Android build id, e.g. 2145099, P2804227")
151 create_cf_parser.add_argument(
152 "--kernel_build_id",
153 type=str,
154 dest="kernel_build_id",
155 required=False,
156 help="Android kernel build id, e.g. 4586590. This is to test a new"
157 " kernel build with a particular Android build (--build_id). If not"
158 " specified, the kernel that's bundled with the Android build would"
159 " be used.")
Kevin Chengb5963882018-05-09 00:06:27 -0700160
Kevin Cheng3087af52018-08-13 13:26:50 -0700161 create_args.AddCommonCreateArgs(create_cf_parser)
Kevin Chengb5963882018-05-09 00:06:27 -0700162 subparser_list.append(create_cf_parser)
163
164 # Command "create_gf", create goldfish instances
165 # In order to create a goldfish device we need the following parameters:
166 # 1. The emulator build we wish to use, this is the binary that emulates
167 # an android device. See go/emu-dev for more
168 # 2. A system-image. This is the android release we wish to run on the
169 # emulated hardware.
170 create_gf_parser = subparsers.add_parser(CMD_CREATE_GOLDFISH)
171 create_gf_parser.required = False
172 create_gf_parser.set_defaults(which=CMD_CREATE_GOLDFISH)
173 create_gf_parser.add_argument(
174 "--build_target",
175 type=str,
176 dest="build_target",
177 help="Android build target, should be a goldfish target name.")
178 create_gf_parser.add_argument(
179 "--branch",
180 type=str,
181 dest="branch",
182 help="Android branch, e.g. git_master")
183 create_gf_parser.add_argument(
184 "--build_id",
185 type=str,
186 dest="build_id",
187 help="Android build id, e.g. 4669424, P2804227")
188 create_gf_parser.add_argument(
189 "--emulator_build_id",
190 type=str,
191 dest="emulator_build_id",
192 required=False,
193 help="Emulator build used to run the images. e.g. 4669466.")
194 create_gf_parser.add_argument(
195 "--gpu",
196 type=str,
197 dest="gpu",
198 required=False,
199 default=None,
200 help="GPU accelerator to use if any."
201 " e.g. nvidia-tesla-k80, omit to use swiftshader")
202 create_gf_parser.add_argument(
Kevin Chengbced4af2018-06-26 10:35:01 -0700203 "--base_image",
204 type=str,
205 dest="base_image",
206 required=False,
207 help="Name of the goldfish base image to be used to create the instance. "
208 "This will override stable_goldfish_host_image_name from config. "
209 "e.g. emu-dev-cts-061118")
Kevin Chengb5963882018-05-09 00:06:27 -0700210
Kevin Cheng3087af52018-08-13 13:26:50 -0700211 create_args.AddCommonCreateArgs(create_gf_parser)
Kevin Chengb5963882018-05-09 00:06:27 -0700212 subparser_list.append(create_gf_parser)
213
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700214 # Command "Delete"
215 delete_parser = subparsers.add_parser(CMD_DELETE)
216 delete_parser.required = False
217 delete_parser.set_defaults(which=CMD_DELETE)
218 delete_parser.add_argument(
219 "--instance_names",
220 dest="instance_names",
221 nargs="+",
222 required=True,
223 help="The names of the instances that need to delete, "
224 "separated by spaces, e.g. --instance_names instance-1 instance-2")
225 subparser_list.append(delete_parser)
226
227 # Command "cleanup"
228 cleanup_parser = subparsers.add_parser(CMD_CLEANUP)
229 cleanup_parser.required = False
230 cleanup_parser.set_defaults(which=CMD_CLEANUP)
231 cleanup_parser.add_argument(
232 "--expiration_mins",
233 type=int,
234 dest="expiration_mins",
235 required=True,
236 help="Garbage collect all gce instances, gce images, cached disk "
237 "images that are older than |expiration_mins|.")
238 subparser_list.append(cleanup_parser)
239
Fang Deng69498c32017-03-02 14:29:30 -0800240 # Command "project_sshkey"
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700241 sshkey_parser = subparsers.add_parser(CMD_SSHKEY)
242 sshkey_parser.required = False
243 sshkey_parser.set_defaults(which=CMD_SSHKEY)
244 sshkey_parser.add_argument(
245 "--user",
246 type=str,
247 dest="user",
248 default=getpass.getuser(),
249 help="The user name which the sshkey belongs to, default to: %s." %
250 getpass.getuser())
251 sshkey_parser.add_argument(
252 "--ssh_rsa_path",
253 type=str,
254 dest="ssh_rsa_path",
255 required=True,
Fang Deng69498c32017-03-02 14:29:30 -0800256 help="Absolute path to the file that contains the public rsa key "
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700257 "that will be added as project-wide ssh key.")
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700258 subparser_list.append(sshkey_parser)
259
Kevin Chengee6030f2018-06-26 10:55:30 -0700260 # Command "setup"
261 subparser_list.append(setup_args.GetSetupArgParser(subparsers))
262
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700263 # Add common arguments.
Kevin Chengb21d7712018-05-24 14:54:55 -0700264 for subparser in subparser_list:
265 acloud_common.AddCommonArguments(subparser)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700266
267 return parser.parse_args(args)
268
269
herbertxueb617e8a2018-08-22 10:02:19 +0800270# TODO(b/112803893): Delete this method once the new create method has been completed.
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700271def _TranslateAlias(parsed_args):
272 """Translate alias to Launch Control compatible values.
273
274 This method translates alias to Launch Control compatible values.
275 - branch: "git_" prefix will be added if branch name doesn't have it.
276 - build_target: For example, "phone" will be translated to full target
277 name "git_x86_phone-userdebug",
278
279 Args:
280 parsed_args: Parsed args.
281
282 Returns:
283 Parsed args with its values being translated.
284 """
Kevin Cheng3087af52018-08-13 13:26:50 -0700285 if parsed_args.which == create_args.CMD_CREATE:
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700286 if (parsed_args.branch and
287 not parsed_args.branch.startswith(constants.BRANCH_PREFIX)):
288 parsed_args.branch = constants.BRANCH_PREFIX + parsed_args.branch
289 parsed_args.build_target = constants.BUILD_TARGET_MAPPING.get(
290 parsed_args.build_target, parsed_args.build_target)
291 return parsed_args
292
293
herbertxue2625b042018-08-16 23:28:20 +0800294# pylint: disable=too-many-branches
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700295def _VerifyArgs(parsed_args):
296 """Verify args.
297
298 Args:
299 parsed_args: Parsed args.
300
301 Raises:
302 errors.CommandArgError: If args are invalid.
303 """
herbertxue2625b042018-08-16 23:28:20 +0800304 if parsed_args.which == create_args.CMD_CREATE:
305 create_args.VerifyArgs(parsed_args)
306
Kevin Cheng3087af52018-08-13 13:26:50 -0700307 if (parsed_args.which == create_args.CMD_CREATE
308 and parsed_args.avd_type == constants.TYPE_GCE):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700309 if (parsed_args.spec and parsed_args.spec not in constants.SPEC_NAMES):
310 raise errors.CommandArgError(
311 "%s is not valid. Choose from: %s" %
312 (parsed_args.spec, ", ".join(constants.SPEC_NAMES)))
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700313 if not ((parsed_args.build_id and parsed_args.build_target)
314 or parsed_args.gce_image or parsed_args.local_disk_image):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700315 raise errors.CommandArgError(
316 "At least one of the following should be specified: "
317 "--build_id and --build_target, or --gce_image, or "
318 "--local_disk_image.")
319 if bool(parsed_args.build_id) != bool(parsed_args.build_target):
320 raise errors.CommandArgError(
321 "Must specify --build_id and --build_target at the same time.")
Kevin Chengb5963882018-05-09 00:06:27 -0700322
Kevin Cheng84d3eed2018-08-16 15:16:00 -0700323 if parsed_args.which == CMD_CREATE_CUTTLEFISH:
Kevin Chengb5963882018-05-09 00:06:27 -0700324 if not parsed_args.build_id or not parsed_args.build_target:
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700325 raise errors.CommandArgError(
326 "Must specify --build_id and --build_target")
Kevin Chengb5963882018-05-09 00:06:27 -0700327
328 if parsed_args.which == CMD_CREATE_GOLDFISH:
Kevin Cheng84d3eed2018-08-16 15:16:00 -0700329 if not parsed_args.emulator_build_id and not parsed_args.build_id:
330 raise errors.CommandArgError("Must specify either "
331 "--emulator_build_id or --build_id")
332 if not parsed_args.build_target:
333 raise errors.CommandArgError("Must specify --build_target")
Kevin Chengb5963882018-05-09 00:06:27 -0700334
335 if parsed_args.which in [
Kevin Cheng3087af52018-08-13 13:26:50 -0700336 create_args.CMD_CREATE, CMD_CREATE_CUTTLEFISH, CMD_CREATE_GOLDFISH
Kevin Chengb5963882018-05-09 00:06:27 -0700337 ]:
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700338 if (parsed_args.serial_log_file
339 and not parsed_args.serial_log_file.endswith(".tar.gz")):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700340 raise errors.CommandArgError(
341 "--serial_log_file must ends with .tar.gz")
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700342 if (parsed_args.logcat_file
343 and not parsed_args.logcat_file.endswith(".tar.gz")):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700344 raise errors.CommandArgError(
345 "--logcat_file must ends with .tar.gz")
346
347
Sam Chiu29d858f2018-08-14 20:06:25 +0800348def _SetupLogging(log_file, verbose):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700349 """Setup logging.
350
Sam Chiu29d858f2018-08-14 20:06:25 +0800351 This function define the logging policy in below manners.
352 - without -v , -vv ,--log_file:
353 Only display critical log and print() message on screen.
354
355 - with -v:
356 Display INFO log and set StreamHandler to acloud parent logger to turn on
357 ONLY acloud modules logging.(silence all 3p libraries)
358
359 - with -vv:
360 Display INFO/DEBUG log and set StreamHandler to root logger to turn on all
361 acloud modules and 3p libraries logging.
362
363 - with --log_file.
364 Dump logs to FileHandler with DEBUG level.
365
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700366 Args:
Sam Chiu29d858f2018-08-14 20:06:25 +0800367 log_file: String, if not None, dump the log to log file.
368 verbose: Int, if verbose = 1(-v), log at INFO level and turn on
369 logging on libraries to a StreamHandler.
370 If verbose = 2(-vv), log at DEBUG level and turn on logging on
371 all libraries and 3rd party libraries to a StreamHandler.
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700372 """
Sam Chiu29d858f2018-08-14 20:06:25 +0800373 # Define logging level and hierarchy by verbosity.
374 shandler_level = None
375 logger = None
376 if verbose == 0:
377 shandler_level = logging.CRITICAL
378 logger = logging.getLogger(ACLOUD_LOGGER)
379 elif verbose == 1:
380 shandler_level = logging.INFO
381 logger = logging.getLogger(ACLOUD_LOGGER)
382 elif verbose > 1:
383 shandler_level = logging.DEBUG
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700384 logger = logging.getLogger()
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700385
Sam Chiu29d858f2018-08-14 20:06:25 +0800386 # Add StreamHandler by default.
387 shandler = logging.StreamHandler()
388 shandler.setFormatter(logging.Formatter(LOGGING_FMT))
389 shandler.setLevel(shandler_level)
390 logger.addHandler(shandler)
391 # Set the default level to DEBUG, the other handlers will handle
392 # their own levels via the args supplied (-v and --log_file).
393 logger.setLevel(logging.DEBUG)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700394
Sam Chiu29d858f2018-08-14 20:06:25 +0800395 # Add FileHandler if log_file is provided.
Sam Chiufde41e92018-08-07 18:37:02 +0800396 if log_file:
Sam Chiu29d858f2018-08-14 20:06:25 +0800397 fhandler = logging.FileHandler(filename=log_file)
398 fhandler.setFormatter(logging.Formatter(LOGGING_FMT))
399 fhandler.setLevel(logging.DEBUG)
400 logger.addHandler(fhandler)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700401
402
403def main(argv):
404 """Main entry.
405
406 Args:
407 argv: A list of system arguments.
408
409 Returns:
410 0 if success. None-zero if fails.
411 """
412 args = _ParseArgs(argv)
Sam Chiu29d858f2018-08-14 20:06:25 +0800413 _SetupLogging(args.log_file, args.verbose)
herbertxueb617e8a2018-08-22 10:02:19 +0800414 # Translation of the branch will happen in AvdSpec(), skip it for now.
415 #args = _TranslateAlias(args)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700416 _VerifyArgs(args)
417
418 config_mgr = config.AcloudConfigManager(args.config_file)
419 cfg = config_mgr.Load()
420 cfg.OverrideWithArgs(args)
421
Kevin Cheng3087af52018-08-13 13:26:50 -0700422 # TODO: Move this check into the functions it is actually needed.
Fang Dengcef4b112017-03-02 11:20:17 -0800423 # Check access.
Kevin Cheng3087af52018-08-13 13:26:50 -0700424 # device_driver.CheckAccess(cfg)
Fang Dengcef4b112017-03-02 11:20:17 -0800425
Kevin Chengee6030f2018-06-26 10:55:30 -0700426 report = None
Kevin Cheng3087af52018-08-13 13:26:50 -0700427 if (args.which == create_args.CMD_CREATE
428 and args.avd_type == constants.TYPE_GCE):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700429 report = device_driver.CreateAndroidVirtualDevices(
430 cfg,
431 args.build_target,
432 args.build_id,
433 args.num,
434 args.gce_image,
435 args.local_disk_image,
436 cleanup=not args.no_cleanup,
437 serial_log_file=args.serial_log_file,
Kevin Chengb5963882018-05-09 00:06:27 -0700438 logcat_file=args.logcat_file,
439 autoconnect=args.autoconnect)
Kevin Cheng3087af52018-08-13 13:26:50 -0700440 elif args.which == create_args.CMD_CREATE:
Kevin Chengc3d0d5e2018-08-14 14:22:44 -0700441 create.Run(args)
Kevin Chengb5963882018-05-09 00:06:27 -0700442 elif args.which == CMD_CREATE_CUTTLEFISH:
443 report = create_cuttlefish_action.CreateDevices(
444 cfg=cfg,
445 build_target=args.build_target,
446 build_id=args.build_id,
447 kernel_build_id=args.kernel_build_id,
448 num=args.num,
449 serial_log_file=args.serial_log_file,
450 logcat_file=args.logcat_file,
451 autoconnect=args.autoconnect)
452 elif args.which == CMD_CREATE_GOLDFISH:
453 report = create_goldfish_action.CreateDevices(
454 cfg=cfg,
455 build_target=args.build_target,
456 build_id=args.build_id,
457 emulator_build_id=args.emulator_build_id,
458 gpu=args.gpu,
459 num=args.num,
460 serial_log_file=args.serial_log_file,
461 logcat_file=args.logcat_file,
Kevin Cheng84d3eed2018-08-16 15:16:00 -0700462 autoconnect=args.autoconnect,
463 branch=args.branch)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700464 elif args.which == CMD_DELETE:
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700465 report = device_driver.DeleteAndroidVirtualDevices(
466 cfg, args.instance_names)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700467 elif args.which == CMD_CLEANUP:
468 report = device_driver.Cleanup(cfg, args.expiration_mins)
469 elif args.which == CMD_SSHKEY:
470 report = device_driver.AddSshRsa(cfg, args.user, args.ssh_rsa_path)
Kevin Chengee6030f2018-06-26 10:55:30 -0700471 elif args.which == setup_args.CMD_SETUP:
herbertxue34776bb2018-07-03 21:57:48 +0800472 setup.Run(args)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700473 else:
474 sys.stderr.write("Invalid command %s" % args.which)
475 return 2
476
Kevin Chengee6030f2018-06-26 10:55:30 -0700477 if report:
478 report.Dump(args.report_file)
479 if report.errors:
480 msg = "\n".join(report.errors)
481 sys.stderr.write("Encountered the following errors:\n%s\n" % msg)
482 return 1
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700483 return 0
Tri Vo8e292532016-10-01 16:55:51 -0700484
485
486if __name__ == "__main__":
487 main(sys.argv[1:])