|
5 | 5 | _update_dataframe_datatypes, |
6 | 6 | _create_dataframe, |
7 | 7 | resolve_workspace_id, |
| 8 | + resolve_capacity_id, |
8 | 9 | ) |
9 | 10 | from sempy._utils._log import log |
10 | 11 | import sempy_labs._icons as icons |
11 | 12 | from uuid import UUID |
12 | | -from typing import Optional |
| 13 | +from typing import List, Optional |
13 | 14 |
|
14 | 15 |
|
15 | 16 | @log |
@@ -484,3 +485,96 @@ def assign_workspace_to_stage( |
484 | 485 | print( |
485 | 486 | f"{icons.green_dot} The workspace has been assigned to the '{stage}' stage of the '{deployment_pipeline}' deployment pipeline successfully." |
486 | 487 | ) |
| 488 | + |
| 489 | + |
| 490 | +@log |
| 491 | +def deploy_stage_content( |
| 492 | + deployment_pipeline: str | UUID, |
| 493 | + source_stage_id: UUID, |
| 494 | + target_stage_id: UUID, |
| 495 | + items: Optional[dict | List[dict]] = None, |
| 496 | + note: Optional[str] = None, |
| 497 | + allow_cross_region_deployment: Optional[bool] = False, |
| 498 | + capacity: Optional[str | UUID] = None, |
| 499 | + workspace_name: Optional[str] = None, |
| 500 | +): |
| 501 | + """ |
| 502 | + Deploys items from the specified stage of the specified deployment pipeline. |
| 503 | +
|
| 504 | + This is a wrapper function for the following API: `Deployment Pipelines - Deploy Stage Content <https://learn.microsoft.com/rest/api/fabric/core/deployment-pipelines/deploy-stage-content>`_. |
| 505 | +
|
| 506 | + Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples). |
| 507 | +
|
| 508 | + Parameters |
| 509 | + ---------- |
| 510 | + deployment_pipeline : str | uuid.UUID |
| 511 | + The deployment pipeline name or ID. |
| 512 | + source_stage_id : uuid.UUID |
| 513 | + The source deployment pipeline stage ID. |
| 514 | + target_stage_id : uuid.UUID |
| 515 | + The target deployment pipeline stage ID. |
| 516 | + items : dict | List[dict], default=None |
| 517 | + A list of items to deploy. Each item should be a dictionary with the following structure: |
| 518 | + { |
| 519 | + "itemId": "1a201f2a-d1d8-45c0-8c61-1676338517de", |
| 520 | + "itemType": "SemanticModel" |
| 521 | + } |
| 522 | + If None, all items will be deployed. |
| 523 | + note : str, default=None |
| 524 | + An optional note to include with the deployment. |
| 525 | + allow_cross_region_deployment : bool, default=False |
| 526 | + Indicates whether cross region deployment is enabled. True - enabled, False - disabled. Default value is False. |
| 527 | + capacity : str | uuid.UUID, default=None |
| 528 | + The capacity name or ID to use for the deployment operation if creating a new workspace. Required when deploying to a stage that has no assigned workspaces, otherwise it is ignored. The deployment will fail if the new workspace configuration details aren't provided when required. |
| 529 | + workspace_name : str, default=None |
| 530 | + The workspace name to use for the deployment operation if creating a new workspace. Required when deploying to a stage that has no assigned workspaces, otherwise it is ignored. The deployment will fail if the new workspace configuration details aren't provided when required. |
| 531 | + """ |
| 532 | + |
| 533 | + deployment_pipeline_id = resolve_deployment_pipeline_id( |
| 534 | + deployment_pipeline=deployment_pipeline |
| 535 | + ) |
| 536 | + |
| 537 | + payload = { |
| 538 | + "sourceStageId": source_stage_id, |
| 539 | + "targetStageId": target_stage_id, |
| 540 | + } |
| 541 | + if note: |
| 542 | + payload["note"] = note |
| 543 | + |
| 544 | + if items: |
| 545 | + if isinstance(items, dict): |
| 546 | + items = [items] |
| 547 | + |
| 548 | + if not isinstance(items, list): |
| 549 | + raise ValueError( |
| 550 | + f"{icons.red_dot} The 'items' parameter must be a list of dictionaries." |
| 551 | + ) |
| 552 | + |
| 553 | + payload["items"] = items |
| 554 | + |
| 555 | + if allow_cross_region_deployment: |
| 556 | + payload["options"] = {"allowCrossRegionDeployment": True} |
| 557 | + |
| 558 | + if capacity and workspace_name: |
| 559 | + capacity_id = resolve_capacity_id(capacity) |
| 560 | + payload["createdWorkspaceDetails"] = { |
| 561 | + "capacityId": capacity_id, |
| 562 | + "name": workspace_name, |
| 563 | + } |
| 564 | + |
| 565 | + _base_api( |
| 566 | + request=f"/v1/deploymentPipelines/{deployment_pipeline_id}/deploy", |
| 567 | + method="post", |
| 568 | + payload=payload, |
| 569 | + status_codes=[200, 202], |
| 570 | + lro_return_status_code=True, |
| 571 | + ) |
| 572 | + |
| 573 | + print( |
| 574 | + f"{icons.green_dot} The deployment from stage '{source_stage_id}' to stage '{target_stage_id}' in the '{deployment_pipeline}' deployment pipeline has been initiated successfully." |
| 575 | + ) |
| 576 | + |
| 577 | + if capacity and workspace_name: |
| 578 | + print( |
| 579 | + f"{icons.info} A new workspace '{workspace_name}' will be created in the specified capacity for the deployment." |
| 580 | + ) |
0 commit comments