|
| 1 | +import argparse |
| 2 | +import logging |
| 3 | +import os |
| 4 | + |
| 5 | +import entitysdk |
| 6 | +from entitysdk import Client, ProjectContext |
| 7 | + |
| 8 | +from obi_one.core.run_tasks import run_task_for_single_config_asset |
| 9 | + |
| 10 | +L = logging.getLogger(__name__) |
| 11 | + |
| 12 | + |
| 13 | +def main() -> None: |
| 14 | + """Script to launch a task for a single configuration asset. |
| 15 | +
|
| 16 | + Example usage. |
| 17 | +
|
| 18 | + python launch_task_for_single_config_asset.py |
| 19 | + --entity_type Simulation |
| 20 | + --entity_id 1569a81e-b578-4c39-a3a9-f9a05f123db9 |
| 21 | + --config_asset_id c9edaedf-e5c0-4643-979c-47375f3160e0 |
| 22 | + --lab_id 123e4567-e89b-12d3-a456-426614174000 |
| 23 | + --project_id 987e6543-e21b-12d3-a456-426614174999 |
| 24 | +
|
| 25 | + Environment Variables Required: |
| 26 | + OBI_AUTHENTICATION_TOKEN: Your authentication token for the platform. |
| 27 | + """ |
| 28 | + parser = argparse.ArgumentParser( |
| 29 | + description="Script to launch a task for a single configuration asset." |
| 30 | + ) |
| 31 | + |
| 32 | + parser.add_argument("--entity_type", required=True, help="EntitySDK Entity type as string") |
| 33 | + parser.add_argument("--entity_id", required=True, help="Entity ID as string") |
| 34 | + parser.add_argument("--config_asset_id", required=True, help="Configuration Asset ID as string") |
| 35 | + parser.add_argument("--lab_id", required=True, help="Virtual Lab ID as string") |
| 36 | + parser.add_argument("--project_id", required=True, help="Project ID as string.") |
| 37 | + |
| 38 | + args = parser.parse_args() |
| 39 | + |
| 40 | + entity_type_str = args.entity_type |
| 41 | + entity_id = args.entity_id |
| 42 | + config_asset_id = args.config_asset_id |
| 43 | + lab_id = args.lab_id |
| 44 | + project_id = args.project_id |
| 45 | + |
| 46 | + entity_type = getattr(entitysdk.models, entity_type_str) |
| 47 | + |
| 48 | + token = os.getenv("OBI_AUTHENTICATION_TOKEN") |
| 49 | + |
| 50 | + project_context = ProjectContext(virtual_lab_id=lab_id, project_id=project_id) |
| 51 | + db_client = Client(token_manager=token, project_context=project_context) |
| 52 | + |
| 53 | + run_task_for_single_config_asset( |
| 54 | + entity_type=entity_type, |
| 55 | + entity_id=entity_id, |
| 56 | + config_asset_id=config_asset_id, |
| 57 | + db_client=db_client, |
| 58 | + ) |
| 59 | + |
| 60 | + |
| 61 | +if __name__ == "__main__": |
| 62 | + main() |
0 commit comments