xref: /aosp_15_r20/tools/acloud/create/base_avd_create.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"""BaseAVDCreate class.
17*800a58d9SAndroid Build Coastguard Worker
18*800a58d9SAndroid Build Coastguard WorkerParent class that will hold common logic for AVD creation use cases.
19*800a58d9SAndroid Build Coastguard Worker"""
20*800a58d9SAndroid Build Coastguard Worker
21*800a58d9SAndroid Build Coastguard Workerfrom acloud.internal import constants
22*800a58d9SAndroid Build Coastguard Workerfrom acloud.internal.lib import utils
23*800a58d9SAndroid Build Coastguard Worker
24*800a58d9SAndroid Build Coastguard Worker
25*800a58d9SAndroid Build Coastguard Workerclass BaseAVDCreate():
26*800a58d9SAndroid Build Coastguard Worker    """Base class for all AVD intance creation classes."""
27*800a58d9SAndroid Build Coastguard Worker
28*800a58d9SAndroid Build Coastguard Worker    def _CreateAVD(self, avd_spec, no_prompts):
29*800a58d9SAndroid Build Coastguard Worker        """Do the actual creation work, should be overridden by child classes.
30*800a58d9SAndroid Build Coastguard Worker
31*800a58d9SAndroid Build Coastguard Worker        Args:
32*800a58d9SAndroid Build Coastguard Worker            avd_spec: AVDSpec object that tells us what we're going to create.
33*800a58d9SAndroid Build Coastguard Worker            no_prompts: Boolean, True to skip all prompts.
34*800a58d9SAndroid Build Coastguard Worker        """
35*800a58d9SAndroid Build Coastguard Worker        raise NotImplementedError
36*800a58d9SAndroid Build Coastguard Worker
37*800a58d9SAndroid Build Coastguard Worker    def Create(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        self.PrintAvdDetails(avd_spec)
45*800a58d9SAndroid Build Coastguard Worker        results = self._CreateAVD(avd_spec, no_prompts)
46*800a58d9SAndroid Build Coastguard Worker        utils.PrintDeviceSummary(results)
47*800a58d9SAndroid Build Coastguard Worker        return results
48*800a58d9SAndroid Build Coastguard Worker
49*800a58d9SAndroid Build Coastguard Worker    @staticmethod
50*800a58d9SAndroid Build Coastguard Worker    def PrintAvdDetails(avd_spec):
51*800a58d9SAndroid Build Coastguard Worker        """Display spec information to user.
52*800a58d9SAndroid Build Coastguard Worker
53*800a58d9SAndroid Build Coastguard Worker        Example:
54*800a58d9SAndroid Build Coastguard Worker            Creating remote AVD instance with the following details:
55*800a58d9SAndroid Build Coastguard Worker            Image:
56*800a58d9SAndroid Build Coastguard Worker              aosp/master - aosp_cf_x86_64_phone-userdebug [1234]
57*800a58d9SAndroid Build Coastguard Worker            hw config:
58*800a58d9SAndroid Build Coastguard Worker              cpu - 2
59*800a58d9SAndroid Build Coastguard Worker              ram - 2GB
60*800a58d9SAndroid Build Coastguard Worker              disk - 10GB
61*800a58d9SAndroid Build Coastguard Worker              display - 1024x862 (224 DPI)
62*800a58d9SAndroid Build Coastguard Worker
63*800a58d9SAndroid Build Coastguard Worker        Args:
64*800a58d9SAndroid Build Coastguard Worker            avd_spec: AVDSpec object that tells us what we're going to create.
65*800a58d9SAndroid Build Coastguard Worker        """
66*800a58d9SAndroid Build Coastguard Worker        utils.PrintColorString(
67*800a58d9SAndroid Build Coastguard Worker            "Creating %s AVD instance with the following details:" %
68*800a58d9SAndroid Build Coastguard Worker            avd_spec.instance_type)
69*800a58d9SAndroid Build Coastguard Worker        if avd_spec.image_source == constants.IMAGE_SRC_LOCAL:
70*800a58d9SAndroid Build Coastguard Worker            utils.PrintColorString("Image (local):")
71*800a58d9SAndroid Build Coastguard Worker            utils.PrintColorString("  %s" % (avd_spec.local_image_dir or
72*800a58d9SAndroid Build Coastguard Worker                                             avd_spec.local_image_artifact))
73*800a58d9SAndroid Build Coastguard Worker        elif avd_spec.image_source == constants.IMAGE_SRC_REMOTE:
74*800a58d9SAndroid Build Coastguard Worker            utils.PrintColorString("Image:")
75*800a58d9SAndroid Build Coastguard Worker            utils.PrintColorString(
76*800a58d9SAndroid Build Coastguard Worker                "  %s - %s [%s]" %
77*800a58d9SAndroid Build Coastguard Worker                (avd_spec.remote_image[constants.BUILD_BRANCH],
78*800a58d9SAndroid Build Coastguard Worker                 avd_spec.remote_image[constants.BUILD_TARGET],
79*800a58d9SAndroid Build Coastguard Worker                 avd_spec.remote_image[constants.BUILD_ID]))
80*800a58d9SAndroid Build Coastguard Worker        utils.PrintColorString("hw config:")
81*800a58d9SAndroid Build Coastguard Worker        utils.PrintColorString("  cpu - %s" % (avd_spec.hw_property[constants.HW_ALIAS_CPUS]))
82*800a58d9SAndroid Build Coastguard Worker        utils.PrintColorString("  ram - %dGB" % (
83*800a58d9SAndroid Build Coastguard Worker            int(avd_spec.hw_property[constants.HW_ALIAS_MEMORY]) / 1024))
84*800a58d9SAndroid Build Coastguard Worker        if constants.HW_ALIAS_DISK in avd_spec.hw_property:
85*800a58d9SAndroid Build Coastguard Worker            utils.PrintColorString("  disk - %dGB" % (
86*800a58d9SAndroid Build Coastguard Worker                int(avd_spec.hw_property[constants.HW_ALIAS_DISK]) / 1024))
87*800a58d9SAndroid Build Coastguard Worker        utils.PrintColorString(
88*800a58d9SAndroid Build Coastguard Worker            "  display - %sx%s (%s DPI)" %
89*800a58d9SAndroid Build Coastguard Worker            (avd_spec.hw_property[constants.HW_X_RES],
90*800a58d9SAndroid Build Coastguard Worker             avd_spec.hw_property[constants.HW_Y_RES],
91*800a58d9SAndroid Build Coastguard Worker             avd_spec.hw_property[constants.HW_ALIAS_DPI]))
92*800a58d9SAndroid Build Coastguard Worker        utils.PrintColorString("\n")
93