Microsoft Azure Batch Management Client Library for Python
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Deployment and version management for applications that run on Batch compute nodes, including application packages and version control.
from azure.mgmt.batch.operations import ApplicationOperations, ApplicationPackageOperations
from azure.mgmt.batch.models import Application, ApplicationPackage, ActivateApplicationPackageParameters
from azure.core.paging import ItemPaged
from typing import Union, Optional, IO, AnyCreates new applications within a Batch account for deployment to compute nodes.
def create(
resource_group_name: str,
account_name: str,
application_name: str,
parameters: Application = None,
**kwargs: Any
) -> Application:
"""
Adds an application to the specified Batch account.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
application_name (str): The name of the application
parameters (Application, optional): Application creation parameters
Returns:
Application: The created application
"""Retrieves detailed information about an existing application.
def get(
resource_group_name: str,
account_name: str,
application_name: str,
**kwargs: Any
) -> Application:
"""
Gets information about the specified application.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
application_name (str): The name of the application
Returns:
Application: The application details
"""Updates application properties including display name, default version, and update permissions.
def update(
resource_group_name: str,
account_name: str,
application_name: str,
parameters: Application,
**kwargs: Any
) -> Application:
"""
Updates settings for the specified application.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
application_name (str): The name of the application
parameters (Application): Application update parameters
Returns:
Application: The updated application
"""Deletes an application and all its versions.
def delete(
resource_group_name: str,
account_name: str,
application_name: str,
**kwargs: Any
) -> None:
"""
Deletes an application.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
application_name (str): The name of the application
"""Lists all applications within a Batch account.
def list(
resource_group_name: str,
account_name: str,
maxresults: int = None,
**kwargs: Any
) -> ItemPaged[Application]:
"""
Lists all applications in the specified account.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
maxresults (int, optional): Maximum number of results to return
Returns:
ItemPaged[Application]: Paginated list of applications
"""Application packages contain the binary files deployed to compute nodes for task execution.
Creates an application package record with a storage URL for uploading package contents.
def create(
resource_group_name: str,
account_name: str,
application_name: str,
version_name: str,
parameters: Optional[Union[ApplicationPackage, IO[bytes]]] = None,
**kwargs: Any
) -> ApplicationPackage:
"""
Creates an application package record. The record contains a storageUrl where the package
should be uploaded to. Once uploaded, the ApplicationPackage needs to be activated.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
application_name (str): The name of the application
version_name (str): The version of the application
parameters (ApplicationPackage | IO[bytes], optional): Package parameters
Returns:
ApplicationPackage: The created application package with storage URL
"""Activates an uploaded package to make it available for deployment to compute nodes.
def activate(
resource_group_name: str,
account_name: str,
application_name: str,
version_name: str,
parameters: Union[ActivateApplicationPackageParameters, IO[bytes]],
**kwargs: Any
) -> ApplicationPackage:
"""
Activates the specified application package. This should be done after the
ApplicationPackage was created and uploaded. This needs to be done before an
ApplicationPackage can be used on Pools or Tasks.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
application_name (str): The name of the application
version_name (str): The version of the application
parameters (ActivateApplicationPackageParameters | IO[bytes]): Activation parameters
Returns:
ApplicationPackage: The activated application package
"""Gets information about a specific application package version.
def get(
resource_group_name: str,
account_name: str,
application_name: str,
version_name: str,
**kwargs: Any
) -> ApplicationPackage:
"""
Gets information about the specified application package.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
application_name (str): The name of the application
version_name (str): The version of the application
Returns:
ApplicationPackage: The application package details
"""Deletes an application package record and its associated binary file.
def delete(
resource_group_name: str,
account_name: str,
application_name: str,
version_name: str,
**kwargs: Any
) -> None:
"""
Deletes an application package record and its associated binary file.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
application_name (str): The name of the application
version_name (str): The version of the application
"""Lists all package versions for an application.
def list(
resource_group_name: str,
account_name: str,
application_name: str,
maxresults: Optional[int] = None,
**kwargs: Any
) -> ItemPaged[ApplicationPackage]:
"""
Lists all of the application packages in the specified application.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
application_name (str): The name of the application
maxresults (int, optional): Maximum number of items to return in the response
Returns:
ItemPaged[ApplicationPackage]: An iterator of ApplicationPackage objects
"""class Application:
id: str
name: str
type: str
etag: str
display_name: str
allow_updates: bool
default_version: str
class ApplicationPackage:
id: str
name: str
type: str
etag: str
state: PackageState
format: str
storage_url: str
storage_url_expiry: datetime
last_activation_time: datetime
class ActivateApplicationPackageParameters:
format: str
class ApplicationPackageReference:
id: str
version: str# Create a new application
app_params = {
"display_name": "My Batch Application",
"allow_updates": True
}
application = client.application.create(
"my-resource-group",
"my-batch-account",
"my-app",
app_params
)
print(f"Created application: {application.display_name}")
# Update application settings
update_params = {
"display_name": "Updated Application Name",
"allow_updates": False,
"default_version": "1.0"
}
updated_app = client.application.update(
"my-resource-group",
"my-batch-account",
"my-app",
update_params
)from azure.mgmt.batch.models import ActivateApplicationPackageParameters
# Create a new application package version
package = client.application_package.create(
"my-resource-group",
"my-batch-account",
"my-app",
"1.0"
)
print(f"Package URL for upload: {package.storage_url}")
# Upload your application files to the storage_url
# (This would be done using Azure Storage SDK or REST API)
# Activate the package after uploading files
activation_params = ActivateApplicationPackageParameters(format="zip")
activated_package = client.application_package.activate(
"my-resource-group",
"my-batch-account",
"my-app",
"1.0",
activation_params
)
print(f"Package state: {activated_package.state}")from azure.mgmt.batch.models import ApplicationPackageReference
# Reference application packages in pool configuration
app_packages = [
ApplicationPackageReference(id="my-app", version="1.0"),
ApplicationPackageReference(id="my-other-app", version="2.1")
]
# Use in pool creation (this would be part of a Pool object)
pool_config = {
"application_packages": app_packages,
# ... other pool configuration
}# List all applications
applications = client.application.list("my-resource-group", "my-batch-account")
for app in applications:
print(f"Application: {app.name}, Default Version: {app.default_version}")
# List packages for each application
packages = client.application_package.list(
"my-resource-group",
"my-batch-account",
app.name
)
for package in packages:
print(f" Package: {package.name}, State: {package.state}")Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-batch