示例#1
0
def get_known_clouds(refresh=False):
    if 'ARM_CLOUD_METADATA_URL' in os.environ:
        from azure.cli.core._session import CLOUD_ENDPOINTS
        endpoints_file = os.path.join(GLOBAL_CONFIG_DIR, 'cloudEndpoints.json')
        CLOUD_ENDPOINTS.load(endpoints_file)
        if refresh:
            CLOUD_ENDPOINTS['clouds'] = {}
        clouds = []
        if CLOUD_ENDPOINTS['clouds']:
            try:
                clouds = [Cloud.from_json(c) for c in CLOUD_ENDPOINTS['clouds']]
                logger.info("Cloud endpoints loaded from local file: %s", endpoints_file)
            except Exception as ex:  # pylint: disable=broad-except
                logger.info("Failed to parse cloud endpoints from local file. CLI will clean it and reload from ARM_CLOUD_METADATA_URL. %s", str(ex))
                CLOUD_ENDPOINTS['clouds'] = {}

        if not CLOUD_ENDPOINTS['clouds']:
            try:
                arm_cloud_dict = json.loads(urlretrieve(os.getenv('ARM_CLOUD_METADATA_URL')))
                cli_cloud_dict = _convert_arm_to_cli(arm_cloud_dict)
                if 'AzureCloud' in cli_cloud_dict:
                    cli_cloud_dict['AzureCloud'].endpoints.active_directory = 'https://login.microsoftonline.com'  # change once active_directory is fixed in ARM for the public cloud
                clouds = list(cli_cloud_dict.values())
                CLOUD_ENDPOINTS['clouds'] = [c.to_json() for c in clouds]
                logger.info("Cloud endpoints loaded from ARM_CLOUD_METADATA_URL: %s", os.getenv('ARM_CLOUD_METADATA_URL'))
            except Exception as ex:  # pylint: disable=broad-except
                logger.warning('Failed to load cloud metadata from the url specified by ARM_CLOUD_METADATA_URL')
                raise ex
        if not clouds:
            raise CLIError("No clouds available. Please ensure ARM_CLOUD_METADATA_URL is valid.")
        return clouds
    return HARD_CODED_CLOUD_LIST
示例#2
0
        storage_endpoint='core.cloudapi.de',
        keyvault_dns='.vault.microsoftazure.de',
        sql_server_hostname='.database.cloudapi.de',
        mysql_server_endpoint='.mysql.database.cloudapi.de',
        postgresql_server_endpoint='.postgres.database.cloudapi.de',
        mariadb_server_endpoint='.mariadb.database.cloudapi.de'))

KNOWN_CLOUDS = [
    AZURE_PUBLIC_CLOUD, AZURE_CHINA_CLOUD, AZURE_US_GOV_CLOUD,
    AZURE_GERMAN_CLOUD
]

if 'ARM_CLOUD_METADATA_URL' in os.environ:
    try:
        arm_cloud_dict = json.loads(
            urlretrieve(os.getenv('ARM_CLOUD_METADATA_URL')))
        cli_cloud_dict = _convert_arm_to_cli(arm_cloud_dict)
        if 'AzureCloud' in cli_cloud_dict:
            cli_cloud_dict['AzureCloud'].endpoints.active_directory = 'https://login.microsoftonline.com'  # pylint: disable=line-too-long # change once active_directory is fixed in ARM for the public cloud
        KNOWN_CLOUDS = list(cli_cloud_dict.values())
    except Exception as ex:  # pylint: disable=broad-except
        logger.warning(
            'Failed to load cloud metadata from the url specified by ARM_CLOUD_METADATA_URL'
        )
        raise ex


def _set_active_cloud(cli_ctx, cloud_name):
    cli_ctx.config.set_value('cloud', 'name', cloud_name)
    cli_ctx.cloud = get_cloud(cli_ctx, cloud_name)
示例#3
0
        vm_image_alias_doc='https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-compute/quickstart-templates/aliases.json',
        media_resource_id='https://rest.media.cloudapi.de',
        ossrdbms_resource_id='https://ossrdbms-aad.database.cloudapi.de'),
    suffixes=CloudSuffixes(
        storage_endpoint='core.cloudapi.de',
        keyvault_dns='.vault.microsoftazure.de',
        sql_server_hostname='.database.cloudapi.de',
        mysql_server_endpoint='.mysql.database.cloudapi.de',
        postgresql_server_endpoint='.postgres.database.cloudapi.de',
        mariadb_server_endpoint='.mariadb.database.cloudapi.de'))

KNOWN_CLOUDS = [AZURE_PUBLIC_CLOUD, AZURE_CHINA_CLOUD, AZURE_US_GOV_CLOUD, AZURE_GERMAN_CLOUD]

if 'ARM_CLOUD_METADATA_URL' in os.environ:
    try:
        arm_cloud_dict = json.loads(urlretrieve(os.getenv('ARM_CLOUD_METADATA_URL')))
        cli_cloud_dict = _convert_arm_to_cli(arm_cloud_dict)
        if 'AzureCloud' in cli_cloud_dict:
            cli_cloud_dict['AzureCloud'].endpoints.active_directory = 'https://login.microsoftonline.com'  # change once active_directory is fixed in ARM for the public cloud
        KNOWN_CLOUDS = list(cli_cloud_dict.values())
    except Exception as ex:  # pylint: disable=broad-except
        logger.warning('Failed to load cloud metadata from the url specified by ARM_CLOUD_METADATA_URL')
        raise ex


def _set_active_cloud(cli_ctx, cloud_name):
    cli_ctx.config.set_value('cloud', 'name', cloud_name)
    cli_ctx.cloud = get_cloud(cli_ctx, cloud_name)


def get_active_cloud_name(cli_ctx):