コード例 #1
0
ファイル: config.py プロジェクト: davidkydd/azure-batch-maya
    def init_from_config(self):
        parsedStorageAccountId = msrestazuretools.parse_resource_id(
            self.storage_account_resource_id)
        self.storage_account = parsedStorageAccountId['name']

        self.storage_mgmt_client = StorageManagementClient(
            self.mgmtCredentials,
            str(self.subscription_id),
            base_url=self.aad_environment_provider.getResourceManager(
                self.aad_environment_id))

        self.storage_key = self._call(
            self.storage_mgmt_client.storage_accounts.list_keys,
            parsedStorageAccountId['resource_group'],
            self.storage_account).keys[0].value

        self._storage = storage.BlockBlobService(self.storage_account,
                                                 self.storage_key)
        self._storage.MAX_SINGLE_PUT_SIZE = 2 * 1024 * 1024

        #TODO refactor move the below shared block into def configureClient(client)
        self._client = batch.BatchExtensionsClient(
            self.batchCredentials,
            base_url=self.batch_url,
            storage_client=self._storage)

        self._client.config.add_user_agent(self._user_agent)
        self._client.threads = self.threads
        self.save_changes()
        self._log = self._configure_logging(self.logging_level)
コード例 #2
0
ファイル: config.py プロジェクト: ns-abe-jun/azure-batch-maya
 def _configure_plugin(self):
     """Set up the the config file, authenticate the SDK clients
     and set up the log file.
     """
     if not os.path.exists(self._data_dir):
         os.makedirs(self._data_dir)
     config_file = os.path.join(self._data_dir, self._ini_file)
     try:
         self._cfg.read(config_file)
         self._storage = storage.BlockBlobService(
             self._cfg.get('AzureBatch', 'storage_account'),
             self._cfg.get('AzureBatch', 'storage_key'),
             endpoint_suffix=self._cfg.get('AzureBatch', 'storage_suffix'))
         self._storage.MAX_SINGLE_PUT_SIZE = 2 * 1024 * 1024
         credentials = SharedKeyCredentials(
             self._cfg.get('AzureBatch', 'batch_account'),
             self._cfg.get('AzureBatch', 'batch_key'))
         self._client = batch.BatchExtensionsClient(
             credentials,
             base_url=self._cfg.get('AzureBatch', 'batch_url'),
             storage_client=self._storage)
         self._client.threads = self._cfg.getint('AzureBatch', 'threads')
         self._client.config.add_user_agent(self._user_agent)
         self._log = self._configure_logging(
             self._cfg.get('AzureBatch', 'logging'))
     except Exception as exp:
         # We should only worry about this if it happens when authenticating
         # using the UI, otherwise it's expected.
         if self.ui:
             raise ValueError("Invalid Configuration: {}".format(exp))
         else:
             # We'll need a place holder logger
             self._log = self._configure_logging(LOG_LEVELS['debug'])
コード例 #3
0
    def __init__(self, batchToken: str, armToken: str, account: BatchAccount):
        self.batchCreds = AdalAuthentication(
            lambda: {'accessToken': batchToken})
        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)
コード例 #4
0
ファイル: config.py プロジェクト: davidkydd/azure-batch-maya
    def init_after_batch_account_selected(self, batchaccount, subscription_id):
        self.batch_account = batchaccount.name
        self.batch_url = "https://" + batchaccount.account_endpoint

        storageAccountId = batchaccount.auto_storage.storage_account_id
        self.storage_account_resource_id = storageAccountId

        parsedStorageAccountId = msrestazuretools.parse_resource_id(
            storageAccountId)
        self.storage_account = parsedStorageAccountId['name']

        self.storage_mgmt_client = StorageManagementClient(
            self.mgmtCredentials,
            str(subscription_id),
            base_url=self.aad_environment_provider.getResourceManager(
                self.aad_environment_id))

        try:
            self.storage_key = self._call(
                self.storage_mgmt_client.storage_accounts.list_keys,
                parsedStorageAccountId['resource_group'],
                self.storage_account).keys[0].value
        except Exception as exp:
            self.remove_old_batch_account_from_config()
            raise exp

        self._storage = storage.BlockBlobService(self.storage_account,
                                                 self.storage_key)
        self._storage.MAX_SINGLE_PUT_SIZE = 2 * 1024 * 1024

        #TODO refactor move the below shared block into def configureClient(client)
        self._client = batch.BatchExtensionsClient(
            self.batchCredentials,
            base_url=self.batch_url,
            storage_client=self._storage)

        self._client.config.add_user_agent(self._user_agent)
        self._client.threads = self.threads
        self._log = self._configure_logging(self.logging_level)
コード例 #5
0
    permissions.
    TODO: Move this into BatchExtensions file utils.
    """
    container_name = fileutils.get_container_name(file_group)
    container_url = fileutils.generate_container_sas_token(
        container_name,
        storage_client,
        permission='rl')
    return container_url


if __name__ == '__main__':
    # Setup client
    storage_client = BlockBlobService(STORAGE_ACCOUNT, STORAGE_KEY, endpoint_suffix="core.windows.net")
    credentials = SharedKeyCredentials(BATCH_ACCOUNT, BATCH_KEY)
    client = batch.BatchExtensionsClient(credentials, base_url=BATCH_ENDPOINT, storage_client=storage_client)

    # Setup test render input data
    scene_file = 'test_scene.mb'
    maya_data = 'maya-data-{}'.format(uuid.uuid4())
    client.file.upload(SAMPLE_DIR, maya_data, flatten=True)
    client.file.upload(os.path.join(SCRIPT_DIR, 'generate_thumbnails.py'), maya_data, flatten=True)

    # Create pool using existing pool template file
    pool_ref = client.pool.get(POOL_ID)
    os_flavor = os_flavor(pool_ref.virtual_machine_configuration.image_reference)
    pool_info = {'poolId': POOL_ID}

    # Create a pool model with an application template reference
    job_id = 'maya_test_{}_{}'.format(os_flavor.lower(), uuid.uuid4())
    batch_parameters = {'id': job_id}