Exemplo n.º 1
0
    def __init__(self, batchToken: str, armToken: str, account: BatchAccount):
        self.batchCreds = AdalAuthentication(lambda: {
            'accessToken': batchToken,
            'tokenType': 'Bearer'
        })
        self.armCreds = AdalAuthentication(lambda: {
            'accessToken': armToken,
            'tokenType': 'Bearer'
        })
        self.account = account

        self.client = batch.BatchExtensionsClient(
            credentials=self.batchCreds,
            batch_account=self.account.name,
            base_url='https://{0}'.format(account.account_endpoint),
            subscription_id=account.subscription_id,
            mgmt_credentials=self.armCreds)
def batch_extensions_client(cli_ctx, kwargs):  # pylint: disable=unused-argument
    from knack.util import CLIError
    import azext.batch as batch

    account_name = kwargs.pop('account_name', None)
    account_endpoint = kwargs.pop('account_endpoint', None)
    resource_group = kwargs.pop('resource_group', None)
    if account_endpoint and not account_endpoint.startswith('https://'):
        account_endpoint = 'https://' + account_endpoint
    try:
        client = batch.BatchExtensionsClient(base_url=account_endpoint)
    except ValueError as error:
        raise CLIError(str(error))
    client.resource_group = resource_group
    client.batch_account = account_name
    kwargs.pop('account_key', None)
    return client
Exemplo n.º 3
0
def create_batch_client(args: object) -> batch.BatchExtensionsClient:
    """
    Create a batch client using AAD.

    :param args: The list of arguments that come in through the command line
    :type args: ArgumentParser
    :return batch.BatchExtensionsClient: returns the valid batch extension client that used AAD.
    """
    credentials = ServicePrincipalCredentials(
        client_id=args.ServicePrincipalCredentialsClientID,
        secret=args.ServicePrincipalCredentialsSecret,
        tenant=args.ServicePrincipalCredentialsTenant,
        resource=args.ServicePrincipalCredentialsResouce)

    return batch.BatchExtensionsClient(credentials=credentials,
                                       batch_account=args.BatchAccountName,
                                       base_url=args.BatchAccountUrl,
                                       subscription_id=args.BatchAccountSub)
    def __init__(self, test_method):
        super(TestBatchExtensionsLive, self).__init__(__file__, test_method)
        if self.playback:
            self.account_name = 'sdktest2'
            self.account_endpoint = 'https://sdktest2.westcentralus.batch.azure.com'
            self.account_key = 'abc=='
            self.subscription_id = "677f962b-9abf-4423-a27b-0c2f4094dcec"
            storage_account = 'sdkteststore2'
            storage_key = 'abc=='
        else:
            self.account_name = os.environ.get('AZURE_BATCH_ACCOUNT', 'test1')
            self.account_endpoint = os.environ.get(
                'AZURE_BATCH_ENDPOINT',
                'https://test1.westus.batch.azure.com/')
            self.account_key = os.environ['AZURE_BATCH_ACCESS_KEY']
            self.subscription_id = os.environ.get(
                'AZURE_BATCH_SUBSCRIPTION_ID',
                "677f962b-9abf-4423-a27b-0c2f4094dcec")
            storage_account = os.environ.get('AZURE_STORAGE_ACCOUNT',
                                             'testaccountforbatch')
            storage_key = os.environ.get('AZURE_STORAGE_ACCESS_KEY', 'abc==')

        self.data_dir = os.path.join(os.path.dirname(__file__), 'data')
        self.blob_client = CloudStorageAccount(storage_account, storage_key)\
            .create_block_blob_service()
        credentials = batchauth.SharedKeyCredentials(self.account_name,
                                                     self.account_key)
        self.batch_client = batch.BatchExtensionsClient(
            credentials,
            batch_url=self.account_endpoint,
            subscription_id=self.subscription_id,
            batch_account=self.account_name)

        self.output_blob_container = 'aaatestcontainer'
        sas_token = self.blob_client.generate_container_shared_access_signature(
            container_name=self.output_blob_container,
            permission=BlobPermissions(read=True, write=True),
            start=datetime.datetime.utcnow(),
            expiry=datetime.datetime.utcnow() + datetime.timedelta(days=1))
        self.output_container_sas = 'https://{}.blob.core.windows.net/{}?{}'.format(
            storage_account, self.output_blob_container, sas_token)
        print('Full container sas: {}'.format(self.output_container_sas))
Exemplo n.º 5
0
    def __init__(self, test_method):
        super(TestBatchExtensionsLive, self).__init__(__file__, test_method)
        if self.playback:
            self.account_name = 'brkltest'
            self.account_endpoint = 'https://brkltest.eastus2.batch.azure.com/'
            self.account_key = 'ZmFrZV9hY29jdW50X2tleQ=='
            storage_account = 'brkltest'
            storage_key = '1234=='
        else:
            self.account_name = os.environ.get('AZURE_BATCH_ACCOUNT', 'test1')
            self.account_endpoint = os.environ.get(
                'AZURE_BATCH_ENDPOINT',
                'https://test1.westus.batch.azure.com/')
            self.account_key = os.environ['AZURE_BATCH_ACCESS_KEY']
        storage_account = os.environ.get('AZURE_STORAGE_ACCOUNT',
                                         'testaccountforbatch')
        storage_key = os.environ.get('AZURE_STORAGE_ACCESS_KEY',
                                     'ZmFrZV9hY29jdW50X2tleQ==')

        self.blob_client = CloudStorageAccount(storage_account, storage_key)\
            .create_block_blob_service()
        credentials = batchauth.SharedKeyCredentials(self.account_name,
                                                     self.account_key)
        self.batch_client = batch.BatchExtensionsClient(
            credentials, base_url=self.account_endpoint)

        self.output_blob_container = 'aaatestcontainer'
        sas_token = self.blob_client.generate_container_shared_access_signature(
            container_name=self.output_blob_container,
            permission=BlobPermissions(read=True, write=True),
            start=datetime.datetime.utcnow(),
            expiry=datetime.datetime.utcnow() + datetime.timedelta(days=1))
        self.output_container_sas = 'https://{}.blob.core.windows.net/{}?{}'.format(
            storage_account, self.output_blob_container, sas_token)
        self.output_container_sas = 'https://testaccountforbatch.blob.core.windows.net:443/aaatestcontainer'
        print('Full container sas: {}'.format(self.output_container_sas))
Exemplo n.º 6
0
if __name__ == '__main__':

    # Authentication.
    # Note that providing credentials and subscription ID is not required
    # if the Azure CLI is installed and already authenticated.
    creds = ServicePrincipalCredentials(
        client_id=BATCH_CLIENT_ID,
        secret=BATCH_SECRET,
        tenant=BATCH_TENANT,
        resource=BATCH_RESOURCE
    )

    # Setup client
    client = batch.BatchExtensionsClient(
        credentials=creds,
        base_url=BATCH_ENDPOINT,
        batch_account=BATCH_ACCOUNT,
        subscription_id=SUBSCRIPTION_ID)
    
    # Setup test render input data
    scene_file = os.path.join(SAMPLE_DIR, 'blender', 'scene.blend')
    blender_data = 'blender-app-template-data'
    client.file.upload(scene_file, blender_data)

    # Create pool using existing pool template file
    pool_id = 'blender-app-template-test-pool'
    path_to_pool = os.path.join(SAMPLE_DIR, 'blender-appTemplate', 'pool.json')
    with open(path_to_pool, 'r') as template:
        pool_json = json.load(template)
    pool_parameters = {'poolId': pool_id}
    pool_json = client.pool.expand_template(pool_json, pool_parameters)