4
4
import os
5
5
import sys
6
6
import time
7
+ import config
7
8
8
9
try :
9
10
input = raw_input
18
19
sys .path .append ('.' )
19
20
sys .path .append ('..' )
20
21
21
-
22
- # Update the Batch and Storage account credential strings below with the values
22
+ # Update the Batch and Storage account credential strings in config.py with values
23
23
# unique to your accounts. These are used when constructing connection strings
24
24
# for the Batch and Storage client objects.
25
25
26
- # global
27
- _BATCH_ACCOUNT_NAME = ''
28
- _BATCH_ACCOUNT_KEY = ''
29
- _BATCH_ACCOUNT_URL = ''
30
- _STORAGE_ACCOUNT_NAME = ''
31
- _STORAGE_ACCOUNT_KEY = ''
32
- _POOL_ID = 'LinuxFfmpegPool'
33
- _DEDICATED_POOL_NODE_COUNT = 0
34
- _LOW_PRIORITY_POOL_NODE_COUNT = 5
35
- _POOL_VM_SIZE = 'STANDARD_A1_v2'
36
- _JOB_ID = 'LinuxFfmpegJob'
37
-
38
-
39
26
def query_yes_no (question , default = "yes" ):
40
27
"""
41
28
Prompts the user for yes/no input, displaying the specified question text.
@@ -116,7 +103,7 @@ def upload_file_to_container(block_blob_client, container_name, file_path):
116
103
sas_token = sas_token )
117
104
118
105
return batchmodels .ResourceFile (file_path = blob_name ,
119
- blob_source = sas_url )
106
+ http_url = sas_url )
120
107
121
108
def get_container_sas_token (block_blob_client ,
122
109
container_name , blob_permissions ):
@@ -162,7 +149,7 @@ def get_container_sas_url(block_blob_client,
162
149
container_name , azureblob .BlobPermissions .WRITE )
163
150
164
151
# Construct SAS URL for the container
165
- container_sas_url = "https://{}.blob.core.windows.net/{}?{}" .format (_STORAGE_ACCOUNT_NAME , container_name , sas_token )
152
+ container_sas_url = "https://{}.blob.core.windows.net/{}?{}" .format (config . _STORAGE_ACCOUNT_NAME , container_name , sas_token )
166
153
167
154
return container_sas_url
168
155
@@ -198,9 +185,9 @@ def create_pool(batch_service_client, pool_id):
198
185
version = "latest"
199
186
),
200
187
node_agent_sku_id = "batch.node.ubuntu 18.04" ),
201
- vm_size = _POOL_VM_SIZE ,
202
- target_dedicated_nodes = _DEDICATED_POOL_NODE_COUNT ,
203
- target_low_priority_nodes = _LOW_PRIORITY_POOL_NODE_COUNT ,
188
+ vm_size = config . _POOL_VM_SIZE ,
189
+ target_dedicated_nodes = config . _DEDICATED_POOL_NODE_COUNT ,
190
+ target_low_priority_nodes = config . _LOW_PRIORITY_POOL_NODE_COUNT ,
204
191
start_task = batchmodels .StartTask (
205
192
command_line = "/bin/bash -c \" apt-get update && apt-get install -y ffmpeg\" " ,
206
193
wait_for_success = True ,
@@ -314,8 +301,8 @@ def wait_for_tasks_to_complete(batch_service_client, job_id, timeout):
314
301
315
302
316
303
blob_client = azureblob .BlockBlobService (
317
- account_name = _STORAGE_ACCOUNT_NAME ,
318
- account_key = _STORAGE_ACCOUNT_KEY )
304
+ account_name = config . _STORAGE_ACCOUNT_NAME ,
305
+ account_key = config . _STORAGE_ACCOUNT_KEY )
319
306
320
307
# Use the blob client to create the containers in Azure Storage if they
321
308
# don't yet exist.
@@ -350,29 +337,29 @@ def wait_for_tasks_to_complete(batch_service_client, job_id, timeout):
350
337
351
338
# Create a Batch service client. We'll now be interacting with the Batch
352
339
# service in addition to Storage
353
- credentials = batchauth .SharedKeyCredentials (_BATCH_ACCOUNT_NAME ,
354
- _BATCH_ACCOUNT_KEY )
340
+ credentials = batchauth .SharedKeyCredentials (config . _BATCH_ACCOUNT_NAME ,
341
+ config . _BATCH_ACCOUNT_KEY )
355
342
356
343
batch_client = batch .BatchServiceClient (
357
344
credentials ,
358
- base_url = _BATCH_ACCOUNT_URL )
345
+ batch_url = config . _BATCH_ACCOUNT_URL )
359
346
360
347
try :
361
348
# Create the pool that will contain the compute nodes that will execute the
362
349
# tasks.
363
- create_pool (batch_client , _POOL_ID )
350
+ create_pool (batch_client , config . _POOL_ID )
364
351
365
352
# Create the job that will run the tasks.
366
- create_job (batch_client , _JOB_ID , _POOL_ID )
353
+ create_job (batch_client , config . _JOB_ID , config . _POOL_ID )
367
354
368
355
# Add the tasks to the job. Pass the input files and a SAS URL
369
356
# to the storage container for output files.
370
- add_tasks (batch_client , _JOB_ID , input_files , output_container_sas_url )
357
+ add_tasks (batch_client , config . _JOB_ID , input_files , output_container_sas_url )
371
358
372
359
# Pause execution until tasks reach Completed state.
373
360
wait_for_tasks_to_complete (batch_client ,
374
- _JOB_ID ,
375
- datetime .timedelta (minutes = 30 ))
361
+ config . _JOB_ID ,
362
+ datetime .timedelta (minutes = 30 ))
376
363
377
364
print (" Success! All tasks reached the 'Completed' state within the "
378
365
"specified timeout period." )
@@ -395,10 +382,10 @@ def wait_for_tasks_to_complete(batch_service_client, job_id, timeout):
395
382
396
383
# Clean up Batch resources (if the user so chooses).
397
384
if query_yes_no ('Delete job?' ) == 'yes' :
398
- batch_client .job .delete (_JOB_ID )
385
+ batch_client .job .delete (config . _JOB_ID )
399
386
400
387
if query_yes_no ('Delete pool?' ) == 'yes' :
401
- batch_client .pool .delete (_POOL_ID )
388
+ batch_client .pool .delete (config . _POOL_ID )
402
389
403
390
print ()
404
391
input ('Press ENTER to exit...' )
0 commit comments