本文整理匯總了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
示例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
示例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
示例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
示例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
示例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)
示例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
示例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)
示例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