Skip to content

Commit 278daae

Browse files
authored
Update to latest REST API (#95)
* Update to latest CLI/REST API * fix incorrect httpFiles text * Fix help text and incorrect change of mgmt_base_url to mgmt_batch_url * Update test recordings * removing trailing '/' from endpoint * Re record tests * Update os_flavor bug * Add blob source back as a map to http_url and update comments * remove excess url template option * Update to new python model scheme * pylint stuff * Fixup copy paste error for ParamtricSweepFactory * add license headers * Add template not implemented on exceed maximum api version * Add template api check to one more location and add tests * Update samples to 2018
1 parent 8856473 commit 278daae

File tree

106 files changed

+9663
-5974
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+9663
-5974
lines changed

HISTORY.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
SDK Release History
44
===================
55

6+
5.0.0 (2019-02-01)
7+
------------------
8+
9+
* Align to Python SDK for breaking changes to shared models
10+
* This also includes collapsing all models into one models file. Models should now be imported from the models namespace and not from their individual files.
11+
612
4.0.2 (2018-10-06)
713
------------------
814

TEMPLATE-HISTORY.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. :changelog:
2+
3+
Template Release History
4+
===================
5+
6+
2018-12-01
7+
------------------
8+
* Add functionality to have supported template versions to SDK Extensions
9+
* Add functionality to template resource files to support expanded resource file properties
10+
11+
2016-12-01
12+
------------------
13+
* Initial Release

azext/batch/_file_utils.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
import pathlib
1414
from six.moves.urllib.parse import urlsplit # pylint: disable=import-error,relative-import
1515
from six.moves.urllib.parse import quote # pylint: disable=import-error,no-name-in-module,relative-import
16+
from knack.log import get_logger
1617

1718
from azure.storage.blob import BlobPermissions, BlockBlobService
1819
from . import models
1920

21+
logger = get_logger(__name__)
2022

2123
def construct_sas_url(blob, uri):
2224
"""Make up blob URL with container URL"""
@@ -40,7 +42,7 @@ def convert_blobs_to_resource_files(blobs, resource_properties):
4042
file_path = resource_properties.file_path if resource_properties.file_path \
4143
else blobs[0]['filePath']
4244
resource_files.append(models.ExtendedResourceFile(
43-
blob_source=blobs[0]['url'],
45+
http_url=blobs[0]['url'],
4446
file_path=file_path,
4547
))
4648
else:
@@ -53,7 +55,7 @@ def convert_blobs_to_resource_files(blobs, resource_properties):
5355
for blob in blobs:
5456
file_path = '{}{}'.format(base_file_path, blob['filePath'])
5557
resource_files.append(models.ExtendedResourceFile(
56-
blob_source=blob['url'],
58+
http_url=blob['url'],
5759
file_path=file_path
5860
))
5961

@@ -320,16 +322,29 @@ def get_container_list(self, source):
320322

321323
def resolve_resource_file(self, resource_file):
322324
"""Convert new resourceFile reference to server-supported reference"""
323-
if resource_file.blob_source:
325+
if resource_file.http_url:
324326
# Support original resourceFile reference
327+
if not resource_file.file_path:
328+
raise ValueError('Malformed ResourceFile: \'httpUrl\' must '
329+
'also have \'file_path\' attribute')
330+
return [resource_file]
331+
332+
if resource_file.blob_source:
325333
if not resource_file.file_path:
326334
raise ValueError('Malformed ResourceFile: \'blobSource\' must '
327335
'also have \'file_path\' attribute')
336+
resource_file.http_url = resource_file.blob_source
337+
logger.warning('BlobSource has been updated to HttpUrl to reflect new '
338+
'functionality of accepting any http url instead of just storage '
339+
'blobs. Please update your templates to reflect this')
340+
return [resource_file]
341+
342+
if resource_file.storage_container_url or resource_file.auto_storage_container_name:
328343
return [resource_file]
329344

330345
if not hasattr(resource_file, 'source') or not resource_file.source:
331346
raise ValueError('Malformed ResourceFile: Must have either '
332-
' \'source\' or \'blobSource\'')
347+
' \'source\' or \'httpUrl\'')
333348

334349
storage_client = self.resolve_storage_account()
335350
container = None

azext/batch/_template_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def _add_cmd_prefix(task, os_flavor):
215215
if os_flavor == pool_utils.PoolOperatingSystemFlavor.WINDOWS:
216216
# TODO: Do we need windows shell escaping?
217217
task.command_line = 'cmd /c "{}"'.format(task.command_line) #.replace('\"','\\\\\"')
218-
if os_flavor == pool_utils.PoolOperatingSystemFlavor.LINUX:
218+
elif os_flavor == pool_utils.PoolOperatingSystemFlavor.LINUX:
219219
task.command_line = '/bin/bash -c \'set -e; set -o pipefail; {}; wait\''.format(task.command_line)
220220
else:
221221
raise ValueError("Unknown pool OS flavor: " + str(os_flavor))
@@ -846,7 +846,7 @@ def _transform_repeat_task(task, context, index, transformer):
846846
try:
847847
for resource in new_task.resource_files:
848848
_replacement_transform(transformer, resource, 'file_path', context)
849-
_replacement_transform(transformer, resource, 'blob_source', context)
849+
_replacement_transform(transformer, resource, 'http_url', context)
850850
try:
851851
for param in ['file_group', 'prefix', 'container_url', 'url']:
852852
_replacement_transform(transformer, resource.source, param, context)

azext/batch/batch_extensions_client.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,26 @@ class BatchExtensionsClient(BatchServiceClient):
4545
object<msrestazure.azure_active_directory>`
4646
:param api_version: Client API Version.
4747
:type api_version: str
48-
:param str base_url: Batch Service URL
48+
:param str batch_url: Batch Service URL
4949
:param str mgmt_base_uri: Management Service URL
5050
:param str storage_enpoint: Storage Endpoint Suffix
5151
"""
5252

53-
def __init__(self, credentials=None, base_url=None, subscription_id=None,
53+
def __init__(self, credentials=None, batch_url=None, subscription_id=None,
5454
resource_group=None, batch_account=None, storage_client=None,
5555
storage_endpoint=None, mgmt_credentials=None, mgmt_base_url=None):
5656
credentials, mgmt_credentials, subscription_id = self._configure_credentials(
5757
credentials, mgmt_credentials, subscription_id)
58-
super(BatchExtensionsClient, self).__init__(credentials, base_url=base_url)
58+
super(BatchExtensionsClient, self).__init__(credentials, batch_url=batch_url)
5959
self.config.add_user_agent('batchextensionsclient/{}'.format(VERSION))
60-
self._base_url = base_url
60+
self._batch_url = batch_url
61+
if self._batch_url:
62+
self._batch_url = self._batch_url.rstrip('/')
6163
self._mgmt_client = None
6264
self._mgmt_credentials = mgmt_credentials
6365
self._mgmt_base_url = mgmt_base_url
66+
if self._mgmt_base_url:
67+
self._mgmt_base_url = self._mgmt_base_url.rstrip('/')
6468
self._resolved_storage_client = storage_client
6569
self._subscription = subscription_id
6670
self._storage_endpoint = storage_endpoint
@@ -162,7 +166,7 @@ def _storage_account(self):
162166
# Otherwise, we need to parse the URL for a region in order to identify
163167
# the Batch account in the subscription
164168
# Example URL: https://batchaccount.westus.batch.azure.com
165-
region = urlsplit(self.config.base_url).netloc.split('.', 2)[1]
169+
region = urlsplit(self.config.batch_url).netloc.split('.', 2)[1]
166170
accounts = (x for x in client.batch_account.list()
167171
if x.name == self.batch_account and x.location == region)
168172
try:

azext/batch/models/__init__.py

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,72 @@
55

66
# pylint: disable=wildcard-import,unused-import,unused-wildcard-import
77

8-
# Not ideal syntax - but savaes us having to check and repopulate this
8+
# Not ideal syntax - but saves us having to check and repopulate this
99
# list every time the SDK is regenerated.
1010
from azure.batch.models import *
11-
from azure.batch.models.batch_service_client_enums import *
1211

1312
try:
14-
from .extended_task_parameter_py3 import ExtendedTaskParameter
15-
from .extended_job_parameter_py3 import ExtendedJobParameter
16-
from .extended_pool_parameter_py3 import ExtendedPoolParameter
17-
from .extended_pool_specification_py3 import ExtendedPoolSpecification
18-
from .auto_pool_specification_py3 import AutoPoolSpecification
19-
from .output_file_py3 import OutputFile
20-
from .extended_output_file_destination_py3 import ExtendedOutputFileDestination
21-
from .output_file_auto_storage_destination_py3 import OutputFileAutoStorageDestination
22-
from .extended_resource_file_py3 import ExtendedResourceFile
23-
from .multi_instance_settings_py3 import MultiInstanceSettings
24-
from .file_source_py3 import FileSource
25-
from .task_factory_base_py3 import TaskFactoryBase
26-
from .task_collection_task_factory_py3 import TaskCollectionTaskFactory
27-
from .parametric_sweep_task_factory_py3 import ParametricSweepTaskFactory
28-
from .file_collection_task_factory_py3 import FileCollectionTaskFactory
29-
from .parameter_set_py3 import ParameterSet
30-
from .repeat_task_py3 import RepeatTask
31-
from .package_reference_base_py3 import PackageReferenceBase
32-
from .chocolatey_package_reference_py3 import ChocolateyPackageReference
33-
from .yum_package_reference_py3 import YumPackageReference
34-
from .apt_package_reference_py3 import AptPackageReference
35-
from .application_template_info_py3 import ApplicationTemplateInfo
36-
from .merge_task_py3 import MergeTask
37-
from .job_preparation_task_py3 import JobPreparationTask
38-
from .job_release_task_py3 import JobReleaseTask
39-
from .job_manager_task_py3 import JobManagerTask
40-
from .start_task_py3 import StartTask
41-
from .application_template_py3 import ApplicationTemplate
42-
from .job_template_py3 import JobTemplate
43-
from .pool_template_py3 import PoolTemplate
13+
from ._models_py3 import ExtendedTaskParameter
14+
from ._models_py3 import ExtendedJobParameter
15+
from ._models_py3 import ExtendedPoolParameter
16+
from ._models_py3 import ExtendedPoolSpecification
17+
from ._models_py3 import AutoPoolSpecification
18+
from ._models_py3 import OutputFile
19+
from ._models_py3 import ExtendedOutputFileDestination
20+
from ._models_py3 import OutputFileAutoStorageDestination
21+
from ._models_py3 import ExtendedResourceFile
22+
from ._models_py3 import MultiInstanceSettings
23+
from ._models_py3 import FileSource
24+
from ._models_py3 import TaskFactoryBase
25+
from ._models_py3 import TaskCollectionTaskFactory
26+
from ._models_py3 import ParametricSweepTaskFactory
27+
from ._models_py3 import FileCollectionTaskFactory
28+
from ._models_py3 import ParameterSet
29+
from ._models_py3 import RepeatTask
30+
from ._models_py3 import PackageReferenceBase
31+
from ._models_py3 import ChocolateyPackageReference
32+
from ._models_py3 import YumPackageReference
33+
from ._models_py3 import AptPackageReference
34+
from ._models_py3 import ApplicationTemplateInfo
35+
from ._models_py3 import MergeTask
36+
from ._models_py3 import JobPreparationTask
37+
from ._models_py3 import JobReleaseTask
38+
from ._models_py3 import JobManagerTask
39+
from ._models_py3 import StartTask
40+
from ._models_py3 import ApplicationTemplate
41+
from ._models_py3 import JobTemplate
42+
from ._models_py3 import PoolTemplate
4443
except (SyntaxError, ImportError):
45-
from .extended_task_parameter import ExtendedTaskParameter
46-
from .extended_job_parameter import ExtendedJobParameter
47-
from .extended_pool_parameter import ExtendedPoolParameter
48-
from .extended_pool_specification import ExtendedPoolSpecification
49-
from .auto_pool_specification import AutoPoolSpecification
50-
from .output_file import OutputFile
51-
from .extended_output_file_destination import ExtendedOutputFileDestination
52-
from .output_file_auto_storage_destination import OutputFileAutoStorageDestination
53-
from .extended_resource_file import ExtendedResourceFile
54-
from .multi_instance_settings import MultiInstanceSettings
55-
from .file_source import FileSource
56-
from .task_factory_base import TaskFactoryBase
57-
from .task_collection_task_factory import TaskCollectionTaskFactory
58-
from .parametric_sweep_task_factory import ParametricSweepTaskFactory
59-
from .file_collection_task_factory import FileCollectionTaskFactory
60-
from .parameter_set import ParameterSet
61-
from .repeat_task import RepeatTask
62-
from .package_reference_base import PackageReferenceBase
63-
from .chocolatey_package_reference import ChocolateyPackageReference
64-
from .yum_package_reference import YumPackageReference
65-
from .apt_package_reference import AptPackageReference
66-
from .application_template_info import ApplicationTemplateInfo
67-
from .merge_task import MergeTask
68-
from .job_preparation_task import JobPreparationTask
69-
from .job_release_task import JobReleaseTask
70-
from .job_manager_task import JobManagerTask
71-
from .start_task import StartTask
72-
from .application_template import ApplicationTemplate
73-
from .job_template import JobTemplate
74-
from .pool_template import PoolTemplate
44+
from ._models import ExtendedTaskParameter
45+
from ._models import ExtendedJobParameter
46+
from ._models import ExtendedPoolParameter
47+
from ._models import ExtendedPoolSpecification
48+
from ._models import AutoPoolSpecification
49+
from ._models import OutputFile
50+
from ._models import ExtendedOutputFileDestination
51+
from ._models import OutputFileAutoStorageDestination
52+
from ._models import ExtendedResourceFile
53+
from ._models import MultiInstanceSettings
54+
from ._models import FileSource
55+
from ._models import TaskFactoryBase
56+
from ._models import TaskCollectionTaskFactory
57+
from ._models import ParametricSweepTaskFactory
58+
from ._models import FileCollectionTaskFactory
59+
from ._models import ParameterSet
60+
from ._models import RepeatTask
61+
from ._models import PackageReferenceBase
62+
from ._models import ChocolateyPackageReference
63+
from ._models import YumPackageReference
64+
from ._models import AptPackageReference
65+
from ._models import ApplicationTemplateInfo
66+
from ._models import MergeTask
67+
from ._models import JobPreparationTask
68+
from ._models import JobReleaseTask
69+
from ._models import JobManagerTask
70+
from ._models import StartTask
71+
from ._models import ApplicationTemplate
72+
from ._models import JobTemplate
73+
from ._models import PoolTemplate
7574

7675
from .constants import (
7776
PROPS_RESERVED_FOR_JOBS,

0 commit comments

Comments
 (0)