|
| 1 | +# -*- coding: utf-8 -*- |
1 | 2 | # -------------------------------------------------------------------------------------------- |
2 | 3 | # Copyright (c) Microsoft Corporation. All rights reserved. |
3 | 4 | # Licensed under the MIT License. See License.txt in the project root for license information. |
@@ -2023,6 +2024,49 @@ def migrate_firewall_rules_from_single_to_flex(db_context, cmd, source_server_id |
2023 | 2024 | firewall_rule_name=rule.name) |
2024 | 2025 |
|
2025 | 2026 |
|
| 2027 | +def _fm_settings_payload(state, uami=None): |
| 2028 | + """ |
| 2029 | + Build the flattened payload expected by the SDK for FabricMirroringSettings. |
| 2030 | + Because of x-ms-client-flatten, we set properties at the top level. |
| 2031 | + """ |
| 2032 | + # Most recent autorest will let us pass state/identityResourceId directly on the Settings model |
| 2033 | + return mysql_models.FabricMirroringSettings( |
| 2034 | + state=state, |
| 2035 | + identity_resource_id=uami # optional when disabling |
| 2036 | + ) |
| 2037 | + |
| 2038 | + |
| 2039 | +def flexible_server_mirroring_enable(cmd, client, resource_group_name, server_name, identity_resource_id): |
| 2040 | + """ |
| 2041 | + 'Enable' translates to PUT the 'Default' FabricMirroringSettings with state=Enabled and UAMI. |
| 2042 | + The Swagger limits settings name to 'Default'. |
| 2043 | + """ |
| 2044 | + if not identity_resource_id: |
| 2045 | + raise RequiredArgumentMissingError( |
| 2046 | + "Parameter --identity-resource-id is required when enabling fabric mirroring." |
| 2047 | + ) |
| 2048 | + |
| 2049 | + payload = _fm_settings_payload(state='Enabled', uami=identity_resource_id) |
| 2050 | + |
| 2051 | + # Long-running operation |
| 2052 | + poller = (getattr(client, 'begin_create_or_update', None) or getattr(client, 'begin_put'))( |
| 2053 | + resource_group_name, server_name, 'Default', payload |
| 2054 | + ) |
| 2055 | + return resolve_poller(poller, cmd.cli_ctx, 'Enable Fabric mirroring') |
| 2056 | + |
| 2057 | + |
| 2058 | +def flexible_server_mirroring_disable(cmd, client, resource_group_name, server_name): |
| 2059 | + """ |
| 2060 | + 'Disable' translates to PUT the 'Default' FabricMirroringSettings with state=Disabled. |
| 2061 | + identityResourceId can be omitted when disabling<97>service will deactivate/clean bindings. |
| 2062 | + """ |
| 2063 | + payload = _fm_settings_payload(state='Disabled', uami=None) |
| 2064 | + poller = (getattr(client, 'begin_create_or_update', None) or getattr(client, 'begin_put'))( |
| 2065 | + resource_group_name, server_name, 'Default', payload |
| 2066 | + ) |
| 2067 | + return resolve_poller(poller, cmd.cli_ctx, 'Disable Fabric mirroring') |
| 2068 | + |
| 2069 | + |
2026 | 2070 | # pylint: disable=too-many-instance-attributes, too-few-public-methods |
2027 | 2071 | class DbContext: |
2028 | 2072 | def __init__(self, cmd=None, azure_sdk=None, logging_name=None, cf_firewall=None, cf_db=None, |
|
0 commit comments