Microsoft Azure Batch Management Client Library for Python
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Management of security certificates for secure communication and authentication in Batch environments, including certificate deployment and lifecycle management.
Creates and installs security certificates on Batch compute nodes.
def create(
resource_group_name: str,
account_name: str,
certificate_name: str,
parameters: CertificateCreateOrUpdateParameters,
if_match: str = None,
if_none_match: str = None,
**kwargs: Any
) -> LROPoller[Certificate]:
"""
Creates a new certificate inside the specified account.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
certificate_name (str): The identifier for the certificate
parameters (CertificateCreateOrUpdateParameters): Certificate parameters
if_match (str, optional): ETag value for conditional operations
if_none_match (str, optional): ETag value for conditional operations
Returns:
LROPoller[Certificate]: Long-running operation poller for the certificate
"""Retrieves detailed information about an existing certificate.
def get(
resource_group_name: str,
account_name: str,
certificate_name: str,
**kwargs: Any
) -> Certificate:
"""
Gets information about the specified certificate.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
certificate_name (str): The identifier for the certificate
Returns:
Certificate: The certificate details
"""Updates certificate properties and configuration.
def update(
resource_group_name: str,
account_name: str,
certificate_name: str,
parameters: CertificateCreateOrUpdateParameters,
if_match: str = None,
**kwargs: Any
) -> LROPoller[Certificate]:
"""
Updates the specified certificate.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
certificate_name (str): The identifier for the certificate
parameters (CertificateCreateOrUpdateParameters): Update parameters
if_match (str, optional): ETag value for conditional operations
Returns:
LROPoller[Certificate]: Long-running operation poller for the update
"""Deletes a certificate from the Batch account.
def delete(
resource_group_name: str,
account_name: str,
certificate_name: str,
**kwargs: Any
) -> LROPoller[None]:
"""
Deletes the specified certificate.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
certificate_name (str): The identifier for the certificate
Returns:
LROPoller[None]: Long-running operation poller for the deletion
"""Lists certificates within a Batch account with optional filtering.
def list_by_batch_account(
resource_group_name: str,
account_name: str,
maxresults: int = None,
select: str = None,
filter: str = None,
**kwargs: Any
) -> ItemPaged[Certificate]:
"""
Lists all certificates 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
select (str, optional): OData select clause
filter (str, optional): OData filter clause
Returns:
ItemPaged[Certificate]: Paginated list of certificates
"""Cancels a failed certificate deletion operation.
def cancel_deletion(
resource_group_name: str,
account_name: str,
certificate_name: str,
**kwargs: Any
) -> Certificate:
"""
Cancels a failed deletion of a certificate from the specified account.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
certificate_name (str): The identifier for the certificate
Returns:
Certificate: The certificate after cancellation
"""class CertificateCreateOrUpdateParameters:
properties: CertificateCreateOrUpdateProperties
class CertificateCreateOrUpdateProperties:
data: str
format: CertificateFormat
password: str
thumbprint: str
thumbprint_algorithm: str
class Certificate:
id: str
name: str
type: str
etag: str
properties: CertificateProperties
class CertificateProperties(CertificateBaseProperties):
provisioning_state: CertificateProvisioningState
provisioning_state_transition_time: datetime
previous_provisioning_state: CertificateProvisioningState
previous_provisioning_state_transition_time: datetime
public_data: str
delete_certificate_error: DeleteCertificateErrorclass CertificateBaseProperties:
thumbprint: str
thumbprint_algorithm: str
format: CertificateFormat
class CertificateReference:
id: str
store_location: CertificateStoreLocation
store_name: str
visibility: list
class DeleteCertificateError:
code: str
message: str
target: str
details: listclass CertificateFormat:
PFX = "Pfx"
CER = "Cer"
class CertificateProvisioningState:
SUCCEEDED = "Succeeded"
DELETING = "Deleting"
FAILED = "Failed"
class CertificateStoreLocation:
CURRENT_USER = "CurrentUser"
LOCAL_MACHINE = "LocalMachine"
class CertificateVisibility:
START_TASK = "StartTask"
TASK = "Task"
REMOTE_USER = "RemoteUser"import base64
from azure.mgmt.batch.models import (
CertificateCreateOrUpdateParameters,
CertificateCreateOrUpdateProperties,
CertificateFormat
)
# Read certificate file
with open("certificate.pfx", "rb") as cert_file:
cert_data = base64.b64encode(cert_file.read()).decode('utf-8')
# Create certificate parameters
cert_properties = CertificateCreateOrUpdateProperties(
data=cert_data,
format=CertificateFormat.PFX,
password="certificate_password",
thumbprint="THUMBPRINT_VALUE"
)
cert_params = CertificateCreateOrUpdateParameters(properties=cert_properties)
# Create the certificate
operation = client.certificate.create(
"my-resource-group",
"my-batch-account",
"my-certificate",
cert_params
)
certificate = operation.result()
print(f"Created certificate: {certificate.name}")
print(f"Provisioning state: {certificate.properties.provisioning_state}")# Read public certificate file
with open("certificate.cer", "rb") as cert_file:
cert_data = base64.b64encode(cert_file.read()).decode('utf-8')
# Create certificate parameters
cert_properties = CertificateCreateOrUpdateProperties(
data=cert_data,
format=CertificateFormat.CER,
thumbprint="THUMBPRINT_VALUE"
# No password needed for CER format
)
cert_params = CertificateCreateOrUpdateParameters(properties=cert_properties)
operation = client.certificate.create(
"my-resource-group",
"my-batch-account",
"my-public-cert",
cert_params
)
certificate = operation.result()from azure.mgmt.batch.models import (
CertificateReference,
CertificateStoreLocation,
CertificateVisibility
)
# Reference certificates in pool configuration
cert_references = [
CertificateReference(
id="/subscriptions/.../certificates/my-certificate",
store_location=CertificateStoreLocation.LOCAL_MACHINE,
store_name="My",
visibility=[CertificateVisibility.START_TASK, CertificateVisibility.TASK]
)
]
# Use in pool creation (this would be part of a Pool object)
pool_config = {
"certificates": cert_references,
# ... other pool configuration
}# List all certificates
certificates = client.certificate.list_by_batch_account(
"my-resource-group",
"my-batch-account"
)
for cert in certificates:
print(f"Certificate: {cert.name}")
print(f"Thumbprint: {cert.properties.thumbprint}")
print(f"State: {cert.properties.provisioning_state}")
# Check for deletion errors
if cert.properties.delete_certificate_error:
error = cert.properties.delete_certificate_error
print(f"Deletion Error: {error.code} - {error.message}")
# Cancel failed deletion if needed
if cert.properties.provisioning_state == "Deleting":
client.certificate.cancel_deletion(
"my-resource-group",
"my-batch-account",
cert.name
)
print("Cancelled failed deletion")# List certificates with filtering
certificates = client.certificate.list_by_batch_account(
"my-resource-group",
"my-batch-account",
maxresults=10,
filter="properties/provisioningState eq 'Succeeded'",
select="name,properties/thumbprint,properties/provisioningState"
)
for cert in certificates:
print(f"Active Certificate: {cert.name} ({cert.properties.thumbprint})")Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-batch