Skip to content

Commit

Permalink
[dataprotection] Add support for cross-subscription restore for Backu…
Browse files Browse the repository at this point in the history
…p vaults (#6386)

* Update backup-vault to 2023-01-01, Enable csr flag, Comments for initialize restores

* Removed incorrect validations for alternate/original location restores

* code changes for CSR - Adding target-resource-id (for restore as files)

* Set up new version details, to be fully tested before merge.

* Testing complete.

* Updated test runs

* Fix documentation issue

* Remove live-test only lines from AKS test

* Updated AAZ version, new codegen

---------

Co-authored-by: Zubair Abid <zubairabid@microsoft.com>
  • Loading branch information
zubairabid and Zubair Abid authored Jun 12, 2023
1 parent 5fa770f commit 9ecde6a
Show file tree
Hide file tree
Showing 18 changed files with 8,406 additions and 7,443 deletions.
7 changes: 7 additions & 0 deletions src/dataprotection/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Release History
===============
0.9.0
+++++
* Add support for cross-subscription-restore for Dataprotection.
* `az dataprotection backup-vault create`: Add parameter (`--cross-subscription-restore-state`/ `--csr-state`), allowing backup vault creation with the cross-subscription-restore state flag set.
* `az dataprotection backup-vault update`: Add parameter (`--cross-subscription-restore-state`/ `--csr-state`), allowing updating the cross-subscription-restore state flag in backup vaults.
* `az dataprotection backup-instance restore initialize-for-data-recovery-as-files`: Add parameter `--target-resource-id`, required for cross-subscription-restore of OSS Scenario as files.

0.8.2
+++++
* No user-facing updates - quickfix making the `aaz_operations` folder a module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
is_experimental=True,
)
class __CMDGroup(AAZCommandGroup):
"""Manage dataprotection.
"""Manage dataprotection
"""
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class Create(AAZCommand):
"""

_aaz_info = {
"version": "2022-12-01",
"version": "2023-01-01",
"resources": [
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.dataprotection/backupvaults/{}", "2022-12-01"],
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.dataprotection/backupvaults/{}", "2023-01-01"],
]
}

Expand Down Expand Up @@ -58,6 +58,16 @@ def _build_arguments_schema(cls, *args, **kwargs):
required=True,
)

# define Arg Group "FeatureSettings"

_args_schema = cls._args_schema
_args_schema.cross_subscription_restore_state = AAZStrArg(
options=["--csr-state", "--cross-subscription-restore-state"],
arg_group="FeatureSettings",
help="CrossSubscriptionRestore state",
enum={"Disabled": "Disabled", "Enabled": "Enabled", "PermanentlyDisabled": "PermanentlyDisabled"},
)

# define Arg Group "Identity"

_args_schema = cls._args_schema
Expand Down Expand Up @@ -235,7 +245,7 @@ def url_parameters(self):
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2022-12-01",
"api-version", "2023-01-01",
required=True,
),
}
Expand Down Expand Up @@ -272,10 +282,19 @@ def content(self):

properties = _builder.get(".properties")
if properties is not None:
properties.set_prop("featureSettings", AAZObjectType)
properties.set_prop("monitoringSettings", AAZObjectType)
properties.set_prop("securitySettings", AAZObjectType)
properties.set_prop("storageSettings", AAZListType, ".storage_setting", typ_kwargs={"flags": {"required": True}})

feature_settings = _builder.get(".properties.featureSettings")
if feature_settings is not None:
feature_settings.set_prop("crossSubscriptionRestoreSettings", AAZObjectType)

cross_subscription_restore_settings = _builder.get(".properties.featureSettings.crossSubscriptionRestoreSettings")
if cross_subscription_restore_settings is not None:
cross_subscription_restore_settings.set_prop("state", AAZStrType, ".cross_subscription_restore_state")

monitoring_settings = _builder.get(".properties.monitoringSettings")
if monitoring_settings is not None:
monitoring_settings.set_prop("azureMonitorAlertSettings", AAZObjectType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ class Delete(AAZCommand):
"""

_aaz_info = {
"version": "2022-12-01",
"version": "2023-01-01",
"resources": [
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.dataprotection/backupvaults/{}", "2022-12-01"],
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.dataprotection/backupvaults/{}", "2023-01-01"],
]
}

AZ_SUPPORT_NO_WAIT = True

def _handler(self, command_args):
super()._handler(command_args)
self._execute_operations()
return None
return self.build_lro_poller(self._execute_operations, None)

_args_schema = None

Expand All @@ -59,7 +60,7 @@ def _build_arguments_schema(cls, *args, **kwargs):

def _execute_operations(self):
self.pre_operations()
self.BackupVaultsDelete(ctx=self.ctx)()
yield self.BackupVaultsDelete(ctx=self.ctx)()
self.post_operations()

@register_callback
Expand All @@ -76,12 +77,33 @@ class BackupVaultsDelete(AAZHttpOperation):
def __call__(self, *args, **kwargs):
request = self.make_request()
session = self.client.send_request(request=request, stream=False, **kwargs)
if session.http_response.status_code in [200]:
return self.on_200(session)
if session.http_response.status_code in [202]:
return self.on_202(session)
return self.client.build_lro_polling(
self.ctx.args.no_wait,
session,
self.on_200,
self.on_error,
lro_options={"final-state-via": "azure-async-operation"},
path_format_arguments=self.url_parameters,
)
if session.http_response.status_code in [200]:
return self.client.build_lro_polling(
self.ctx.args.no_wait,
session,
self.on_200,
self.on_error,
lro_options={"final-state-via": "azure-async-operation"},
path_format_arguments=self.url_parameters,
)
if session.http_response.status_code in [204]:
return self.on_204(session)
return self.client.build_lro_polling(
self.ctx.args.no_wait,
session,
self.on_204,
self.on_error,
lro_options={"final-state-via": "azure-async-operation"},
path_format_arguments=self.url_parameters,
)

return self.on_error(session.http_response)

Expand Down Expand Up @@ -122,7 +144,7 @@ def url_parameters(self):
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2022-12-01",
"api-version", "2023-01-01",
required=True,
),
}
Expand All @@ -131,9 +153,6 @@ def query_parameters(self):
def on_200(self, session):
pass

def on_202(self, session):
pass

def on_204(self, session):
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class List(AAZCommand):
"""

_aaz_info = {
"version": "2022-12-01",
"version": "2023-01-01",
"resources": [
["mgmt-plane", "/subscriptions/{}/providers/microsoft.dataprotection/backupvaults", "2022-12-01"],
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.dataprotection/backupvaults", "2022-12-01"],
["mgmt-plane", "/subscriptions/{}/providers/microsoft.dataprotection/backupvaults", "2023-01-01"],
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.dataprotection/backupvaults", "2023-01-01"],
]
}

Expand All @@ -53,12 +53,12 @@ def _build_arguments_schema(cls, *args, **kwargs):

def _execute_operations(self):
self.pre_operations()
condition_0 = has_value(self.ctx.subscription_id) and has_value(self.ctx.args.resource_group) is not True
condition_1 = has_value(self.ctx.args.resource_group) and has_value(self.ctx.subscription_id)
condition_0 = has_value(self.ctx.args.resource_group) and has_value(self.ctx.subscription_id)
condition_1 = has_value(self.ctx.subscription_id) and has_value(self.ctx.args.resource_group) is not True
if condition_0:
self.BackupVaultsGetInSubscription(ctx=self.ctx)()
if condition_1:
self.BackupVaultsGetInResourceGroup(ctx=self.ctx)()
if condition_1:
self.BackupVaultsGetInSubscription(ctx=self.ctx)()
self.post_operations()

@register_callback
Expand All @@ -74,7 +74,7 @@ def _output(self, *args, **kwargs):
next_link = self.deserialize_output(self.ctx.vars.instance.next_link)
return result, next_link

class BackupVaultsGetInSubscription(AAZHttpOperation):
class BackupVaultsGetInResourceGroup(AAZHttpOperation):
CLIENT_TYPE = "MgmtClient"

def __call__(self, *args, **kwargs):
Expand All @@ -88,7 +88,7 @@ def __call__(self, *args, **kwargs):
@property
def url(self):
return self.client.format_url(
"/subscriptions/{subscriptionId}/providers/Microsoft.DataProtection/backupVaults",
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataProtection/backupVaults",
**self.url_parameters
)

Expand All @@ -103,6 +103,10 @@ def error_format(self):
@property
def url_parameters(self):
parameters = {
**self.serialize_url_param(
"resourceGroupName", self.ctx.args.resource_group,
required=True,
),
**self.serialize_url_param(
"subscriptionId", self.ctx.subscription_id,
required=True,
Expand All @@ -114,7 +118,7 @@ def url_parameters(self):
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2022-12-01",
"api-version", "2023-01-01",
required=True,
),
}
Expand Down Expand Up @@ -308,7 +312,7 @@ def _build_schema_on_200(cls):

return cls._schema_on_200

class BackupVaultsGetInResourceGroup(AAZHttpOperation):
class BackupVaultsGetInSubscription(AAZHttpOperation):
CLIENT_TYPE = "MgmtClient"

def __call__(self, *args, **kwargs):
Expand All @@ -322,7 +326,7 @@ def __call__(self, *args, **kwargs):
@property
def url(self):
return self.client.format_url(
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataProtection/backupVaults",
"/subscriptions/{subscriptionId}/providers/Microsoft.DataProtection/backupVaults",
**self.url_parameters
)

Expand All @@ -337,10 +341,6 @@ def error_format(self):
@property
def url_parameters(self):
parameters = {
**self.serialize_url_param(
"resourceGroupName", self.ctx.args.resource_group,
required=True,
),
**self.serialize_url_param(
"subscriptionId", self.ctx.subscription_id,
required=True,
Expand All @@ -352,7 +352,7 @@ def url_parameters(self):
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2022-12-01",
"api-version", "2023-01-01",
required=True,
),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class Show(AAZCommand):
"""

_aaz_info = {
"version": "2022-12-01",
"version": "2023-01-01",
"resources": [
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.dataprotection/backupvaults/{}", "2022-12-01"],
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.dataprotection/backupvaults/{}", "2023-01-01"],
]
}

Expand Down Expand Up @@ -124,7 +124,7 @@ def url_parameters(self):
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2022-12-01",
"api-version", "2023-01-01",
required=True,
),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class Update(AAZCommand):
"""

_aaz_info = {
"version": "2022-12-01",
"version": "2023-01-01",
"resources": [
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.dataprotection/backupvaults/{}", "2022-12-01"],
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.dataprotection/backupvaults/{}", "2023-01-01"],
]
}

Expand Down Expand Up @@ -58,6 +58,17 @@ def _build_arguments_schema(cls, *args, **kwargs):
id_part="name",
)

# define Arg Group "FeatureSettings"

_args_schema = cls._args_schema
_args_schema.cross_subscription_restore_state = AAZStrArg(
options=["--csr-state", "--cross-subscription-restore-state"],
arg_group="FeatureSettings",
help="CrossSubscriptionRestore state",
nullable=True,
enum={"Disabled": "Disabled", "Enabled": "Enabled", "PermanentlyDisabled": "PermanentlyDisabled"},
)

# define Arg Group "Identity"

_args_schema = cls._args_schema
Expand Down Expand Up @@ -203,7 +214,7 @@ def url_parameters(self):
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2022-12-01",
"api-version", "2023-01-01",
required=True,
),
}
Expand Down Expand Up @@ -302,7 +313,7 @@ def url_parameters(self):
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2022-12-01",
"api-version", "2023-01-01",
required=True,
),
}
Expand Down Expand Up @@ -370,9 +381,18 @@ def _update_instance(self, instance):

properties = _builder.get(".properties")
if properties is not None:
properties.set_prop("featureSettings", AAZObjectType)
properties.set_prop("monitoringSettings", AAZObjectType)
properties.set_prop("securitySettings", AAZObjectType)

feature_settings = _builder.get(".properties.featureSettings")
if feature_settings is not None:
feature_settings.set_prop("crossSubscriptionRestoreSettings", AAZObjectType)

cross_subscription_restore_settings = _builder.get(".properties.featureSettings.crossSubscriptionRestoreSettings")
if cross_subscription_restore_settings is not None:
cross_subscription_restore_settings.set_prop("state", AAZStrType, ".cross_subscription_restore_state")

monitoring_settings = _builder.get(".properties.monitoringSettings")
if monitoring_settings is not None:
monitoring_settings.set_prop("azureMonitorAlertSettings", AAZObjectType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Wait(AAZWaitCommand):

_aaz_info = {
"resources": [
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.dataprotection/backupvaults/{}", "2022-12-01"],
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.dataprotection/backupvaults/{}", "2023-01-01"],
]
}

Expand Down Expand Up @@ -116,7 +116,7 @@ def url_parameters(self):
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2022-12-01",
"api-version", "2023-01-01",
required=True,
),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def _build_arguments_schema(cls, *args, **kwargs):

_args_schema = cls._args_schema
_args_schema.resource_group = AAZResourceGroupNameArg(
help="Name of resource group. You can configure the default group using `az configure --defaults group=<name>`.",
required=True,
)
_args_schema.vault_name = AAZStrArg(
Expand Down
Loading

0 comments on commit 9ecde6a

Please sign in to comment.