# Copyright 2018 - The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. r"""Instance class. Define the instance class used to hold details about an AVD instance. The instance class will hold details about AVD instances (remote/local) used to enable users to understand what instances they've created. This will be leveraged for the list, delete, and reconnect commands. The details include: - instance name (for remote instances) - creation date/instance duration - instance image details (branch/target/build id) - and more! """ import collections import datetime import logging import os import re import subprocess import tempfile # pylint: disable=import-error import dateutil.parser import dateutil.tz from acloud.internal import constants from acloud.internal.lib import cvd_runtime_config from acloud.internal.lib import utils from acloud.internal.lib.adb_tools import AdbTools logger = logging.getLogger(__name__) _ACLOUD_CVD_TEMP = os.path.join(tempfile.gettempdir(), "acloud_cvd_temp") _CVD_RUNTIME_FOLDER_NAME = "cuttlefish_runtime" _CVD_STATUS_BIN = "cvd_status" _MSG_UNABLE_TO_CALCULATE = "Unable to calculate" _RE_GROUP_ADB = "local_adb_port" _RE_GROUP_VNC = "local_vnc_port" _RE_SSH_TUNNEL_PATTERN = (r"((.*\s*-L\s)(?P<%s>\d+):127.0.0.1:%s)" r"((.*\s*-L\s)(?P<%s>\d+):127.0.0.1:%s)" r"(.+%s)") _RE_TIMEZONE = re.compile(r"^(?P