コード例 #1
0
def migrate_task_os(table_service: TableService) -> None:
    table_name = "Task"
    tasks = table_service.query_entities(
        table_name, select="PartitionKey,RowKey,os,config")
    partitionKey = None

    count = 0
    batch = TableBatch()
    for task in tasks:
        if partitionKey != task.PartitionKey:
            table_service.commit_batch(table_name, batch)
            batch = TableBatch()

        partitionKey = task.PartitionKey
        if "os" not in task or (not task.os):
            config = json.loads(task.config)
            print(config)
            if "windows".lower() in config["vm"]["image"].lower():
                task["os"] = "windows"
            else:
                task["os"] = "linux"
            count = count + 1
        batch.merge_entity(task)
    table_service.commit_batch(table_name, batch)
    print("migrated %s rows" % count)
コード例 #2
0
from azure.cosmosdb.table.tableservice import TableService
from azure.cosmosdb.table.models import Entity

# Let's import the batch library
from azure.cosmosdb.table.tablebatch import TableBatch

# Connect to the Table service
table_service = TableService(connection_string=connect_str)
print("\nConnected to Table service")

# Let's perform a batch transaction, and add two course expiry dates
batch = TableBatch()
task001 = {
    'PartitionKey': 'Azure',
    'RowKey': '280',
    'expiryDate': '1 July 2020'
}
task002 = {
    'PartitionKey': 'Azure',
    'RowKey': '381',
    'expiryDate': '1 July 2020'
}

# Perform batch transaction using MERGE (could be update, insert, etc)
batch.merge_entity(task001)
batch.merge_entity(task002)
table_service.commit_batch(table_name, batch)

print("\nBatch transaction complete")
print("=======================")