File: //lib/python3.6/site-packages/cloudinit/sources/DataSourceAliYun.py
# This file is part of cloud-init. See LICENSE file for license information.
import logging
from cloudinit import dmi, sources
from cloudinit.sources import DataSourceApsara as apsara
LOG = logging.getLogger(__name__)
ALIYUN_PRODUCT = "Alibaba Cloud ECS"
class DataSourceAliYun(apsara.DataSourceApsara):
dsname = "AliYun"
def _get_cloud_name(self):
if _is_aliyun():
return self.dsname.lower()
return "NO_ALIYUN_METADATA"
@property
def imdsv2_token_put_header(self):
return "X-aliyun-ecs-metadata-token"
def _is_aliyun():
return dmi.read_dmi_data("system-product-name") == ALIYUN_PRODUCT
class DataSourceAliYunLocal(DataSourceAliYun):
"""Datasource run at init-local which sets up network to query metadata.
In init-local, no network is available. This subclass sets up minimal
networking with dhclient on a viable nic so that it can talk to the
metadata service. If the metadata service provides network configuration
then render the network configuration for that instance based on metadata.
"""
perform_dhcp_setup = True
# Used to match classes to dependencies
datasources = [
(DataSourceAliYunLocal, (sources.DEP_FILESYSTEM,)), # Run at init-local
(DataSourceAliYun, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)),
]
# Return a list of data sources that match this set of dependencies
def get_datasource_list(depends):
return sources.list_from_depends(depends, datasources)
# vi: ts=4 expandtab