blob: 30e18be556b1daa584f896678974f3538de934e0 [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.
Sam Chiu42ac7c52018-10-22 12:27:34 +080016r"""
17Welcome to
18 ___ _______ ____ __ _____
19 / _ |/ ___/ / / __ \/ / / / _ \
20 / __ / /__/ /__/ /_/ / /_/ / // /
21/_/ |_\___/____/\____/\____/____/
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070022
Sam Chiu42ac7c52018-10-22 12:27:34 +080023
24This a tool to create Android Virtual Devices locally/remotely.
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070025
26- Prerequisites:
Sam Chiu42ac7c52018-10-22 12:27:34 +080027 The manual will be available at
28 https://android.googlesource.com/platform/tools/acloud/+/master/README.md
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070029
Sam Chiu42ac7c52018-10-22 12:27:34 +080030- To get started:
31 - Create instances:
32 1) To create a remote cuttlefish instance with the local built image.
33 Example:
34 $ acloud create --local_image /tmp/image_dir
35 2) To create a local cuttlefish instance using the image which has been
36 built out in your workspace.
37 Example:
38 $ acloud create --local-instance --local-image
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070039
Sam Chiu42ac7c52018-10-22 12:27:34 +080040 - Delete instances:
41 $ acloud delete
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070042
Sam Chiu42ac7c52018-10-22 12:27:34 +080043Try $acloud [cmd] --help for further details.
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070044
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070045"""
46import argparse
47import getpass
48import logging
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070049import sys
50
Kevin Chengf4137c62018-05-22 16:06:58 -070051# Needed to silence oauth2client.
Sam Chiu29d858f2018-08-14 20:06:25 +080052# This is a workaround to get rid of below warning message:
53# 'No handlers could be found for logger "oauth2client.contrib.multistore_file'
54# TODO(b/112803893): Remove this code once bug is fixed.
55OAUTH2_LOGGER = logging.getLogger('oauth2client.contrib.multistore_file')
56OAUTH2_LOGGER.setLevel(logging.CRITICAL)
57OAUTH2_LOGGER.addHandler(logging.FileHandler("/dev/null"))
Kevin Chengb5963882018-05-09 00:06:27 -070058
Kevin Chengf4137c62018-05-22 16:06:58 -070059# pylint: disable=wrong-import-position
Kevin Cheng6001db32018-10-23 12:34:20 -070060from acloud.create import create
61from acloud.create import create_args
62from acloud.delete import delete
63from acloud.delete import delete_args
cylan4569dca2018-11-02 12:12:53 +080064from acloud.reconnect import reconnect
65from acloud.reconnect import reconnect_args
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070066from acloud.internal import constants
Sam Chiu56c58892018-10-25 09:53:19 +080067from acloud.list import list as list_instances
68from acloud.list import list_args
Kevin Cheng6001db32018-10-23 12:34:20 -070069from acloud.metrics import metrics
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070070from acloud.public import acloud_common
71from acloud.public import config
72from acloud.public import device_driver
73from acloud.public import errors
Kevin Chengb5963882018-05-09 00:06:27 -070074from acloud.public.actions import create_cuttlefish_action
75from acloud.public.actions import create_goldfish_action
Kevin Chengee6030f2018-06-26 10:55:30 -070076from acloud.setup import setup
77from acloud.setup import setup_args
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070078
Sam Chiu445941f2018-10-04 11:54:40 +080079LOGGING_FMT = "%(asctime)s |%(levelname)s| %(module)s:%(lineno)s| %(message)s"
Sam Chiu29d858f2018-08-14 20:06:25 +080080ACLOUD_LOGGER = "acloud"
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070081
82# Commands
Kevin Chengb5963882018-05-09 00:06:27 -070083CMD_CREATE_CUTTLEFISH = "create_cf"
84CMD_CREATE_GOLDFISH = "create_gf"
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070085CMD_CLEANUP = "cleanup"
Fang Deng69498c32017-03-02 14:29:30 -080086CMD_SSHKEY = "project_sshkey"
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070087
88
Kevin Cheng3031f8a2018-05-16 13:21:51 -070089# pylint: disable=too-many-statements
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070090def _ParseArgs(args):
91 """Parse args.
92
93 Args:
94 args: Argument list passed from main.
95
96 Returns:
97 Parsed args.
98 """
Kevin Cheng3031f8a2018-05-16 13:21:51 -070099 usage = ",".join([
Sam Chiue669ef72018-10-16 16:23:37 +0800100 setup_args.CMD_SETUP,
101 create_args.CMD_CREATE,
Kevin Chengab0b36b2018-08-02 14:38:30 -0700102 CMD_CREATE_CUTTLEFISH,
103 CMD_CREATE_GOLDFISH,
Sam Chiu56c58892018-10-25 09:53:19 +0800104 list_args.CMD_LIST,
Kevin Chengeb85e862018-10-09 15:35:13 -0700105 delete_args.CMD_DELETE,
cylan4569dca2018-11-02 12:12:53 +0800106 reconnect_args.CMD_RECONNECT,
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700107 ])
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700108 parser = argparse.ArgumentParser(
109 description=__doc__,
110 formatter_class=argparse.RawDescriptionHelpFormatter,
Sam Chiu42ac7c52018-10-22 12:27:34 +0800111 usage="acloud {" + usage + "} ...")
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700112 subparsers = parser.add_subparsers()
113 subparser_list = []
114
Kevin Chengb5963882018-05-09 00:06:27 -0700115 # Command "create_cf", create cuttlefish instances
116 create_cf_parser = subparsers.add_parser(CMD_CREATE_CUTTLEFISH)
117 create_cf_parser.required = False
118 create_cf_parser.set_defaults(which=CMD_CREATE_CUTTLEFISH)
119 create_cf_parser.add_argument(
120 "--build_target",
121 type=str,
122 dest="build_target",
123 help="Android build target, should be a cuttlefish target name.")
124 create_cf_parser.add_argument(
125 "--branch",
126 type=str,
127 dest="branch",
128 help="Android branch, e.g. git_master")
129 create_cf_parser.add_argument(
130 "--build_id",
131 type=str,
132 dest="build_id",
133 help="Android build id, e.g. 2145099, P2804227")
134 create_cf_parser.add_argument(
135 "--kernel_build_id",
136 type=str,
137 dest="kernel_build_id",
138 required=False,
139 help="Android kernel build id, e.g. 4586590. This is to test a new"
140 " kernel build with a particular Android build (--build_id). If not"
141 " specified, the kernel that's bundled with the Android build would"
142 " be used.")
Kevin Chengb5963882018-05-09 00:06:27 -0700143
Kevin Cheng3087af52018-08-13 13:26:50 -0700144 create_args.AddCommonCreateArgs(create_cf_parser)
Kevin Chengb5963882018-05-09 00:06:27 -0700145 subparser_list.append(create_cf_parser)
146
147 # Command "create_gf", create goldfish instances
148 # In order to create a goldfish device we need the following parameters:
149 # 1. The emulator build we wish to use, this is the binary that emulates
150 # an android device. See go/emu-dev for more
151 # 2. A system-image. This is the android release we wish to run on the
152 # emulated hardware.
153 create_gf_parser = subparsers.add_parser(CMD_CREATE_GOLDFISH)
154 create_gf_parser.required = False
155 create_gf_parser.set_defaults(which=CMD_CREATE_GOLDFISH)
156 create_gf_parser.add_argument(
157 "--build_target",
158 type=str,
159 dest="build_target",
160 help="Android build target, should be a goldfish target name.")
161 create_gf_parser.add_argument(
162 "--branch",
163 type=str,
164 dest="branch",
165 help="Android branch, e.g. git_master")
166 create_gf_parser.add_argument(
167 "--build_id",
168 type=str,
169 dest="build_id",
170 help="Android build id, e.g. 4669424, P2804227")
171 create_gf_parser.add_argument(
172 "--emulator_build_id",
173 type=str,
174 dest="emulator_build_id",
175 required=False,
176 help="Emulator build used to run the images. e.g. 4669466.")
177 create_gf_parser.add_argument(
178 "--gpu",
179 type=str,
180 dest="gpu",
181 required=False,
182 default=None,
183 help="GPU accelerator to use if any."
184 " e.g. nvidia-tesla-k80, omit to use swiftshader")
185 create_gf_parser.add_argument(
Kevin Chengbced4af2018-06-26 10:35:01 -0700186 "--base_image",
187 type=str,
188 dest="base_image",
189 required=False,
190 help="Name of the goldfish base image to be used to create the instance. "
191 "This will override stable_goldfish_host_image_name from config. "
192 "e.g. emu-dev-cts-061118")
Kevin Chengb5963882018-05-09 00:06:27 -0700193
Kevin Cheng3087af52018-08-13 13:26:50 -0700194 create_args.AddCommonCreateArgs(create_gf_parser)
Kevin Chengb5963882018-05-09 00:06:27 -0700195 subparser_list.append(create_gf_parser)
196
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700197 # Command "cleanup"
198 cleanup_parser = subparsers.add_parser(CMD_CLEANUP)
199 cleanup_parser.required = False
200 cleanup_parser.set_defaults(which=CMD_CLEANUP)
201 cleanup_parser.add_argument(
202 "--expiration_mins",
203 type=int,
204 dest="expiration_mins",
205 required=True,
206 help="Garbage collect all gce instances, gce images, cached disk "
207 "images that are older than |expiration_mins|.")
208 subparser_list.append(cleanup_parser)
209
Fang Deng69498c32017-03-02 14:29:30 -0800210 # Command "project_sshkey"
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700211 sshkey_parser = subparsers.add_parser(CMD_SSHKEY)
212 sshkey_parser.required = False
213 sshkey_parser.set_defaults(which=CMD_SSHKEY)
214 sshkey_parser.add_argument(
215 "--user",
216 type=str,
217 dest="user",
218 default=getpass.getuser(),
219 help="The user name which the sshkey belongs to, default to: %s." %
220 getpass.getuser())
221 sshkey_parser.add_argument(
222 "--ssh_rsa_path",
223 type=str,
224 dest="ssh_rsa_path",
225 required=True,
Fang Deng69498c32017-03-02 14:29:30 -0800226 help="Absolute path to the file that contains the public rsa key "
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700227 "that will be added as project-wide ssh key.")
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700228 subparser_list.append(sshkey_parser)
229
Kevin Chengeb85e862018-10-09 15:35:13 -0700230 # Command "create"
231 subparser_list.append(create_args.GetCreateArgParser(subparsers))
232
Kevin Chengee6030f2018-06-26 10:55:30 -0700233 # Command "setup"
234 subparser_list.append(setup_args.GetSetupArgParser(subparsers))
235
Sam Chiu56c58892018-10-25 09:53:19 +0800236 # Command "delete"
Kevin Chengeb85e862018-10-09 15:35:13 -0700237 subparser_list.append(delete_args.GetDeleteArgParser(subparsers))
238
Sam Chiu56c58892018-10-25 09:53:19 +0800239 # Command "list"
240 subparser_list.append(list_args.GetListArgParser(subparsers))
241
cylan4569dca2018-11-02 12:12:53 +0800242 # Command "Reconnect"
243 subparser_list.append(reconnect_args.GetReconnectArgParser(subparsers))
244
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700245 # Add common arguments.
Kevin Chengb21d7712018-05-24 14:54:55 -0700246 for subparser in subparser_list:
247 acloud_common.AddCommonArguments(subparser)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700248
249 return parser.parse_args(args)
250
251
herbertxue2625b042018-08-16 23:28:20 +0800252# pylint: disable=too-many-branches
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700253def _VerifyArgs(parsed_args):
254 """Verify args.
255
256 Args:
257 parsed_args: Parsed args.
258
259 Raises:
260 errors.CommandArgError: If args are invalid.
261 """
herbertxue2625b042018-08-16 23:28:20 +0800262 if parsed_args.which == create_args.CMD_CREATE:
263 create_args.VerifyArgs(parsed_args)
264
Kevin Cheng3087af52018-08-13 13:26:50 -0700265 if (parsed_args.which == create_args.CMD_CREATE
266 and parsed_args.avd_type == constants.TYPE_GCE):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700267 if (parsed_args.spec and parsed_args.spec not in constants.SPEC_NAMES):
268 raise errors.CommandArgError(
269 "%s is not valid. Choose from: %s" %
270 (parsed_args.spec, ", ".join(constants.SPEC_NAMES)))
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700271 if not ((parsed_args.build_id and parsed_args.build_target)
272 or parsed_args.gce_image or parsed_args.local_disk_image):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700273 raise errors.CommandArgError(
274 "At least one of the following should be specified: "
275 "--build_id and --build_target, or --gce_image, or "
276 "--local_disk_image.")
277 if bool(parsed_args.build_id) != bool(parsed_args.build_target):
278 raise errors.CommandArgError(
279 "Must specify --build_id and --build_target at the same time.")
Kevin Chengb5963882018-05-09 00:06:27 -0700280
Kevin Cheng84d3eed2018-08-16 15:16:00 -0700281 if parsed_args.which == CMD_CREATE_CUTTLEFISH:
Kevin Chengb5963882018-05-09 00:06:27 -0700282 if not parsed_args.build_id or not parsed_args.build_target:
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700283 raise errors.CommandArgError(
284 "Must specify --build_id and --build_target")
Kevin Chengb5963882018-05-09 00:06:27 -0700285
286 if parsed_args.which == CMD_CREATE_GOLDFISH:
Kevin Cheng84d3eed2018-08-16 15:16:00 -0700287 if not parsed_args.emulator_build_id and not parsed_args.build_id:
288 raise errors.CommandArgError("Must specify either "
289 "--emulator_build_id or --build_id")
290 if not parsed_args.build_target:
291 raise errors.CommandArgError("Must specify --build_target")
Kevin Chengb5963882018-05-09 00:06:27 -0700292
293 if parsed_args.which in [
Kevin Cheng3087af52018-08-13 13:26:50 -0700294 create_args.CMD_CREATE, CMD_CREATE_CUTTLEFISH, CMD_CREATE_GOLDFISH
Kevin Chengb5963882018-05-09 00:06:27 -0700295 ]:
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700296 if (parsed_args.serial_log_file
297 and not parsed_args.serial_log_file.endswith(".tar.gz")):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700298 raise errors.CommandArgError(
299 "--serial_log_file must ends with .tar.gz")
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700300 if (parsed_args.logcat_file
301 and not parsed_args.logcat_file.endswith(".tar.gz")):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700302 raise errors.CommandArgError(
303 "--logcat_file must ends with .tar.gz")
304
305
Sam Chiu29d858f2018-08-14 20:06:25 +0800306def _SetupLogging(log_file, verbose):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700307 """Setup logging.
308
Sam Chiu29d858f2018-08-14 20:06:25 +0800309 This function define the logging policy in below manners.
310 - without -v , -vv ,--log_file:
311 Only display critical log and print() message on screen.
312
313 - with -v:
314 Display INFO log and set StreamHandler to acloud parent logger to turn on
315 ONLY acloud modules logging.(silence all 3p libraries)
316
317 - with -vv:
318 Display INFO/DEBUG log and set StreamHandler to root logger to turn on all
319 acloud modules and 3p libraries logging.
320
321 - with --log_file.
322 Dump logs to FileHandler with DEBUG level.
323
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700324 Args:
Sam Chiu29d858f2018-08-14 20:06:25 +0800325 log_file: String, if not None, dump the log to log file.
326 verbose: Int, if verbose = 1(-v), log at INFO level and turn on
327 logging on libraries to a StreamHandler.
328 If verbose = 2(-vv), log at DEBUG level and turn on logging on
329 all libraries and 3rd party libraries to a StreamHandler.
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700330 """
Sam Chiu29d858f2018-08-14 20:06:25 +0800331 # Define logging level and hierarchy by verbosity.
332 shandler_level = None
333 logger = None
334 if verbose == 0:
335 shandler_level = logging.CRITICAL
336 logger = logging.getLogger(ACLOUD_LOGGER)
337 elif verbose == 1:
338 shandler_level = logging.INFO
339 logger = logging.getLogger(ACLOUD_LOGGER)
340 elif verbose > 1:
341 shandler_level = logging.DEBUG
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700342 logger = logging.getLogger()
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700343
Sam Chiu29d858f2018-08-14 20:06:25 +0800344 # Add StreamHandler by default.
345 shandler = logging.StreamHandler()
346 shandler.setFormatter(logging.Formatter(LOGGING_FMT))
347 shandler.setLevel(shandler_level)
348 logger.addHandler(shandler)
349 # Set the default level to DEBUG, the other handlers will handle
350 # their own levels via the args supplied (-v and --log_file).
351 logger.setLevel(logging.DEBUG)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700352
Sam Chiu29d858f2018-08-14 20:06:25 +0800353 # Add FileHandler if log_file is provided.
Sam Chiufde41e92018-08-07 18:37:02 +0800354 if log_file:
Sam Chiu29d858f2018-08-14 20:06:25 +0800355 fhandler = logging.FileHandler(filename=log_file)
356 fhandler.setFormatter(logging.Formatter(LOGGING_FMT))
357 fhandler.setLevel(logging.DEBUG)
358 logger.addHandler(fhandler)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700359
360
Erwin Jansen95559242018-11-08 15:38:18 -0800361def main(argv=None):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700362 """Main entry.
363
364 Args:
365 argv: A list of system arguments.
366
367 Returns:
368 0 if success. None-zero if fails.
369 """
Erwin Jansen95559242018-11-08 15:38:18 -0800370 if argv is None:
371 argv = sys.argv[1:]
372
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700373 args = _ParseArgs(argv)
Sam Chiu29d858f2018-08-14 20:06:25 +0800374 _SetupLogging(args.log_file, args.verbose)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700375 _VerifyArgs(args)
376
Sam Chiuc64f3432018-08-17 11:19:06 +0800377 cfg = config.GetAcloudConfig(args)
Kevin Cheng3087af52018-08-13 13:26:50 -0700378 # TODO: Move this check into the functions it is actually needed.
Fang Dengcef4b112017-03-02 11:20:17 -0800379 # Check access.
Kevin Cheng3087af52018-08-13 13:26:50 -0700380 # device_driver.CheckAccess(cfg)
Fang Dengcef4b112017-03-02 11:20:17 -0800381
Kevin Cheng6001db32018-10-23 12:34:20 -0700382 metrics.LogUsage()
Kevin Chengee6030f2018-06-26 10:55:30 -0700383 report = None
Kevin Cheng3087af52018-08-13 13:26:50 -0700384 if (args.which == create_args.CMD_CREATE
385 and args.avd_type == constants.TYPE_GCE):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700386 report = device_driver.CreateAndroidVirtualDevices(
387 cfg,
388 args.build_target,
389 args.build_id,
390 args.num,
391 args.gce_image,
392 args.local_disk_image,
393 cleanup=not args.no_cleanup,
394 serial_log_file=args.serial_log_file,
Kevin Chengb5963882018-05-09 00:06:27 -0700395 logcat_file=args.logcat_file,
Kevin Cheng86d43c72018-08-30 10:59:14 -0700396 autoconnect=args.autoconnect,
397 report_internal_ip=args.report_internal_ip)
Kevin Cheng3087af52018-08-13 13:26:50 -0700398 elif args.which == create_args.CMD_CREATE:
Kevin Chengc3d0d5e2018-08-14 14:22:44 -0700399 create.Run(args)
Kevin Chengb5963882018-05-09 00:06:27 -0700400 elif args.which == CMD_CREATE_CUTTLEFISH:
401 report = create_cuttlefish_action.CreateDevices(
402 cfg=cfg,
403 build_target=args.build_target,
404 build_id=args.build_id,
405 kernel_build_id=args.kernel_build_id,
406 num=args.num,
407 serial_log_file=args.serial_log_file,
408 logcat_file=args.logcat_file,
Kevin Cheng86d43c72018-08-30 10:59:14 -0700409 autoconnect=args.autoconnect,
410 report_internal_ip=args.report_internal_ip)
Kevin Chengb5963882018-05-09 00:06:27 -0700411 elif args.which == CMD_CREATE_GOLDFISH:
412 report = create_goldfish_action.CreateDevices(
413 cfg=cfg,
414 build_target=args.build_target,
415 build_id=args.build_id,
416 emulator_build_id=args.emulator_build_id,
417 gpu=args.gpu,
418 num=args.num,
419 serial_log_file=args.serial_log_file,
420 logcat_file=args.logcat_file,
Kevin Cheng84d3eed2018-08-16 15:16:00 -0700421 autoconnect=args.autoconnect,
Kevin Cheng86d43c72018-08-30 10:59:14 -0700422 branch=args.branch,
423 report_internal_ip=args.report_internal_ip)
Sam Chiu56c58892018-10-25 09:53:19 +0800424 elif args.which == delete_args.CMD_DELETE:
Kevin Chengeb85e862018-10-09 15:35:13 -0700425 report = delete.Run(args)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700426 elif args.which == CMD_CLEANUP:
427 report = device_driver.Cleanup(cfg, args.expiration_mins)
Sam Chiu56c58892018-10-25 09:53:19 +0800428 elif args.which == list_args.CMD_LIST:
429 list_instances.Run(args)
cylan4569dca2018-11-02 12:12:53 +0800430 elif args.which == reconnect_args.CMD_RECONNECT:
431 reconnect.Run(args)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700432 elif args.which == CMD_SSHKEY:
433 report = device_driver.AddSshRsa(cfg, args.user, args.ssh_rsa_path)
Kevin Chengee6030f2018-06-26 10:55:30 -0700434 elif args.which == setup_args.CMD_SETUP:
herbertxue34776bb2018-07-03 21:57:48 +0800435 setup.Run(args)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700436 else:
437 sys.stderr.write("Invalid command %s" % args.which)
438 return 2
439
herbertxue07293a32018-11-05 20:40:11 +0800440 if report and args.report_file:
Kevin Chengee6030f2018-06-26 10:55:30 -0700441 report.Dump(args.report_file)
442 if report.errors:
443 msg = "\n".join(report.errors)
444 sys.stderr.write("Encountered the following errors:\n%s\n" % msg)
445 return 1
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700446 return 0
Tri Vo8e292532016-10-01 16:55:51 -0700447
448
449if __name__ == "__main__":
450 main(sys.argv[1:])