|
48 | 48 | from kubernetes.client import CoreV1Api, V1NodeList |
49 | 49 | from requests import Response |
50 | 50 |
|
51 | | - from azext_connectedk8s.vendored_sdks.preview_2024_07_01.models import ( |
| 51 | + from azext_connectedk8s.vendored_sdks.preview_2025_08_01.models import ( |
52 | 52 | ConnectedCluster, |
53 | 53 | ) |
54 | 54 |
|
@@ -823,7 +823,7 @@ def get_helm_values( |
823 | 823 | chart_location_url = f"{config_dp_endpoint}/{chart_location_url_segment}" |
824 | 824 | dp_request_identity = connected_cluster.identity |
825 | 825 | identity = connected_cluster.id |
826 | | - request_dict = connected_cluster.serialize() |
| 826 | + request_dict = connected_cluster.as_dict() |
827 | 827 | request_dict["identity"]["tenantId"] = dp_request_identity.tenant_id |
828 | 828 | request_dict["identity"]["principalId"] = dp_request_identity.principal_id |
829 | 829 | request_dict["id"] = identity |
@@ -903,6 +903,70 @@ def health_check_dp(cmd: CLICommand, config_dp_endpoint: str) -> bool: |
903 | 903 | raise CLIInternalError("Error while performing DP health check") |
904 | 904 |
|
905 | 905 |
|
| 906 | +def update_gateway_cluster_link( |
| 907 | + cmd: CLICommand, |
| 908 | + subscription_id: str, |
| 909 | + resource_group: str, |
| 910 | + cluster_name: str, |
| 911 | + gateway_resource_id: str | None = None, |
| 912 | +) -> bool: |
| 913 | + """ |
| 914 | + Associates or disassociates a gateway with a cluster. |
| 915 | +
|
| 916 | + If `gateway_resource_id` is provided, performs association. |
| 917 | + If `gateway_resource_id` is None, performs disassociation. |
| 918 | + """ |
| 919 | + api_version = "2025-02-19-preview" |
| 920 | + is_association = gateway_resource_id is not None |
| 921 | + resource = cmd.cli_ctx.cloud.endpoints.active_directory_resource_id |
| 922 | + url = consts.GATEWAY_ASSOCIATE_URL.format( |
| 923 | + subscription_id=subscription_id, |
| 924 | + resource_group=resource_group, |
| 925 | + cluster_name=cluster_name, |
| 926 | + api_version=api_version, |
| 927 | + ) |
| 928 | + |
| 929 | + headers = ["Content-Type=application/json", "Accept=application/json"] |
| 930 | + |
| 931 | + token = os.getenv("AZURE_ACCESS_TOKEN") |
| 932 | + if token: |
| 933 | + headers.append(f"Authorization=Bearer {token}") |
| 934 | + |
| 935 | + operation_type = "association" if is_association else "disassociation" |
| 936 | + body = { |
| 937 | + "properties": { |
| 938 | + "gatewayProperties": { |
| 939 | + "gatewayResourceId": gateway_resource_id # None in case of disassociation |
| 940 | + } |
| 941 | + } |
| 942 | + } |
| 943 | + response = send_request_with_retries( |
| 944 | + cmd.cli_ctx, |
| 945 | + method="put", |
| 946 | + url=url, |
| 947 | + headers=headers, |
| 948 | + fault_type=consts.GATEWAY_LINK_FAULT_TYPE, |
| 949 | + summary=f"Error during gateway {operation_type}", |
| 950 | + request_body=json.dumps(body), |
| 951 | + resource=resource, |
| 952 | + ) |
| 953 | + |
| 954 | + if response.status_code == 200: |
| 955 | + logger.info( |
| 956 | + f"Gateway {operation_type} succeeded for cluster '{cluster_name}' in resource group '{resource_group}'." |
| 957 | + ) |
| 958 | + return True |
| 959 | + |
| 960 | + telemetry.set_exception( |
| 961 | + exception=f"Gateway {operation_type} failed", |
| 962 | + fault_type=consts.GATEWAY_LINK_FAULT_TYPE, |
| 963 | + summary=f"Gateway {operation_type} failed", |
| 964 | + ) |
| 965 | + raise CLIInternalError( |
| 966 | + f"Gateway {operation_type} failed for cluster '{cluster_name}'." |
| 967 | + ) |
| 968 | + |
| 969 | + |
906 | 970 | def send_request_with_retries( |
907 | 971 | cli_ctx: AzCli, |
908 | 972 | method: str, |
@@ -992,10 +1056,10 @@ def arm_exception_handler( |
992 | 1056 | status_code = ex.status_code |
993 | 1057 | if status_code == 404 and return_if_not_found: |
994 | 1058 | return |
995 | | - if status_code // 100 == 4: |
| 1059 | + if status_code is not None and status_code // 100 == 4: |
996 | 1060 | telemetry.set_user_fault() |
997 | 1061 | telemetry.set_exception(exception=ex, fault_type=fault_type, summary=summary) |
998 | | - if status_code // 100 == 5: |
| 1062 | + if status_code is not None and status_code // 100 == 5: |
999 | 1063 | raise AzureInternalError( |
1000 | 1064 | "Http response error occured while making ARM request: " |
1001 | 1065 | + str(ex) |
|
0 commit comments