xref: /aosp_15_r20/tools/acloud/create/local_image_remote_instance.py (revision 800a58d989c669b8eb8a71d8df53b1ba3d411444)
1*800a58d9SAndroid Build Coastguard Worker#!/usr/bin/env python
2*800a58d9SAndroid Build Coastguard Worker#
3*800a58d9SAndroid Build Coastguard Worker# Copyright 2018 - The Android Open Source Project
4*800a58d9SAndroid Build Coastguard Worker#
5*800a58d9SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*800a58d9SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*800a58d9SAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*800a58d9SAndroid Build Coastguard Worker#
9*800a58d9SAndroid Build Coastguard Worker#     http://www.apache.org/licenses/LICENSE-2.0
10*800a58d9SAndroid Build Coastguard Worker#
11*800a58d9SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*800a58d9SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*800a58d9SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*800a58d9SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*800a58d9SAndroid Build Coastguard Worker# limitations under the License.
16*800a58d9SAndroid Build Coastguard Workerr"""LocalImageRemoteInstance class.
17*800a58d9SAndroid Build Coastguard Worker
18*800a58d9SAndroid Build Coastguard WorkerCreate class that is responsible for creating a remote instance AVD with a
19*800a58d9SAndroid Build Coastguard Workerlocal image.
20*800a58d9SAndroid Build Coastguard Worker"""
21*800a58d9SAndroid Build Coastguard Workerfrom acloud.create import create_common
22*800a58d9SAndroid Build Coastguard Workerfrom acloud.create import base_avd_create
23*800a58d9SAndroid Build Coastguard Workerfrom acloud.internal import constants
24*800a58d9SAndroid Build Coastguard Workerfrom acloud.internal.lib import utils
25*800a58d9SAndroid Build Coastguard Workerfrom acloud.public.actions import common_operations
26*800a58d9SAndroid Build Coastguard Workerfrom acloud.public.actions import remote_instance_cf_device_factory
27*800a58d9SAndroid Build Coastguard Workerfrom acloud.public.actions import remote_instance_fvp_device_factory
28*800a58d9SAndroid Build Coastguard Workerfrom acloud.public.actions import remote_instance_trusty_device_factory
29*800a58d9SAndroid Build Coastguard Workerfrom acloud.public import report
30*800a58d9SAndroid Build Coastguard Worker
31*800a58d9SAndroid Build Coastguard Worker
32*800a58d9SAndroid Build Coastguard Workerclass LocalImageRemoteInstance(base_avd_create.BaseAVDCreate):
33*800a58d9SAndroid Build Coastguard Worker    """Create class for a local image remote instance AVD."""
34*800a58d9SAndroid Build Coastguard Worker
35*800a58d9SAndroid Build Coastguard Worker    @utils.TimeExecute(function_description="Total time: ",
36*800a58d9SAndroid Build Coastguard Worker                       print_before_call=False, print_status=False)
37*800a58d9SAndroid Build Coastguard Worker    def _CreateAVD(self, avd_spec, no_prompts):
38*800a58d9SAndroid Build Coastguard Worker        """Create the AVD.
39*800a58d9SAndroid Build Coastguard Worker
40*800a58d9SAndroid Build Coastguard Worker        Args:
41*800a58d9SAndroid Build Coastguard Worker            avd_spec: AVDSpec object that tells us what we're going to create.
42*800a58d9SAndroid Build Coastguard Worker            no_prompts: Boolean, True to skip all prompts.
43*800a58d9SAndroid Build Coastguard Worker
44*800a58d9SAndroid Build Coastguard Worker        Returns:
45*800a58d9SAndroid Build Coastguard Worker            A Report instance.
46*800a58d9SAndroid Build Coastguard Worker        """
47*800a58d9SAndroid Build Coastguard Worker        # AVD type default to CF.
48*800a58d9SAndroid Build Coastguard Worker        command = "create_cf"
49*800a58d9SAndroid Build Coastguard Worker        device_factory = remote_instance_cf_device_factory.RemoteInstanceDeviceFactory(
50*800a58d9SAndroid Build Coastguard Worker            avd_spec,
51*800a58d9SAndroid Build Coastguard Worker            avd_spec.local_image_artifact,
52*800a58d9SAndroid Build Coastguard Worker            create_common.GetCvdHostPackage(avd_spec.cvd_host_package))
53*800a58d9SAndroid Build Coastguard Worker        if avd_spec.avd_type == constants.TYPE_FVP:
54*800a58d9SAndroid Build Coastguard Worker            device_factory = remote_instance_fvp_device_factory.RemoteInstanceDeviceFactory(
55*800a58d9SAndroid Build Coastguard Worker                avd_spec)
56*800a58d9SAndroid Build Coastguard Worker            command = "create_fvp"
57*800a58d9SAndroid Build Coastguard Worker        elif avd_spec.avd_type == constants.TYPE_TRUSTY:
58*800a58d9SAndroid Build Coastguard Worker            device_factory = remote_instance_trusty_device_factory.RemoteInstanceDeviceFactory(
59*800a58d9SAndroid Build Coastguard Worker                avd_spec, avd_spec.local_image_artifact)
60*800a58d9SAndroid Build Coastguard Worker            command = "create_trusty"
61*800a58d9SAndroid Build Coastguard Worker
62*800a58d9SAndroid Build Coastguard Worker        create_report = common_operations.CreateDevices(
63*800a58d9SAndroid Build Coastguard Worker            command, avd_spec.cfg, device_factory,
64*800a58d9SAndroid Build Coastguard Worker            avd_spec.num,
65*800a58d9SAndroid Build Coastguard Worker            report_internal_ip=avd_spec.report_internal_ip,
66*800a58d9SAndroid Build Coastguard Worker            autoconnect=avd_spec.autoconnect,
67*800a58d9SAndroid Build Coastguard Worker            avd_type=avd_spec.avd_type,
68*800a58d9SAndroid Build Coastguard Worker            boot_timeout_secs=avd_spec.boot_timeout_secs,
69*800a58d9SAndroid Build Coastguard Worker            unlock_screen=avd_spec.unlock_screen,
70*800a58d9SAndroid Build Coastguard Worker            wait_for_boot=False,
71*800a58d9SAndroid Build Coastguard Worker            connect_webrtc=avd_spec.connect_webrtc,
72*800a58d9SAndroid Build Coastguard Worker            client_adb_port=avd_spec.client_adb_port)
73*800a58d9SAndroid Build Coastguard Worker        if create_report.status == report.Status.SUCCESS:
74*800a58d9SAndroid Build Coastguard Worker            if avd_spec.connect_vnc:
75*800a58d9SAndroid Build Coastguard Worker                utils.LaunchVNCFromReport(create_report, avd_spec, no_prompts)
76*800a58d9SAndroid Build Coastguard Worker            if avd_spec.connect_webrtc:
77*800a58d9SAndroid Build Coastguard Worker                utils.LaunchBrowserFromReport(create_report)
78*800a58d9SAndroid Build Coastguard Worker
79*800a58d9SAndroid Build Coastguard Worker        return create_report
80