Skip to content

Commit 9037f00

Browse files
xingwu1matthchr
authored andcommitted
Update samples with latest python SDK (#283)
1 parent ce1a53a commit 9037f00

File tree

8 files changed

+28
-24
lines changed

8 files changed

+28
-24
lines changed

Python/Batch/article_samples/mpi/linux_mpi_task_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
pass
3737

3838
import azure.storage.blob as azureblob
39-
import azure.batch.batch_service_client as batch
39+
import azure.batch._batch_service_client as batch
4040
import azure.batch.batch_auth as batchauth
4141
import azure.batch.models as batchmodels
4242
import multi_task_helpers

Python/Batch/article_samples/mpi/multi_task_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
except NameError:
3636
pass
3737

38-
import azure.batch.batch_service_client as batch
38+
import azure.batch._batch_service_client as batch
3939
import azure.batch.models as batchmodels
4040

4141
sys.path.append('.')

Python/Batch/common/helpers.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,22 @@ def select_latest_verified_vm_image_with_node_agent_sku(
7676
:return: (node agent sku id to use, vm image ref to use)
7777
"""
7878
# get verified vm image list and node agent sku ids from service
79-
node_agent_skus = batch_client.account.list_node_agent_skus()
79+
options = batchmodels.AccountListSupportedImagesOptions(
80+
filter="verificationType eq 'verified'")
81+
images = batch_client.account.list_supported_images(
82+
account_list_supported_images_options=options)
83+
8084
# pick the latest supported sku
8185
skus_to_use = [
82-
(sku, image_ref) for sku in node_agent_skus for image_ref in sorted(
83-
sku.verified_image_references, key=lambda item: item.sku)
84-
if image_ref.publisher.lower() == publisher.lower() and
85-
image_ref.offer.lower() == offer.lower() and
86-
image_ref.sku.startswith(sku_starts_with)
86+
(image.node_agent_sku_id, image.image_reference) for image in images
87+
if image.image_reference.publisher.lower() == publisher.lower() and
88+
image.image_reference.offer.lower() == offer.lower() and
89+
image.image_reference.sku.startswith(sku_starts_with)
8790
]
88-
# skus are listed in reverse order, pick first for latest
89-
sku_to_use, image_ref_to_use = skus_to_use[0]
90-
return (sku_to_use.id, image_ref_to_use)
91+
92+
# pick first
93+
agent_sku_id, image_ref_to_use = skus_to_use[0]
94+
return (agent_sku_id, image_ref_to_use)
9195

9296

9397
def wait_for_tasks_to_complete(batch_client, job_id, timeout):
@@ -527,14 +531,15 @@ def wait_for_job_under_job_schedule(batch_client, job_schedule_id, timeout):
527531
:param timeout: The maximum amount of time to wait.
528532
:type timeout: `datetime.timedelta`
529533
"""
530-
cloud_job_schedule = batch_client.job_schedule.get(
531-
job_schedule_id=job_schedule_id)
532-
533534
time_to_timeout_at = datetime.datetime.now() + timeout
534535

535536
while datetime.datetime.now() < time_to_timeout_at:
537+
cloud_job_schedule = batch_client.job_schedule.get(
538+
job_schedule_id=job_schedule_id)
539+
536540
print("Checking if job exists...")
537-
if cloud_job_schedule.execution_info.recent_job.id is not None:
541+
if (cloud_job_schedule.execution_info.recent_job) and (
542+
cloud_job_schedule.execution_info.recent_job.id is not None):
538543
return cloud_job_schedule.execution_info.recent_job.id
539544
time.sleep(1)
540545

@@ -550,11 +555,10 @@ def wait_for_job_schedule_to_complete(batch_client, job_schedule_id, timeout):
550555
:param timeout: The maximum amount of time to wait.
551556
:type timeout: `datetime.datetime`
552557
"""
553-
554-
cloud_job_schedule = batch_client.job_schedule.get(
555-
job_schedule_id=job_schedule_id)
556-
557558
while datetime.datetime.now() < timeout:
559+
cloud_job_schedule = batch_client.job_schedule.get(
560+
job_schedule_id=job_schedule_id)
561+
558562
print("Checking if job schedule is complete...")
559563
state = cloud_job_schedule.state
560564
if state == batchmodels.JobScheduleState.completed:

Python/Batch/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
azure-batch==6.0.0
1+
azure-batch==8.0.0
22
azure-storage-blob==1.3.1

Python/Batch/sample1_helloworld.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import datetime
3333
import os
3434

35-
import azure.batch.batch_service_client as batch
35+
import azure.batch._batch_service_client as batch
3636
import azure.batch.batch_auth as batchauth
3737
import azure.batch.models as batchmodels
3838

Python/Batch/sample2_pools_and_resourcefiles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import os
3434

3535
import azure.storage.blob as azureblob
36-
import azure.batch.batch_service_client as batch
36+
import azure.batch._batch_service_client as batch
3737
import azure.batch.batch_auth as batchauth
3838
import azure.batch.models as batchmodels
3939

Python/Batch/sample3_encrypted_resourcefiles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import subprocess
3636

3737
import azure.storage.blob as azureblob
38-
import azure.batch.batch_service_client as batch
38+
import azure.batch._batch_service_client as batch
3939
import azure.batch.batch_auth as batchauth
4040
import azure.batch.models as batchmodels
4141

Python/Batch/sample4_job_scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import datetime
3535
import os
3636

37-
import azure.batch.batch_service_client as batch
37+
import azure.batch._batch_service_client as batch
3838
import azure.storage.blob as azureblob
3939
import azure.batch.batch_auth as batchauth
4040
import azure.batch.models as batchmodels

0 commit comments

Comments
 (0)