当前位置: 首页>>代码示例>>Python>>正文


Python batch_auth.SharedKeyCredentials方法代码示例

本文整理汇总了Python中azure.batch.batch_auth.SharedKeyCredentials方法的典型用法代码示例。如果您正苦于以下问题:Python batch_auth.SharedKeyCredentials方法的具体用法?Python batch_auth.SharedKeyCredentials怎么用?Python batch_auth.SharedKeyCredentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在azure.batch.batch_auth的用法示例。


在下文中一共展示了batch_auth.SharedKeyCredentials方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _create_batch_service_client

# 需要导入模块: from azure.batch import batch_auth [as 别名]
# 或者: from azure.batch.batch_auth import SharedKeyCredentials [as 别名]
def _create_batch_service_client(ctx):
    # type: (CliContext) -> azure.batch.BatchServiceClient
    """Create batch service client
    :param CliContext ctx: Cli Context
    :rtype: azure.batch.BatchServiceClient
    :return: batch service client
    """
    bc = settings.credentials_batch(ctx.config)
    if util.is_none_or_empty(bc.account_key):
        if settings.verbose(ctx.config):
            logger.debug('using aad auth as batch account key not specified')
        batch_aad = settings.credentials_batch(ctx.config).aad
        credentials = aad.create_aad_credentials(ctx, batch_aad)
    else:
        credentials = batchauth.SharedKeyCredentials(
            bc.account, bc.account_key)
    batch_client = azure.batch.BatchServiceClient(
        credentials, batch_url=bc.account_service_url)
    _modify_client_for_retry_and_user_agent(batch_client)
    return batch_client 
开发者ID:Azure,项目名称:batch-shipyard,代码行数:22,代码来源:clients.py

示例2: get_conn

# 需要导入模块: from azure.batch import batch_auth [as 别名]
# 或者: from azure.batch.batch_auth import SharedKeyCredentials [as 别名]
def get_conn(self):
        """
        Get the batch client connection

        :return: Azure batch client
        """
        conn = self._connection()

        def _get_required_param(name):
            """Extract required parameter from extra JSON, raise exception if not found"""
            value = conn.extra_dejson.get(name)
            if not value:
                raise AirflowException(
                    'Extra connection option is missing required parameter: `{}`'.
                    format(name))
            return value
        batch_account_name = _get_required_param('account_name')
        batch_account_key = _get_required_param('account_key')
        batch_account_url = _get_required_param('account_url')
        credentials = batch_auth.SharedKeyCredentials(batch_account_name,
                                                      batch_account_key)
        batch_client = BatchServiceClient(
            credentials,
            batch_url=batch_account_url)
        return batch_client 
开发者ID:apache,项目名称:airflow,代码行数:27,代码来源:azure_batch.py

示例3: _create_batch_service_client

# 需要导入模块: from azure.batch import batch_auth [as 别名]
# 或者: from azure.batch.batch_auth import SharedKeyCredentials [as 别名]
def _create_batch_service_client(ctx):
    # type: (CliContext) -> azure.batch.batch_service_client.BatchServiceClient
    """Create batch service client
    :param CliContext ctx: Cli Context
    :rtype: azure.batch.batch_service_client.BatchServiceClient
    :return: batch service client
    """
    bc = settings.credentials_batch(ctx.config)
    if util.is_none_or_empty(bc.account_key):
        logger.debug('batch account key not specified, using aad auth')
        batch_aad = settings.credentials_batch(ctx.config).aad
        credentials = aad.create_aad_credentials(ctx, batch_aad)
    else:
        credentials = batchauth.SharedKeyCredentials(
            bc.account, bc.account_key)
    batch_client = batchsc.BatchServiceClient(
        credentials, base_url=bc.account_service_url)
    batch_client.config.add_user_agent('batch-shipyard/{}'.format(__version__))
    return batch_client 
开发者ID:Azure,项目名称:cortana-intelligence-inventory-optimization,代码行数:21,代码来源:clients.py

示例4: _create_credentials

# 需要导入模块: from azure.batch import batch_auth [as 别名]
# 或者: from azure.batch.batch_auth import SharedKeyCredentials [as 别名]
def _create_credentials():
    # type: (None) -> azure.batch.batch_service_client.BatchServiceClient
    """Create authenticated client
    :rtype: `azure.batch.batch_service_client.BatchServiceClient`
    :return: batch_client
    """
    ba, url, bakey = os.environ['SHIPYARD_BATCH_ENV'].split(';')
    batch_client = batch.BatchServiceClient(
        batchauth.SharedKeyCredentials(ba, bakey), base_url=url)
    batch_client.config.add_user_agent('batch-shipyard/tfm')
    return batch_client 
开发者ID:Azure,项目名称:cortana-intelligence-inventory-optimization,代码行数:13,代码来源:task_file_mover.py

示例5: _create_credentials

# 需要导入模块: from azure.batch import batch_auth [as 别名]
# 或者: from azure.batch.batch_auth import SharedKeyCredentials [as 别名]
def _create_credentials():
    # type: (None) -> azure.batch.BatchServiceClient
    """Create authenticated client
    :rtype: `azure.batch.BatchServiceClient`
    :return: batch_client
    """
    ba, url, bakey = os.environ['SHIPYARD_BATCH_ENV'].split(';')
    batch_client = azure.batch.BatchServiceClient(
        batchauth.SharedKeyCredentials(ba, bakey), batch_url=url)
    batch_client.config.add_user_agent('batch-shipyard/tfm')
    return batch_client 
开发者ID:Azure,项目名称:batch-shipyard,代码行数:13,代码来源:task_file_mover.py

示例6: get_batch_client

# 需要导入模块: from azure.batch import batch_auth [as 别名]
# 或者: from azure.batch.batch_auth import SharedKeyCredentials [as 别名]
def get_batch_client() -> batch.BatchServiceClient:
    if not batch_resource_id:
        base_url = batch_service_url
        credentials = batchauth.SharedKeyCredentials(batch_account_name, batch_account_key)
    else:
        credentials = ServicePrincipalCredentials(
            client_id=client_id, secret=credential, tenant=tenant_id, resource="https://management.core.windows.net/")
        m = RESOURCE_ID_PATTERN.match(batch_resource_id)
        batch_client = BatchManagementClient(credentials, m.group("subscription"))
        account = batch_client.batch_account.get(m.group("resourcegroup"), m.group("account"))
        base_url = "https://%s/" % account.account_endpoint
        credentials = ServicePrincipalCredentials(
            client_id=client_id, secret=credential, tenant=tenant_id, resource="https://batch.core.windows.net/")

    return batch.BatchServiceClient(credentials, base_url=base_url) 
开发者ID:Azure,项目名称:aztk,代码行数:17,代码来源:config.py

示例7: make_blob_client

# 需要导入模块: from azure.batch import batch_auth [as 别名]
# 或者: from azure.batch.batch_auth import SharedKeyCredentials [as 别名]
def make_blob_client(secrets):
    """
        Creates a blob client object
        :param str storage_account_key: storage account key
        :param str storage_account_name: storage account name
        :param str storage_account_suffix: storage account suffix
    """

    if secrets.shared_key:
        # Set up SharedKeyCredentials
        blob_client = blob.BlockBlobService(
            account_name=secrets.shared_key.storage_account_name,
            account_key=secrets.shared_key.storage_account_key,
            endpoint_suffix=secrets.shared_key.storage_account_suffix,
        )
    else:
        # Set up ServicePrincipalCredentials
        arm_credentials = ServicePrincipalCredentials(
            client_id=secrets.service_principal.client_id,
            secret=secrets.service_principal.credential,
            tenant=secrets.service_principal.tenant_id,
            resource="https://management.core.windows.net/",
        )
        match = RESOURCE_ID_PATTERN.match(secrets.service_principal.storage_account_resource_id)
        accountname = match.group("account")
        subscription = match.group("subscription")
        resourcegroup = match.group("resourcegroup")
        mgmt_client = StorageManagementClient(arm_credentials, subscription)
        key = (retry_function(
            mgmt_client.storage_accounts.list_keys,
            10,
            1,
            Exception,
            resource_group_name=resourcegroup,
            account_name=accountname,
        ).keys[0].value)
        storage_client = CloudStorageAccount(accountname, key)
        blob_client = storage_client.create_block_blob_service()

    return blob_client 
开发者ID:Azure,项目名称:aztk,代码行数:42,代码来源:azure_api.py

示例8: __init__

# 需要导入模块: from azure.batch import batch_auth [as 别名]
# 或者: from azure.batch.batch_auth import SharedKeyCredentials [as 别名]
def __init__(self, config: BatchConfig, common_data, K, verbose=True):

        # replace any missing values in the configuration with environment variables
        config = validate_config(config)

        self.config = config
        self.K = K

        self.blob_client = azureblob.BlockBlobService(
            account_name=config.STORAGE_ACCOUNT_NAME,
            account_key=config.STORAGE_ACCOUNT_KEY,
        )

        # Use the blob client to create the containers in Azure Storage if they
        # don't yet exist.
        self.blob_client.create_container(config.CONTAINER_NAME, fail_on_exist=False)
        self.CONTAINER_SAS_URL = build_output_sas_url(config, self.blob_client)

        # Create a Batch service client. We'll now be interacting with the Batch
        # service in addition to Storage
        self.credentials = batch_auth.SharedKeyCredentials(
            config.BATCH_ACCOUNT_NAME, config.BATCH_ACCOUNT_KEY
        )

        self.batch_client = batch.BatchServiceClient(
            self.credentials, batch_url=config.BATCH_ACCOUNT_URL
        )

        # Upload The common files.
        self.common_file = self.upload_object_to_container(
            self.blob_client, config.CONTAINER_NAME, _GRAD_COMMON_FILE, common_data
        )

        # Create the pool that will contain the compute nodes that will execute the
        # tasks.
        try:
            create_pool(self.config, self.batch_client)
            if verbose:
                print("Created pool: ", self.config.POOL_ID)
        except models.BatchErrorException:
            if verbose:
                print("Using pool: ", self.config.POOL_ID) 
开发者ID:microsoft,项目名称:SparseSC,代码行数:44,代码来源:gradient_batch_client.py

示例9: make_batch_client

# 需要导入模块: from azure.batch import batch_auth [as 别名]
# 或者: from azure.batch.batch_auth import SharedKeyCredentials [as 别名]
def make_batch_client(secrets):
    """
        Creates a batch client object
        :param str batch_account_key: batch account key
        :param str batch_account_name: batch account name
        :param str batch_service_url: batch service url
    """
    # Validate the given config
    credentials = None

    if secrets.shared_key:
        # Set up SharedKeyCredentials
        base_url = secrets.shared_key.batch_service_url
        credentials = batch_auth.SharedKeyCredentials(secrets.shared_key.batch_account_name,
                                                      secrets.shared_key.batch_account_key)
    else:
        # Set up ServicePrincipalCredentials
        arm_credentials = ServicePrincipalCredentials(
            client_id=secrets.service_principal.client_id,
            secret=secrets.service_principal.credential,
            tenant=secrets.service_principal.tenant_id,
            resource="https://management.core.windows.net/",
        )
        m = RESOURCE_ID_PATTERN.match(secrets.service_principal.batch_account_resource_id)
        arm_batch_client = BatchManagementClient(arm_credentials, m.group("subscription"))
        account = arm_batch_client.batch_account.get(m.group("resourcegroup"), m.group("account"))
        base_url = "https://{0}/".format(account.account_endpoint)
        credentials = ServicePrincipalCredentials(
            client_id=secrets.service_principal.client_id,
            secret=secrets.service_principal.credential,
            tenant=secrets.service_principal.tenant_id,
            resource="https://batch.core.windows.net/",
        )

    # Set up Batch Client
    batch_client = batch.BatchServiceClient(credentials, base_url=base_url)

    # Set retry policy
    batch_client.config.retry_policy.retries = 5
    batch_client.config.add_user_agent("aztk/{}".format(__version__))

    return batch_client 
开发者ID:Azure,项目名称:aztk,代码行数:44,代码来源:azure_api.py


注:本文中的azure.batch.batch_auth.SharedKeyCredentials方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。