Python 用 Azure Scheduler ライブラリ

ライブラリをインストールする

管理

pip install azure-mgmt-scheduler

管理クライアントを作成する

管理クライアントのインスタンスは、以下のコードで作成します。

サブスクリプションの一覧から取得できる をsubscription_id指定する必要があります。

Python SDK を使用した Azure Active Directory の認証処理と Credentials インスタンスの作成について詳しくは、「Resource Management Authentication (リソース管理の認証)」を参照してください。

from azure.mgmt.scheduler import SchedulerManagementClient
from azure.common.credentials import UserPassCredentials

# Replace this with your subscription id
subscription_id = '33333333-3333-3333-3333-333333333333'

# See above for details on creating different types of AAD credentials
credentials = UserPassCredentials(
    'user@domain.com',	# Your user
    'my_password',		# Your password
)

scheduler_client = SchedulerManagementClient(
    credentials,
    subscription_id
)

ジョブ コレクションの作成

以下のコードは、既存のリソース グループにジョブ コレクションを作成するものです。 リソース グループの作成と管理については、リソース管理に関するページを参照してください。

from azure.mgmt.scheduler.models import JobCollectionDefinition, JobCollectionProperties, Sku

group_name = 'myresourcegroup'
job_collection_name = "myjobcollection"
scheduler_client.job_collections.create_or_update(
    group_name,
    job_collection_name,
    JobCollectionDefinition(
        location = "West US",
        properties = JobCollectionProperties(
            sku = Sku(
                name="Free"
            )
        )
    )
)
# scheduler_client is a JobCollectionDefinition instance