Skip to content

Commit 526f6da

Browse files
authored
Merge pull request #7 from laurenhughes/master
Update for latest SDK, include config file
2 parents 2e6c688 + 375914a commit 526f6da

File tree

3 files changed

+52
-34
lines changed

3 files changed

+52
-34
lines changed

src/batch_python_tutorial_ffmpeg.py

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import sys
66
import time
7+
import config
78

89
try:
910
input = raw_input
@@ -18,24 +19,10 @@
1819
sys.path.append('.')
1920
sys.path.append('..')
2021

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
2323
# unique to your accounts. These are used when constructing connection strings
2424
# for the Batch and Storage client objects.
2525

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-
3926
def query_yes_no(question, default="yes"):
4027
"""
4128
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):
116103
sas_token=sas_token)
117104

118105
return batchmodels.ResourceFile(file_path=blob_name,
119-
blob_source=sas_url)
106+
http_url=sas_url)
120107

121108
def get_container_sas_token(block_blob_client,
122109
container_name, blob_permissions):
@@ -162,7 +149,7 @@ def get_container_sas_url(block_blob_client,
162149
container_name, azureblob.BlobPermissions.WRITE)
163150

164151
# 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)
166153

167154
return container_sas_url
168155

@@ -198,9 +185,9 @@ def create_pool(batch_service_client, pool_id):
198185
version="latest"
199186
),
200187
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,
204191
start_task=batchmodels.StartTask(
205192
command_line="/bin/bash -c \"apt-get update && apt-get install -y ffmpeg\"",
206193
wait_for_success=True,
@@ -314,8 +301,8 @@ def wait_for_tasks_to_complete(batch_service_client, job_id, timeout):
314301

315302

316303
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)
319306

320307
# Use the blob client to create the containers in Azure Storage if they
321308
# don't yet exist.
@@ -350,29 +337,29 @@ def wait_for_tasks_to_complete(batch_service_client, job_id, timeout):
350337

351338
# Create a Batch service client. We'll now be interacting with the Batch
352339
# 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)
355342

356343
batch_client = batch.BatchServiceClient(
357344
credentials,
358-
base_url=_BATCH_ACCOUNT_URL)
345+
batch_url=config._BATCH_ACCOUNT_URL)
359346

360347
try:
361348
# Create the pool that will contain the compute nodes that will execute the
362349
# tasks.
363-
create_pool(batch_client, _POOL_ID)
350+
create_pool(batch_client, config._POOL_ID)
364351

365352
# 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)
367354

368355
# Add the tasks to the job. Pass the input files and a SAS URL
369356
# 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)
371358

372359
# Pause execution until tasks reach Completed state.
373360
wait_for_tasks_to_complete(batch_client,
374-
_JOB_ID,
375-
datetime.timedelta(minutes=30))
361+
config._JOB_ID,
362+
datetime.timedelta(minutes=30))
376363

377364
print(" Success! All tasks reached the 'Completed' state within the "
378365
"specified timeout period.")
@@ -395,10 +382,10 @@ def wait_for_tasks_to_complete(batch_service_client, job_id, timeout):
395382

396383
# Clean up Batch resources (if the user so chooses).
397384
if query_yes_no('Delete job?') == 'yes':
398-
batch_client.job.delete(_JOB_ID)
385+
batch_client.job.delete(config._JOB_ID)
399386

400387
if query_yes_no('Delete pool?') == 'yes':
401-
batch_client.pool.delete(_POOL_ID)
388+
batch_client.pool.delete(config._POOL_ID)
402389

403390
print()
404391
input('Press ENTER to exit...')

src/config.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#-------------------------------------------------------------------------
2+
#
3+
# THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
4+
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
5+
# OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
6+
#----------------------------------------------------------------------------------
7+
# The example companies, organizations, products, domain names,
8+
# e-mail addresses, logos, people, places, and events depicted
9+
# herein are fictitious. No association with any real company,
10+
# organization, product, domain name, email address, logo, person,
11+
# places, or events is intended or should be inferred.
12+
#--------------------------------------------------------------------------
13+
14+
# Global constant variables (Azure Storage account/Batch details)
15+
16+
# import "config.py" in "batch_python_tutorial_ffmpeg.py"
17+
18+
# Update the Batch and Storage account credential strings below with the values
19+
# unique to your accounts. These are used when constructing connection strings
20+
# for the Batch and Storage client objects.
21+
22+
_BATCH_ACCOUNT_NAME =''
23+
_BATCH_ACCOUNT_KEY = ''
24+
_BATCH_ACCOUNT_URL = ''
25+
_STORAGE_ACCOUNT_NAME = ''
26+
_STORAGE_ACCOUNT_KEY = ''
27+
_POOL_ID = 'LinuxFfmpegPool'
28+
_DEDICATED_POOL_NODE_COUNT = 0
29+
_LOW_PRIORITY_POOL_NODE_COUNT = 5
30+
_POOL_VM_SIZE = 'STANDARD_A1_v2'
31+
_JOB_ID = 'LinuxFfmpegJob'

src/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
azure-batch==5.1.1
2-
azure-storage-blob==1.4.0
1+
azure-batch==6.0.0
2+
azure-storage-blob==1.4.0

0 commit comments

Comments
 (0)