-
Notifications
You must be signed in to change notification settings - Fork 482
adding preptask sample #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
manishshar
wants to merge
22
commits into
Azure-Samples:master
Choose a base branch
from
manishshar:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f063036
adding preptask sample
manishshar 4158e9a
adding preptask sample
manishshar 709d301
adding preptask sample
manishshar 0742d87
adding preptask sample
manishshar 4aa8c4d
adding preptask sample
manishshar 845e70b
removing config changes
manishshar 01d0e1d
removing config changes
manishshar 38fe86e
removing config changes
manishshar 90e96f4
removing config changes
manishshar d2cbff6
removing config changes
manishshar 2a23022
removing config changes
manishshar 6f02b87
removing config changes
manishshar 7bb4101
removing config changes
manishshar 9411e8c
removing config changes
manishshar 8247409
removing config changes
manishshar 526f17c
removing config changes
manishshar 024151a
adding change in README.md
manishshar c3977b4
correcting comments
manishshar c68f2eb
correcting comments
manishshar 60f4906
adding suggested changes
manishshar d208210
adding suggested from review
manishshar cfe19e6
adding suggested from review
manishshar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [DEFAULT] | ||
| shoulddeletejob=true | ||
| poolvmsize=small | ||
| poolvmcount=1 | ||
manishshar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| # Sample4_preparationtask.py Code Sample | ||
|
|
||
| from __future__ import print_function | ||
| try: | ||
| import configparser | ||
| except ImportError: | ||
| import ConfigParser as configparser | ||
| import datetime | ||
| import os | ||
|
|
||
| import azure.batch.batch_service_client as batch | ||
| import azure.batch.batch_auth as batchauth | ||
| import azure.batch.models as batchmodels | ||
|
|
||
| import common.helpers | ||
|
|
||
| preptaskcommand = 'cmd /c set' | ||
manishshar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def submit_job_and_add_task(batch_client, job_id, vm_size, vm_count): | ||
| """Submits a job to the Azure Batch service | ||
| and adds a simple task with preparation task | ||
| :param batch_client: The batch client to use. | ||
| :type batch_client: `batchserviceclient.BatchServiceClient` | ||
| :param str job_id: The id of the job to create. | ||
| """ | ||
|
|
||
| pool_info = batchmodels.PoolInformation( | ||
| auto_pool_specification=batchmodels.AutoPoolSpecification( | ||
| auto_pool_id_prefix="Helloworld_jobprep", | ||
| pool=batchmodels.PoolSpecification( | ||
| vm_size=vm_size, | ||
| target_dedicated_nodes=vm_count, | ||
| cloud_service_configuration={'os_family': "4"}), | ||
| keep_alive=False, | ||
| pool_lifetime_option=batchmodels.PoolLifetimeOption.job)) | ||
|
|
||
| job = batchmodels.JobAddParameter( | ||
| id=job_id, | ||
| pool_info=pool_info, | ||
| job_preparation_task=batch.models.JobPreparationTask( | ||
| command_line=preptaskcommand, | ||
manishshar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| wait_for_success=True) | ||
| ) | ||
|
|
||
| batch_client.job.add(job) | ||
|
|
||
| task = batchmodels.TaskAddParameter( | ||
| id="HelloWorld_Task", | ||
| command_line=common.helpers.wrap_commands_in_shell( | ||
| 'windows', ['echo Hello world from the Batch Hello world sample!']) | ||
| ) | ||
|
|
||
| batch_client.task.add(job_id=job.id, task=task) | ||
|
|
||
|
|
||
| def execute_sample(global_config, sample_config): | ||
| """Executes the sample with the specified configurations. | ||
| :param global_config: The global configuration to use. | ||
| :type global_config: `configparser.ConfigParser` | ||
| :param sample_config: The sample specific configuration to use. | ||
| :type sample_config: `configparser.ConfigParser` | ||
| """ | ||
| # Set up the configuration | ||
| batch_account_key = global_config.get('Batch', 'batchaccountkey') | ||
| batch_account_name = global_config.get('Batch', 'batchaccountname') | ||
| batch_service_url = global_config.get('Batch', 'batchserviceurl') | ||
|
|
||
| should_delete_job = sample_config.getboolean( | ||
| 'DEFAULT', | ||
| 'shoulddeletejob') | ||
| pool_vm_size = sample_config.get( | ||
| 'DEFAULT', | ||
| 'poolvmsize') | ||
| pool_vm_count = sample_config.getint( | ||
| 'DEFAULT', | ||
| 'poolvmcount') | ||
|
|
||
| # Print the settings we are running with | ||
| common.helpers.print_configuration(global_config) | ||
| common.helpers.print_configuration(sample_config) | ||
|
|
||
| credentials = batchauth.SharedKeyCredentials( | ||
| batch_account_name, | ||
| batch_account_key) | ||
|
|
||
| batch_client = batch.BatchServiceClient( | ||
| credentials, | ||
| base_url=batch_service_url) | ||
|
|
||
| # Retry 5 times -- default is 3 | ||
| batch_client.config.retry_policy.retries = 5 | ||
| job_id = common.helpers.generate_unique_resource_name("samplePrepJob") | ||
|
|
||
| try: | ||
| submit_job_and_add_task( | ||
| batch_client, | ||
| job_id, | ||
| pool_vm_size, | ||
| pool_vm_count) | ||
|
|
||
| common.helpers.wait_for_tasks_to_complete( | ||
| batch_client, | ||
| job_id, | ||
| datetime.timedelta(minutes=25)) | ||
|
|
||
| tasks = batch_client.task.list(job_id) | ||
| task_ids = [task.id for task in tasks] | ||
|
|
||
| common.helpers.print_task_output(batch_client, job_id, task_ids) | ||
| finally: | ||
| if should_delete_job: | ||
| print("Deleting job: ", job_id) | ||
| batch_client.job.delete(job_id) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| global_config = configparser.ConfigParser() | ||
| global_config.read(common.helpers._SAMPLES_CONFIG_FILE_NAME) | ||
|
|
||
| sample_config = configparser.ConfigParser() | ||
| sample_config.read( | ||
| os.path.splitext(os.path.basename(__file__))[0] + '.cfg') | ||
|
|
||
| execute_sample(global_config, sample_config) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.