Skip to content

Commit 19559b6

Browse files
amarjeetkrAmarjeet Kumar
andauthored
Added SQL DB Retry, SQLVM Delete and SQLMI Delete commands (#9256)
* Added SQL DB Retry, SQLVM Delete and SQLMI Delete commands * Updates. * Updates --------- Co-authored-by: Amarjeet Kumar <amakum@microsoft.com>
1 parent f6867a9 commit 19559b6

18 files changed

Lines changed: 1557 additions & 6 deletions

File tree

src/datamigration/HISTORY.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
Release History
44
===============
55

6+
=======
7+
1.0.0
8+
++++++
9+
* Released the first stable version with three new commands.
10+
* [NEW COMMAND] `az datamigration sql-db retry` - Retry on going migration for the database.
11+
* [NEW COMMAND] `az datamigration sql-managed-instance delete` - Delete SQL MI Database Migration resource.
12+
* [NEW COMMAND] `az datamigration sql-vm delete` - Delete SQL VM Database Migration resource.
13+
614
=======
715
1.0.0b6
816
++++++

src/datamigration/azext_datamigration/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ def __init__(self, cli_ctx=None):
2626

2727
def load_command_table(self, args):
2828
from azext_datamigration.generated.commands import load_command_table
29+
from azure.cli.core.aaz import load_aaz_command_table
30+
try:
31+
from . import aaz
32+
except ImportError:
33+
aaz = None
34+
if aaz:
35+
load_aaz_command_table(
36+
loader=self,
37+
aaz_pkg_name=aaz.__name__,
38+
args=args
39+
)
2940
load_command_table(self, args)
3041
try:
3142
from azext_datamigration.manual.commands import load_command_table as load_command_table_manual
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command_group(
15+
"datamigration",
16+
)
17+
class __CMDGroup(AAZCommandGroup):
18+
"""Manage Datamigration
19+
"""
20+
pass
21+
22+
23+
__all__ = ["__CMDGroup"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from .__cmd_group import *
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command_group(
15+
"datamigration sql-db",
16+
)
17+
class __CMDGroup(AAZCommandGroup):
18+
"""Manage Sql Db
19+
"""
20+
pass
21+
22+
23+
__all__ = ["__CMDGroup"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from .__cmd_group import *
12+
from ._retry import *
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command(
15+
"datamigration sql-db retry",
16+
)
17+
class Retry(AAZCommand):
18+
"""Retry on going migration for the database.
19+
20+
:example: Retry Database Migration resource.
21+
az datamigration sql-db retry --resource-group testrg --sql-db-instance-name sqldbinstance --target-db-name db1 --migration-operation-id 9a90bb84-e70f-46f7-b0ae-1aef5b3b9f07
22+
"""
23+
24+
_aaz_info = {
25+
"version": "2025-06-30",
26+
"resources": [
27+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.sql/servers/{}/providers/microsoft.datamigration/databasemigrations/{}/retry", "2025-06-30"],
28+
]
29+
}
30+
31+
AZ_SUPPORT_NO_WAIT = True
32+
33+
def _handler(self, command_args):
34+
super()._handler(command_args)
35+
return self.build_lro_poller(self._execute_operations, self._output)
36+
37+
_args_schema = None
38+
39+
@classmethod
40+
def _build_arguments_schema(cls, *args, **kwargs):
41+
if cls._args_schema is not None:
42+
return cls._args_schema
43+
cls._args_schema = super()._build_arguments_schema(*args, **kwargs)
44+
45+
# define Arg Group ""
46+
47+
_args_schema = cls._args_schema
48+
_args_schema.resource_group = AAZResourceGroupNameArg(
49+
help="Name of the Azure resource group",
50+
required=True,
51+
)
52+
_args_schema.sql_db_instance_name = AAZStrArg(
53+
options=["--sql-db-instance-name"],
54+
help="Name of the SQL database instance",
55+
required=True,
56+
id_part="name",
57+
fmt=AAZStrArgFormat(
58+
pattern="^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}$",
59+
),
60+
)
61+
_args_schema.target_db_name = AAZStrArg(
62+
options=["--target-db-name"],
63+
help="The name of the target database.",
64+
required=True,
65+
id_part="child_name_1",
66+
fmt=AAZStrArgFormat(
67+
pattern="^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}$",
68+
),
69+
)
70+
71+
# define Arg Group "MigrationOperationInput"
72+
73+
_args_schema = cls._args_schema
74+
_args_schema.migration_operation_id = AAZUuidArg(
75+
options=["--migration-operation-id"],
76+
arg_group="MigrationOperationInput",
77+
help="Unique ID for tracking the migration operation",
78+
)
79+
return cls._args_schema
80+
81+
def _execute_operations(self):
82+
self.pre_operations()
83+
yield self.DatabaseMigrationsSqlDbRetry(ctx=self.ctx)()
84+
self.post_operations()
85+
86+
@register_callback
87+
def pre_operations(self):
88+
pass
89+
90+
@register_callback
91+
def post_operations(self):
92+
pass
93+
94+
def _output(self, *args, **kwargs):
95+
result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True)
96+
return result
97+
98+
class DatabaseMigrationsSqlDbRetry(AAZHttpOperation):
99+
CLIENT_TYPE = "MgmtClient"
100+
101+
def __call__(self, *args, **kwargs):
102+
request = self.make_request()
103+
session = self.client.send_request(request=request, stream=False, **kwargs)
104+
if session.http_response.status_code in [202]:
105+
return self.client.build_lro_polling(
106+
self.ctx.args.no_wait,
107+
session,
108+
None,
109+
self.on_error,
110+
lro_options={"final-state-via": "azure-async-operation"},
111+
path_format_arguments=self.url_parameters,
112+
)
113+
114+
return self.on_error(session.http_response)
115+
116+
@property
117+
def url(self):
118+
return self.client.format_url(
119+
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{sqlDbInstanceName}/providers/Microsoft.DataMigration/databaseMigrations/{targetDbName}/retry",
120+
**self.url_parameters
121+
)
122+
123+
@property
124+
def method(self):
125+
return "POST"
126+
127+
@property
128+
def error_format(self):
129+
return "MgmtErrorFormat"
130+
131+
@property
132+
def url_parameters(self):
133+
parameters = {
134+
**self.serialize_url_param(
135+
"resourceGroupName", self.ctx.args.resource_group,
136+
required=True,
137+
),
138+
**self.serialize_url_param(
139+
"sqlDbInstanceName", self.ctx.args.sql_db_instance_name,
140+
required=True,
141+
),
142+
**self.serialize_url_param(
143+
"subscriptionId", self.ctx.subscription_id,
144+
required=True,
145+
),
146+
**self.serialize_url_param(
147+
"targetDbName", self.ctx.args.target_db_name,
148+
required=True,
149+
),
150+
}
151+
return parameters
152+
153+
@property
154+
def query_parameters(self):
155+
parameters = {
156+
**self.serialize_query_param(
157+
"api-version", "2025-06-30",
158+
required=True,
159+
),
160+
}
161+
return parameters
162+
163+
@property
164+
def header_parameters(self):
165+
parameters = {
166+
**self.serialize_header_param(
167+
"Content-Type", "application/json",
168+
),
169+
}
170+
return parameters
171+
172+
@property
173+
def content(self):
174+
_content_value, _builder = self.new_content_builder(
175+
self.ctx.args,
176+
typ=AAZObjectType,
177+
typ_kwargs={"flags": {"required": True, "client_flatten": True}}
178+
)
179+
_builder.set_prop("migrationOperationId", AAZStrType, ".migration_operation_id")
180+
181+
return self.serialize_content(_content_value)
182+
183+
184+
class _RetryHelper:
185+
"""Helper class for Retry"""
186+
187+
188+
__all__ = ["Retry"]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command_group(
15+
"datamigration sql-managed-instance",
16+
)
17+
class __CMDGroup(AAZCommandGroup):
18+
"""Manage Sql Managed Instance
19+
"""
20+
pass
21+
22+
23+
__all__ = ["__CMDGroup"]

0 commit comments

Comments
 (0)