xref: /aosp_15_r20/tools/acloud/create/remote_image_remote_host.py (revision 800a58d989c669b8eb8a71d8df53b1ba3d411444)
1*800a58d9SAndroid Build Coastguard Worker#!/usr/bin/env python
2*800a58d9SAndroid Build Coastguard Worker#
3*800a58d9SAndroid Build Coastguard Worker# Copyright 2019 - 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"""RemoteImageRemoteHost class.
17*800a58d9SAndroid Build Coastguard Worker
18*800a58d9SAndroid Build Coastguard WorkerCreate class that is responsible for creating a remote host AVD with a
19*800a58d9SAndroid Build Coastguard Workerremote image.
20*800a58d9SAndroid Build Coastguard Worker"""
21*800a58d9SAndroid Build Coastguard Worker
22*800a58d9SAndroid Build Coastguard Workerimport logging
23*800a58d9SAndroid Build Coastguard Worker
24*800a58d9SAndroid Build Coastguard Workerfrom acloud.create import base_avd_create
25*800a58d9SAndroid Build Coastguard Workerfrom acloud.internal import constants
26*800a58d9SAndroid Build Coastguard Workerfrom acloud.internal.lib import utils
27*800a58d9SAndroid Build Coastguard Workerfrom acloud.public.actions import common_operations
28*800a58d9SAndroid Build Coastguard Workerfrom acloud.public.actions import remote_host_cf_device_factory
29*800a58d9SAndroid Build Coastguard Worker
30*800a58d9SAndroid Build Coastguard Worker
31*800a58d9SAndroid Build Coastguard Workerlogger = logging.getLogger(__name__)
32*800a58d9SAndroid Build Coastguard Worker
33*800a58d9SAndroid Build Coastguard Worker
34*800a58d9SAndroid Build Coastguard Workerclass RemoteImageRemoteHost(base_avd_create.BaseAVDCreate):
35*800a58d9SAndroid Build Coastguard Worker    """Create class for a remote image remote host AVD."""
36*800a58d9SAndroid Build Coastguard Worker
37*800a58d9SAndroid Build Coastguard Worker    @utils.TimeExecute(function_description="Total time: ",
38*800a58d9SAndroid Build Coastguard Worker                       print_before_call=False, print_status=False)
39*800a58d9SAndroid Build Coastguard Worker    def _CreateAVD(self, avd_spec, no_prompts):
40*800a58d9SAndroid Build Coastguard Worker        """Create the AVD.
41*800a58d9SAndroid Build Coastguard Worker        Args:
42*800a58d9SAndroid Build Coastguard Worker            avd_spec: AVDSpec object that tells us what we're going to create.
43*800a58d9SAndroid Build Coastguard Worker            no_prompts: Boolean, True to skip all prompts.
44*800a58d9SAndroid Build Coastguard Worker        Returns:
45*800a58d9SAndroid Build Coastguard Worker            A Report instance.
46*800a58d9SAndroid Build Coastguard Worker        """
47*800a58d9SAndroid Build Coastguard Worker        device_factory = remote_host_cf_device_factory.RemoteHostDeviceFactory(
48*800a58d9SAndroid Build Coastguard Worker            avd_spec=avd_spec)
49*800a58d9SAndroid Build Coastguard Worker        report = common_operations.CreateDevices(
50*800a58d9SAndroid Build Coastguard Worker            "create_cf", avd_spec.cfg, device_factory, num=1,
51*800a58d9SAndroid Build Coastguard Worker            report_internal_ip=avd_spec.report_internal_ip,
52*800a58d9SAndroid Build Coastguard Worker            autoconnect=avd_spec.autoconnect,
53*800a58d9SAndroid Build Coastguard Worker            avd_type=constants.TYPE_CF,
54*800a58d9SAndroid Build Coastguard Worker            boot_timeout_secs=avd_spec.boot_timeout_secs,
55*800a58d9SAndroid Build Coastguard Worker            unlock_screen=avd_spec.unlock_screen,
56*800a58d9SAndroid Build Coastguard Worker            wait_for_boot=False,
57*800a58d9SAndroid Build Coastguard Worker            connect_webrtc=avd_spec.connect_webrtc,
58*800a58d9SAndroid Build Coastguard Worker            ssh_private_key_path=avd_spec.host_ssh_private_key_path,
59*800a58d9SAndroid Build Coastguard Worker            ssh_user=avd_spec.host_user)
60*800a58d9SAndroid Build Coastguard Worker        # Launch vnc client if we're auto-connecting.
61*800a58d9SAndroid Build Coastguard Worker        if avd_spec.connect_vnc:
62*800a58d9SAndroid Build Coastguard Worker            utils.LaunchVNCFromReport(report, avd_spec, no_prompts)
63*800a58d9SAndroid Build Coastguard Worker        return report
64