1# Copyright 2019 - The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14r"""GceLocalImageRemoteInstance class.
15
16Create class that is responsible for creating a gce remote instance AVD with a
17local image.
18"""
19
20import logging
21
22from acloud.create import base_avd_create
23from acloud.internal.lib import utils
24from acloud.public import device_driver
25
26
27logger = logging.getLogger(__name__)
28
29
30class GceLocalImageRemoteInstance(base_avd_create.BaseAVDCreate):
31    """Create class for a gce local image remote instance AVD."""
32
33    @utils.TimeExecute(function_description="Total time: ",
34                       print_before_call=False, print_status=False)
35    def _CreateAVD(self, avd_spec, no_prompts):
36        """Create the AVD.
37
38        Args:
39            avd_spec: AVDSpec object that tells us what we're going to create.
40            no_prompts: Boolean, True to skip all prompts.
41
42        Returns:
43            A Report instance.
44        """
45        logger.info("GCE local image: %s", avd_spec.local_image_artifact)
46
47        report = device_driver.CreateGCETypeAVD(
48            avd_spec.cfg,
49            num=avd_spec.num,
50            local_disk_image=avd_spec.local_image_artifact,
51            autoconnect=avd_spec.autoconnect,
52            report_internal_ip=avd_spec.report_internal_ip,
53            avd_spec=avd_spec)
54
55        # Launch vnc client if we're auto-connecting.
56        if avd_spec.connect_vnc:
57            utils.LaunchVNCFromReport(report, avd_spec, no_prompts)
58
59        return report
60