# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

from azure.cli.testsdk import *
from azure.cli.testsdk.scenario_tests import AllowLargeResponse
import time

# pylint: disable=line-too-long
class SiteRecoveryScenario(ScenarioTest):
    @AllowLargeResponse()
    @ResourceGroupPreparer(location='eastus2euap', name_prefix='clitest.rg.siterecovery.')
    def test_siterecovery_scenarios(self):
        self.kwargs.update({'vm_name': self.create_random_name(prefix='vm', length=16)})
        self.cmd('az vm create -n {vm_name} -g {rg} --image UbuntuLTS --size Standard_DS2_v2 --generate-ssh-keys')

        # replication-eligibility
        self.cmd('az site-recovery replication-eligibility list -g {rg} --virtual-machine-name {vm_name}')
        self.cmd('az site-recovery replication-eligibility show-default -g {rg} --virtual-machine-name {vm_name}')

    @ResourceGroupPreparer(location='eastus2euap', name_prefix='clitest.rg.siterecovery.vault.')
    def test_siterecovery_vault_scenarios(self):
        self.kwargs.update({
            'vault_name': self.create_random_name(prefix='vault', length=20),
            'alert_setting_name': self.create_random_name(prefix='alert', length=20),
            'policy_name_rcm': self.create_random_name(prefix='policy', length=20),
            'policy_name_rcm_failback': self.create_random_name(prefix='policy', length=20),
            'intent_name': self.create_random_name(prefix='intent', length=20),
        })
        self.cmd('az backup vault create -n {vault_name} -g {rg} -l eastus2euap')

        # vault top-level commands
        self.cmd('az site-recovery vault list-appliance -g {rg} --vault-name {vault_name}')
        self.cmd('az site-recovery vault list-migration-item -g {rg} --vault-name {vault_name}')
        self.cmd('az site-recovery vault list-network -g {rg} --vault-name {vault_name}')
        self.cmd('az site-recovery vault list-network-mapping -g {rg} --vault-name {vault_name}')
        self.cmd('az site-recovery vault list-protected-item -g {rg} --vault-name {vault_name}')
        self.cmd('az site-recovery vault list-protection-container -g {rg} --vault-name {vault_name}')
        self.cmd('az site-recovery vault list-protection-container-mapping -g {rg} --vault-name {vault_name}')
        self.cmd('az site-recovery vault list-recovery-services-provider -g {rg} --vault-name {vault_name}')
        self.cmd('az site-recovery vault list-storage-classification -g {rg} --vault-name {vault_name}')
        self.cmd('az site-recovery vault list-storage-classification-mapping -g {rg} --vault-name {vault_name}')
        self.cmd('az site-recovery vault list-v-center -g {rg} --vault-name {vault_name}')
        self.cmd('az site-recovery vault show-supported-operating-system -g {rg} --vault-name {vault_name}')

        # alert setting
        self.cmd('az site-recovery alert-setting create -n defaultAlertSetting -g {rg} '
                 '--vault-name {vault_name} --custom-email-addresses email@address.com --locale en_US '
                 '--send-to-owners Send')
        self.cmd('az site-recovery alert-setting show -n defaultAlertSetting -g {rg} '
                 '--vault-name {vault_name}',
                 checks=[
                     self.check('name', 'defaultAlertSetting'),
                     self.check('properties.locale', 'en_US'),
                     self.check('properties.customEmailAddresses', ['email@address.com']),
                     self.check('properties.sendToOwners', 'Send')])
        self.cmd('az site-recovery alert-setting update -n defaultAlertSetting -g {rg} '
                 '--vault-name {vault_name} --custom-email-addresses email2@address.com --locale fr_FR '
                 '--send-to-owners DoNotSend',
                 checks=[
                     self.check('properties.locale', 'fr_FR'),
                     self.check('properties.customEmailAddresses', ['email2@address.com']),
                     self.check('properties.sendToOwners', 'DoNotSend')])
        self.cmd('az site-recovery alert-setting list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 1)])

        # event
        events = self.cmd('az site-recovery event list -g {rg} --vault-name {vault_name}').\
            get_output_in_json()
        if events is not None and len(events) > 0:
            self.cmd('az site-recovery event show -g {rg} --vault-name {vault_name} -n '+events[0]["name"])

        # health
        self.cmd('az site-recovery vault health refresh-default -g {rg} --vault-name {vault_name}')
        self.cmd('az site-recovery vault health show -g {rg} --vault-name {vault_name}')

        # job
        jobs = self.cmd('az site-recovery job list -g {rg} --vault-name {vault_name}').get_output_in_json()
        if jobs is not None and len(jobs) > 0:
            self.cmd('az site-recovery job show -g {rg} --vault-name {vault_name} --job-name '+jobs[0]["name"])
            # TODO need to test with actual jobs
            # self.cmd('az site-recovery job restart -g {rg} --vault-name {vault_name} --job-name ' + jobs[0]["name"])
            # self.cmd('az site-recovery job cancel -g {rg} --vault-name {vault_name} --job-name ' + jobs[0]["name"])
            # self.cmd('az site-recovery job resume -g {rg} --vault-name {vault_name} --job-name ' + jobs[0]["name"])
        self.cmd('az site-recovery job export -g {rg} --vault-name {vault_name}')

        # policy
        # in-mage-rcm
        self.cmd('az site-recovery policy create -g {rg} --vault-name {vault_name} -n {policy_name_rcm} '
                 '--provider-specific-input {{in-mage-rcm:{{'
                 'app-consistent-frequency-in-minutes:0,crash-consistent-frequency-in-minutes:5,'
                 'enable-multi-vm-sync:true,recovery-point-history-in-minutes:2880}}}}')
        self.cmd('az site-recovery policy show -g {rg} --vault-name {vault_name} -n {policy_name_rcm}',
                 checks=[self.check('properties.providerSpecificDetails.instanceType', 'InMageRcm'),
                         self.check('properties.providerSpecificDetails.appConsistentFrequencyInMinutes', 0),
                         self.check('properties.providerSpecificDetails.crashConsistentFrequencyInMinutes', 5),
                         self.check('properties.providerSpecificDetails.enableMultiVmSync', 'true'),
                         self.check('properties.providerSpecificDetails.recoveryPointHistoryInMinutes', 2880)
                         ])
        self.cmd('az site-recovery policy list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 1)])
        self.cmd('az site-recovery policy update --debug -g {rg} --vault-name {vault_name} '
                 '-n {policy_name_rcm} '
                 '--provider-specific-input {{in-mage-rcm:{{'
                 'app-consistent-frequency-in-minutes:0,crash-consistent-frequency-in-minutes:5,'
                 'enable-multi-vm-sync:true,recovery-point-history-in-minutes:1440}}}}',
                 checks=[self.check('properties.providerSpecificDetails.appConsistentFrequencyInMinutes', 0),
                         self.check('properties.providerSpecificDetails.crashConsistentFrequencyInMinutes', 5),
                         self.check('properties.providerSpecificDetails.enableMultiVmSync', 'true'),
                         self.check('properties.providerSpecificDetails.recoveryPointHistoryInMinutes', 1440)])
        self.cmd('az site-recovery policy delete -g {rg} --vault-name {vault_name} '
                 '-n {policy_name_rcm} -y')
        self.cmd('az site-recovery policy list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 0)])

        # in-mage-rcm-failback
        self.cmd('az site-recovery policy create -g {rg} --vault-name {vault_name} '
                 '-n {policy_name_rcm_failback} '
                 '--provider-specific-input {{in-mage-rcm-failback:{{'
                 'app-consistent-frequency-in-minutes:60,crash-consistent-frequency-in-minutes:5}}}}')
        self.cmd('az site-recovery policy show -g {rg} --vault-name {vault_name} '
                 '-n {policy_name_rcm_failback}',
                 checks=[self.check('properties.providerSpecificDetails.instanceType', 'InMageRcmFailback'),
                         self.check('properties.providerSpecificDetails.appConsistentFrequencyInMinutes', 60),
                         self.check('properties.providerSpecificDetails.crashConsistentFrequencyInMinutes', 5)])
        self.cmd('az site-recovery policy list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 1)])
        self.cmd('az site-recovery policy update -g {rg} --vault-name {vault_name} '
                 '-n {policy_name_rcm_failback} '
                 '--provider-specific-input {{in-mage-rcm-failback:{{'
                 'app-consistent-frequency-in-minutes:0,crash-consistent-frequency-in-minutes:10}}}}',
                 checks=[self.check('properties.providerSpecificDetails.appConsistentFrequencyInMinutes', 0),
                         self.check('properties.providerSpecificDetails.crashConsistentFrequencyInMinutes', 10)])
        self.cmd('az site-recovery policy delete -g {rg} --vault-name {vault_name} '
                 '-n {policy_name_rcm_failback} -y')
        self.cmd('az site-recovery policy list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 0)])

    # pylint: disable=line-too-long
    @record_only()
    def test_siterecovery_A2A_selfcreated_scenarios(self):
        self.kwargs.update({
            'rg': 'cli.test.rg.SRVault',
            'subscription': '0b1f6471-1bf0-4dda-aec3-cb9272f09590',
            'vault_name': 'SRCliVault',
            'vm_name': 'SRsourcevm',
            'vm_rg': 'cli.test.rg.SRVM',
            'source_loc': 'eastus2',
            'recovery_loc': 'eastus',
            'fabric_source_name': 'cli-test-fabric-A2A-1',
            'fabric_recovery_name': 'cli-test-fabric-A2A-2',
            'policy_name': 'cli-test-vault-policy-A2A-1',
            'container_source_name': 'cli-test-container-A2A-1',
            'container_recovery_name': 'cli-test-container-A2A-2',
            'container_mapping_source_name': 'cli-test-container-mapping-A2A-1',
            'container_mapping_recovery_name': 'cli-test-container-mapping-A2A-2',
            'vnet_recovery_name': 'cli-test-vnet-A2A-2',
            'network_mapping_src_to_recovery_name': 'cli-test-network-mapping-A2A-1',
            'network_mapping_recovery_to_src_name': 'cli-test-network-mapping-A2A-2',
            'protected_item_name': 'cli-test-protected-item-A2A-1',
            'storage_src_name': 'clitestsaa2a1',
            'storage_recovery_name': 'clitestsaa2a2',
            'recovery_plan_name': 'cli-test-recovery-plan-A2A-1'
        })

        # create two fabrics and one container in each, create a policy
        # self.cmd('az account set -n {subscription}')
        self.cmd('az group create -l {recovery_loc} -n {rg}')
        self.cmd('az group create -l {source_loc} -n {vm_rg}')
        self.cmd('az vm create -n {vm_name} -g {vm_rg} --image Win2019Datacenter --public-ip-sku Standard '
                 '--admin-password !q2w3e4R5t6y')
        self.cmd('az backup vault create -g {rg} -n {vault_name} -l {recovery_loc}')
        self.cmd('az site-recovery fabric create -n {fabric_source_name} -g {rg} '
                 '--vault-name {vault_name} --custom-details {{azure:{{location:{source_loc}}}}}')
        self.cmd('az site-recovery fabric create -n {fabric_recovery_name} -g {rg} '
                 '--vault-name {vault_name} --custom-details {{azure:{{location:{recovery_loc}}}}}')

        # crud for fabric
        self.cmd('az site-recovery fabric list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 2)])
        self.cmd('az site-recovery fabric update -n {fabric_source_name} -g {rg} '
                 '--vault-name {vault_name} --custom-details {{azure:{{location:{source_loc}}}}}')
        self.cmd('az site-recovery fabric remove -n {fabric_source_name} -g {rg} '
                 '--vault-name {vault_name}')
        self.cmd('az site-recovery fabric create -n {fabric_source_name} -g {rg} '
                 '--vault-name {vault_name} --custom-details {{azure:{{location:{source_loc}}}}}')

        self.cmd('az site-recovery policy create -g {rg} '
                 '--vault-name {vault_name} -n {policy_name} '
                 '--provider-specific-input {{a2a:{{multi-vm-sync-status:Enable}}}}')

        policy_id = self.cmd('az site-recovery policy show -g {rg} '
                             '--vault-name {vault_name} -n {policy_name}').get_output_in_json()["id"]
        self.kwargs.update({"policy_id": policy_id})

        self.cmd('az site-recovery protection-container create -g {rg} '
                 '--fabric-name {fabric_source_name} -n {container_source_name} --vault-name {vault_name} '
                 '--provider-input [{{instance-type:A2A}}]')
        self.cmd('az site-recovery protection-container create -g {rg} '
                 '--fabric-name {fabric_recovery_name} -n {container_recovery_name} --vault-name {vault_name} '
                 '--provider-input [{{instance-type:A2A}}]')

        # crud for protection-container
        self.cmd('az site-recovery protection-container list -g {rg} '
                 '--fabric-name {fabric_source_name} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 1)])
        self.cmd('az site-recovery protection-container update -g {rg} '
                 '--fabric-name {fabric_source_name} -n {container_source_name} --vault-name {vault_name} '
                 '--provider-input [{{instance-type:A2ACrossClusterMigration}}]')
        self.cmd('az site-recovery protection-container update -g {rg} '
                 '--fabric-name {fabric_source_name} -n {container_source_name} --vault-name {vault_name} '
                 '--provider-input [{{instance-type:A2A}}]')


        container_source_id = self.cmd('az site-recovery protection-container show -g {rg} '
                                       '--fabric-name {fabric_source_name} -n {container_source_name} '
                                       '--vault-name {vault_name}',
                                       checks=[self.check('properties.fabricType', 'Azure')]).get_output_in_json()["id"]
        container_recovery_id = self.cmd('az site-recovery protection-container show '
                                         '-g {rg} --fabric-name {fabric_recovery_name} -n {container_recovery_name} '
                                         '--vault-name {vault_name}').get_output_in_json()["id"]
        self.kwargs.update({"container_source_id": container_source_id, "container_recovery_id": container_recovery_id})

        #  create container mappings
        self.cmd('az site-recovery protection-container mapping create -g {rg} '
                 '--fabric-name {fabric_source_name} -n {container_mapping_source_name} '
                 '--protection-container {container_source_name} --vault-name {vault_name} '
                 '--policy-id {policy_id} --provider-input {{a2a:{{agent-auto-update-status:Disabled}}}} '
                 '--target-container {container_recovery_id}')
        self.cmd('az site-recovery protection-container mapping create -g {rg} '
                 '--fabric-name {fabric_recovery_name} -n {container_mapping_recovery_name} '
                 '--protection-container {container_recovery_name} --vault-name {vault_name} '
                 '--policy-id {policy_id} --provider-input {{a2a:{{agent-auto-update-status:Disabled}}}} '
                 '--target-container {container_source_id}')

        # crud for container mappings
        self.cmd('az site-recovery protection-container mapping list -g {rg} '
                 '--fabric-name {fabric_source_name} '
                 '--protection-container {container_source_name} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 2)])
        self.cmd('az site-recovery protection-container mapping update -g {rg} '
                 '--fabric-name {fabric_source_name} -n {container_mapping_source_name} '
                 '--protection-container {container_source_name} --vault-name {vault_name} '
                 '--policy-id {policy_id} --provider-input {{a2a:{{agent-auto-update-status:Disabled}}}} '
                 '--target-container {container_recovery_id}')
        self.cmd('az site-recovery protection-container mapping show -g {rg} '
                 '--fabric-name {fabric_source_name} -n {container_mapping_source_name} '
                 '--protection-container {container_source_name} --vault-name {vault_name}',
                 checks=[self.check('properties.providerSpecificDetails.agentAutoUpdateStatus', 'Disabled')])
        self.cmd('az site-recovery protection-container mapping remove -g {rg} '
                 '--fabric-name {fabric_source_name} -n {container_mapping_source_name} '
                 '--protection-container {container_source_name} --vault-name {vault_name}')
        self.cmd('az site-recovery protection-container mapping create -g {rg} '
                 '--fabric-name {fabric_source_name} -n {container_mapping_source_name} '
                 '--protection-container {container_source_name} --vault-name {vault_name} '
                 '--policy-id {policy_id} --provider-input {{a2a:{{agent-auto-update-status:Disabled}}}} '
                 '--target-container {container_recovery_id}')


        # create recovery vnet and network mappings
        self.cmd('az network vnet create -g {rg} -n {vnet_recovery_name} -l {recovery_loc} --subnet-name MySubnet '
                 '--subnet-prefix 10.0.0.0/24')

        vnet_recovery = self.cmd('az network vnet show -g {rg} -n {vnet_recovery_name}').get_output_in_json()
        vm = self.cmd('az vm show -n {vm_name} -g {vm_rg}').get_output_in_json()
        nic = vm["networkProfile"]["networkInterfaces"][0]["id"]
        self.kwargs.update({"nic": nic})
        vnetvm_subnet_id = self.cmd('az network nic show '
                                    '--ids {nic}').get_output_in_json()["ipConfigurations"][0]["subnet"]["id"]
        self.kwargs.update({"vnetvm_subnet_id": vnetvm_subnet_id})
        vnetvm_id = self.cmd('az network vnet show --ids {vnetvm_subnet_id}').get_output_in_json()["id"]
        self.kwargs.update({"vnet_recovery_id": vnet_recovery["id"],
                            "vnet_recovery_subnet": vnet_recovery["subnets"][0]["id"],
                            "vnetvm_id": vnetvm_id})
        self.cmd('az site-recovery network mapping create -g {rg} --fabric-name {fabric_source_name} '
                 '-n {network_mapping_src_to_recovery_name} --network-name azureNetwork --vault-name {vault_name} '
                 '--recovery-network-id {vnet_recovery_id} '
                 '--fabric-details {{azure-to-azure:{{primary-network-id:{vnetvm_id}}}}} '
                 '--recovery-fabric-name {fabric_recovery_name}')
        self.cmd('az site-recovery network mapping create -g {rg} --fabric-name {fabric_recovery_name} '
                 '-n {network_mapping_recovery_to_src_name} --network-name azureNetwork --vault-name {vault_name} '
                 '--recovery-network-id {vnetvm_id} '
                 '--fabric-details {{azure-to-azure:{{primary-network-id:{vnet_recovery_id}}}}} '
                 '--recovery-fabric-name {fabric_source_name}')

        # crud for network mapping
        self.cmd('az site-recovery network mapping list -g {rg} --fabric-name {fabric_source_name} '
                 '--network-name azureNetwork --vault-name {vault_name}', checks=[self.check('length(@)', 1)])
        self.cmd('az site-recovery network mapping show -g {rg} --fabric-name {fabric_source_name} '
                 '-n {network_mapping_src_to_recovery_name} --network-name azureNetwork --vault-name {vault_name}',
                 checks=[self.check('properties.recoveryNetworkId', vnet_recovery["id"].lower())])
        self.cmd('az site-recovery network mapping update -g {rg} --fabric-name {fabric_source_name} '
                 '-n {network_mapping_src_to_recovery_name} --network-name azureNetwork --vault-name {vault_name} '
                 '--recovery-network-id {vnet_recovery_id} '
                 '--fabric-details {{azure-to-azure:{{primary-network-id:{vnetvm_id}}}}} '
                 '--recovery-fabric-name {fabric_recovery_name}')


        # create two storage accounts for caching
        self.cmd('az storage account create -n {storage_src_name} -g {vm_rg} --sku Standard_LRS -l {source_loc}')
        self.cmd('az storage account create -n {storage_recovery_name} -g {rg} --sku Standard_LRS -l {recovery_loc}')

        sa_src_id = self.cmd('az storage account show -n {storage_src_name} -g {vm_rg}').get_output_in_json()["id"]
        sa_recovery_id = self.cmd('az storage account show -n {storage_recovery_name} -g {rg}').get_output_in_json()["id"]
        #
        rg_id = self.cmd('az group show -n {rg}').get_output_in_json()["id"]
        vm_rg_id = self.cmd('az group show -n {vm_rg}').get_output_in_json()["id"]
        self.kwargs.update({"sa_src_id": sa_src_id, "sa_recovery_id": sa_recovery_id,
                            "vm_id": vm["id"],
                            "os_disk": vm["storageProfile"]["osDisk"]["managedDisk"]["id"],
                            "rg_id": rg_id, "vm_rg_id": vm_rg_id})

        # fix cert issue with https://learn.microsoft.com/en-us/azure/site-recovery/azure-to-azure-troubleshoot-errors#trusted-root-certificates-error-code-151066

        # enable protection
        self.cmd('az site-recovery protected-item create -g {rg} '
                 '--fabric-name {fabric_source_name} -n {protected_item_name} '
                 '--protection-container {container_source_name} '
                 '--vault-name {vault_name} --policy-id {policy_id} '
                 '--provider-details {{a2a:{{fabric-object-id:{vm_id},'
                 'vm-managed-disks:[{{disk-id:{os_disk},'
                 'primary-staging-azure-storage-account-id:{sa_src_id},'
                 'recovery-resource-group-id:{rg_id}}}],recovery-azure-network-id:{vnet_recovery_id},'
                 'recovery-container-id:{container_recovery_id},'
                 'recovery-resource-group-id:{rg_id},'
                 'recovery-subnet-name:{vnet_recovery_subnet}}}}}')

        #  wait for protection to fully enabled
        while True:
            protected_item = self.cmd('az site-recovery protected-item show -g {rg} '
                                      '--fabric-name {fabric_source_name} -n {protected_item_name} '
                                      '--protection-container {container_source_name} '
                                      '--vault-name {vault_name}').get_output_in_json()
            if protected_item["properties"]["protectionState"] == "Protected":
                self.kwargs.update({"protected_item_id": protected_item["id"]})
                break
            time.sleep(300)

        protected_item = self.cmd('az site-recovery protected-item show -g {rg} '
                                  '--fabric-name {fabric_source_name} -n {protected_item_name} '
                                  '--protection-container {container_source_name} '
                                  '--vault-name {vault_name}').get_output_in_json()
        self.kwargs.update({"protected_item_id": protected_item["id"]})

        # recovery-plan
        fabric1_id = self.cmd('az site-recovery fabric show -n {fabric_source_name} -g {rg} '
                              '--vault-name {vault_name}').get_output_in_json()["id"]
        fabric2_id = self.cmd('az site-recovery fabric show -n {fabric_recovery_name} -g {rg} '
                              '--vault-name {vault_name}').get_output_in_json()["id"]
        self.kwargs.update({"fabric1_id": fabric1_id, "fabric2_id": fabric2_id})
        self.cmd('az site-recovery recovery-plan create -n {recovery_plan_name} -g {rg} '
                 '--vault-name {vault_name} --groups [{{group-type:Boot,'
                 'replication-protected-items:[{{id:{protected_item_id},virtual-machine-id:{vm_id}}}]}}] '
                 '--primary-fabric-id {fabric1_id} '
                 '--recovery-fabric-id {fabric2_id} '
                 '--failover-deployment-model ResourceManager')
        self.cmd('az site-recovery recovery-plan show -n {recovery_plan_name} -g {rg} --vault-name {vault_name}',
                 checks=[self.check('properties.failoverDeploymentModel', 'ResourceManager'),
                         self.check('properties.primaryFabricId', fabric1_id),
                         self.check('properties.recoveryFabricId', fabric2_id)])
        self.cmd('az site-recovery recovery-plan list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 1)])
        self.cmd('az site-recovery recovery-plan delete -n {recovery_plan_name} -g {rg} '
                 '--vault-name {vault_name} -y')
        self.cmd('az site-recovery recovery-plan list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 0)])

        # failover
        self.cmd('az site-recovery protected-item unplanned-failover --fabric-name {fabric_source_name} '
                 '--protection-container {container_source_name} -n {protected_item_name} -g {rg} --vault-name {vault_name} '
                 '--failover-direction PrimaryToRecovery --provider-details {{a2a:{{}}}} '
                 '--source-site-operations NotRequired')

        # failover commit
        self.cmd('az site-recovery protected-item failover-commit --fabric-name {fabric_source_name} '
                 '--protection-container {container_source_name} -n {protected_item_name} -g {rg} --vault-name {vault_name}')

        recovery_vm = self.cmd('az vm show -n {vm_name} -g {rg}').get_output_in_json()
        self.kwargs.update({"recovery_vm_id": recovery_vm["id"],
                            "recovery_os_disk": recovery_vm["storageProfile"]["osDisk"]["managedDisk"]["id"]})

        # # switch protection
        self.cmd('az site-recovery protection-container switch-protection --fabric-name {fabric_source_name} '
                 '-n {container_source_name} --protected-item {protected_item_name} -g {rg} '
                 '--vault-name {vault_name} --provider-details {{a2a:{{policy-id:{policy_id},'
                 'recovery-container-id:{container_source_id},'
                 'recovery-resource-group-id:{vm_rg_id},'
                 'vm-managed-disks:[{{disk-id:{recovery_os_disk},'
                 'primary-staging-azure-storage-account-id:{sa_recovery_id},'
                 'recovery-resource-group-id:{vm_rg_id}}}]}}}}')

        # wait for protection to fully enabled
        while True:
            protected_item = self.cmd('az site-recovery protected-item show -g {rg} '
                                      '--fabric-name {fabric_recovery_name} -n {protected_item_name} '
                                      '--protection-container {container_recovery_name} '
                                      '--vault-name {vault_name}').get_output_in_json()
            if protected_item["properties"]["protectionState"] == "Protected":
                break
            time.sleep(600)

        # failback
        self.cmd('az site-recovery protected-item unplanned-failover --fabric-name {fabric_recovery_name} '
                 '--protection-container {container_recovery_name} -n {protected_item_name} -g {rg} --vault-name {vault_name} '
                 '--failover-direction PrimaryToRecovery --provider-details {{a2a:{{}}}} '
                 '--source-site-operations NotRequired')

        # disable protection
        self.cmd('az site-recovery protected-item remove -g {rg} '
                 '--fabric-name {fabric_recovery_name} -n {protected_item_name} --protection-container {container_recovery_name} '
                 '--vault-name {vault_name}')

        self.cmd('az site-recovery protected-item delete -g {rg} '
                 '--fabric-name {fabric_recovery_name} -n {protected_item_name} --protection-container {container_recovery_name} '
                 '--vault-name {vault_name} -y')

        self.cmd('az site-recovery network mapping delete -g {rg} --fabric-name {fabric_source_name} '
                 '-n {network_mapping_src_to_recovery_name} --network-name azureNetwork --vault-name {vault_name} -y')

        # delete container mappings
        self.cmd('az site-recovery protection-container mapping delete -g {rg} '
                 '--fabric-name {fabric_source_name} -n {container_mapping_source_name} --protection-container {container_source_name} '
                 '--vault-name {vault_name} -y')
        self.cmd('az site-recovery protection-container mapping delete -g {rg} '
                 '--fabric-name {fabric_recovery_name} -n {container_mapping_recovery_name} --protection-container {container_recovery_name} '
                 '--vault-name {vault_name} -y')

        # delete containers
        self.cmd('az site-recovery protection-container remove -g {rg} '
                 '--fabric-name {fabric_source_name} -n {container_source_name} --vault-name {vault_name}')
        self.cmd('az site-recovery protection-container remove -g {rg} '
                 '--fabric-name {fabric_recovery_name} -n {container_recovery_name} --vault-name {vault_name}')

        # delete policy
        self.cmd('az site-recovery policy delete -g {rg} '
                 '--vault-name {vault_name} -n {policy_name} -y')

        # delete fabrics
        self.cmd('az site-recovery fabric delete -n {fabric_source_name} -g {rg} '
                 '--vault-name {vault_name} -y')
        self.cmd('az site-recovery fabric delete -n {fabric_recovery_name} -g {rg} '
                 '--vault-name {vault_name} -y')

        self.cmd('az group delete -g {rg} -y')
        self.cmd('az group delete -g {vm_rg} -y')

    @record_only()
    def test_siterecovery_A2A_scenarios(self):
        self.kwargs.update({
            'rg': 'CliTeraformVaultRG',
            'subscription': '7c943c1b-5122-4097-90c8-861411bdd574',
            'vault_name': 'CliTerraformVault',
            'vm_name': 'CliVM2',
            'vm_rg': 'CliTerraformVMRG',
            'fabric1_name': 'cli-test-fabric-A2A-1',
            'fabric2_name': 'cli-test-fabric-A2A-2',
            'policy_name': 'cli-test-vault-policy-A2A-1',
            'container1_name': 'cli-test-container-A2A-1',
            'container2_name': 'cli-test-container-A2A-2',
            'container_mapping1_name': 'cli-test-container-mapping-A2A-1',
            'container_mapping2_name': 'cli-test-container-mapping-A2A-2',
            'vnet1_name': 'cli-test-vnet-A2A-1',
            'vnet2_name': 'cli-test-vnet-A2A-2',
            'network_mapping1_name': 'cli-test-network-mapping-A2A-1',
            'network_mapping2_name': 'cli-test-network-mapping-A2A-2',
            'protected_item_name': 'cli-test-protected-item-A2A-1',
            'storage1_name': 'cliteststoragea2a1',
            'storage2_name': 'cliteststoragea2a2',
            'recovery_plan_name': 'cli-test-recovery-plan-A2A-1'
        })

        # create two fabrics and one container in each, create a policy
        # self.cmd('az account set -n {subscription}')
        self.cmd('az site-recovery fabric create -n {fabric1_name} -g {rg} '
                 '--vault-name {vault_name} --custom-details {{azure:{{location:eastus}}}}')
        self.cmd('az site-recovery fabric create -n {fabric2_name} -g {rg} '
                 '--vault-name {vault_name} --custom-details {{azure:{{location:eastus2}}}}')
        self.cmd('az site-recovery policy create -g {rg} '
                 '--vault-name {vault_name} -n {policy_name} '
                 '--provider-specific-input {{a2a:{{multi-vm-sync-status:Enable}}}}')
        policy_id = self.cmd('az site-recovery policy show -g {rg} '
                             '--vault-name {vault_name} -n {policy_name}').get_output_in_json()["id"]
        self.kwargs.update({"policy_id": policy_id})

        self.cmd('az site-recovery protection-container create -g {rg} '
                 '--fabric-name {fabric1_name} -n {container1_name} --vault-name {vault_name} '
                 '--provider-input [{{instance-type:A2A}}]')
        self.cmd('az site-recovery protection-container create -g {rg} '
                 '--fabric-name {fabric2_name} -n {container2_name} --vault-name {vault_name} '
                 '--provider-input [{{instance-type:A2A}}]')

        container1_id = self.cmd('az site-recovery protection-container show '
                                 '-g {rg} --fabric-name {fabric1_name} -n {container1_name} '
                                 '--vault-name {vault_name}').get_output_in_json()["id"]
        container2_id = self.cmd('az site-recovery protection-container show '
                                 '-g {rg} --fabric-name {fabric2_name} -n {container2_name} '
                                 '--vault-name {vault_name}').get_output_in_json()["id"]
        self.kwargs.update({"container1_id": container1_id, "container2_id": container2_id})

        # create container mappings
        self.cmd('az site-recovery protection-container mapping create -g {rg} '
                 '--fabric-name {fabric1_name} -n {container_mapping1_name} --protection-container {container1_name} '
                 '--vault-name {vault_name} '
                 '--policy-id {policy_id} --provider-input {{a2a:{{agent-auto-update-status:Disabled}}}} '
                 '--target-container {container2_id}')
        self.cmd('az site-recovery protection-container mapping create -g {rg} '
                 '--fabric-name {fabric2_name} -n {container_mapping2_name} --protection-container {container2_name} '
                 '--vault-name {vault_name} '
                 '--policy-id {policy_id} --provider-input {{a2a:{{agent-auto-update-status:Disabled}}}} '
                 '--target-container {container1_id}')

        # create two vnets and network mapping
        self.cmd('az network vnet create -g {rg} -n {vnet1_name} -l eastus')
        self.cmd('az network vnet create -g {rg} -n {vnet2_name} -l eastus2 --subnet-name MySubnet '
                 '--subnet-prefix 10.0.0.0/24')

        vnet1_id = self.cmd('az network vnet show -g {rg} -n {vnet1_name}').get_output_in_json()["id"]
        vnet2 = self.cmd('az network vnet show -g {rg} -n {vnet2_name}').get_output_in_json()
        self.kwargs.update({"vnet1_id": vnet1_id, "vnet2_id": vnet2["id"],
                            "vnet2_subnet": vnet2["subnets"][0]["id"],
                            "vnetvm_id": '/subscriptions/7c943c1b-5122-4097-90c8-861411bdd574/resourceGroups/'
                                         'CliTerraformVMRG/providers/Microsoft.Network/virtualNetworks/'
                                         'CliTerraformVMRG-vnet'})

        self.cmd('az site-recovery network mapping create -g {rg} --fabric-name {fabric1_name} '
                 '-n {network_mapping1_name} --network-name azureNetwork --vault-name {vault_name} '
                 '--recovery-network-id {vnet2_id} '
                 '--fabric-details {{azure-to-azure:{{primary-network-id:{vnetvm_id}}}}} '
                 '--recovery-fabric-name {fabric2_name}')
        self.cmd('az site-recovery network mapping create -g {rg} --fabric-name {fabric2_name} '
                 '-n {network_mapping2_name} --network-name azureNetwork --vault-name {vault_name} '
                 '--recovery-network-id {vnetvm_id} '
                 '--fabric-details {{azure-to-azure:{{primary-network-id:{vnet2_id}}}}} '
                 '--recovery-fabric-name {fabric1_name}')

        # create two storage accounts for caching
        self.cmd('az storage account create -n {storage1_name} -g {rg} --sku Standard_LRS -l eastus')
        self.cmd('az storage account create -n {storage2_name} -g {vm_rg} --sku Standard_LRS -l eastus2')

        storage1_id = self.cmd('az storage account show -n {storage1_name} -g {rg}').get_output_in_json()["id"]
        storage2_id = self.cmd('az storage account show -n {storage2_name} -g {vm_rg}').get_output_in_json()["id"]
        vm = self.cmd('az vm show -n {vm_name} -g {vm_rg}').get_output_in_json()
        rg_id = self.cmd('az group show -n {rg}').get_output_in_json()["id"]
        vm_rg_id = self.cmd('az group show -n {vm_rg}').get_output_in_json()["id"]
        self.kwargs.update({"storage1_id": storage1_id, "storage2_id": storage2_id,
                            "vm_id": vm["id"],
                            "os_disk": vm["storageProfile"]["osDisk"]["managedDisk"]["id"],
                            "rg_id": rg_id, "vm_rg_id": vm_rg_id})

        # # enable protection
        self.cmd('az site-recovery protected-item create -g {rg} '
                 '--fabric-name {fabric1_name} -n {protected_item_name} --protection-container {container1_name} '
                 '--vault-name {vault_name} --policy-id {policy_id} '
                 '--provider-details {{a2a:{{fabric-object-id:{vm_id},'
                 'vm-managed-disks:[{{disk-id:{os_disk},'
                 'primary-staging-azure-storage-account-id:{storage1_id},'
                 'recovery-resource-group-id:{rg_id}}}],recovery-azure-network-id:{vnet2_id},'
                 'recovery-container-id:{container2_id},'
                 'recovery-resource-group-id:{rg_id},'
                 'recovery-subnet-name:{vnet2_subnet}}}}}')
        #
        # wait for protection to fully enabled
        while True:
            protected_item = self.cmd('az site-recovery protected-item show -g {rg} '
                                      '--fabric-name {fabric1_name} -n {protected_item_name} '
                                      '--protection-container {container1_name} '
                                      '--vault-name {vault_name}').get_output_in_json()
            if protected_item["properties"]["protectionState"] == "Protected":
                self.kwargs.update({"protected_item_id": protected_item["id"]})
                break
            time.sleep(300)

        # # recovery-plan
        fabric1_id = self.cmd('az site-recovery fabric show -n {fabric1_name} -g {rg} '
                              '--vault-name {vault_name}').get_output_in_json()["id"]
        fabric2_id = self.cmd('az site-recovery fabric show -n {fabric2_name} -g {rg} '
                              '--vault-name {vault_name}').get_output_in_json()["id"]
        self.kwargs.update({"fabric1_id": fabric1_id, "fabric2_id": fabric2_id})

        self.cmd('az site-recovery recovery-plan create -n {recovery_plan_name} -g {rg} '
                 '--vault-name {vault_name} --groups [{{group-type:Boot,'
                 'replication-protected-items:[{{id:{protected_item_id},virtual-machine-id:{vm_id}}}]}}] '
                 '--primary-fabric-id {fabric1_id} '
                 '--recovery-fabric-id {fabric2_id} '
                 '--failover-deployment-model ResourceManager')
        self.cmd('az site-recovery recovery-plan show -n {recovery_plan_name} -g {rg} --vault-name {vault_name}',
                 checks=[self.check('properties.failoverDeploymentModel', 'ResourceManager'),
                         self.check('properties.primaryFabricId', fabric1_id),
                         self.check('properties.recoveryFabricId', fabric2_id)])
        self.cmd('az site-recovery recovery-plan list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 1)])
        self.cmd('az site-recovery recovery-plan delete -n {recovery_plan_name} -g {rg} '
                 '--vault-name {vault_name} -y')
        self.cmd('az site-recovery recovery-plan list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 0)])

        # failover
        self.cmd('az site-recovery protected-item unplanned-failover --fabric-name {fabric1_name} '
                 '--protection-container {container1_name} -n {protected_item_name} -g {rg} --vault-name {vault_name} '
                 '--failover-direction PrimaryToRecovery --provider-details {{a2a:{{}}}} '
                 '--source-site-operations NotRequired')

        # failover commit
        self.cmd('az site-recovery protected-item failover-commit --fabric-name {fabric1_name} '
                 '--protection-container {container1_name} -n {protected_item_name} -g {rg} --vault-name {vault_name}')

        recovery_vm = self.cmd('az vm show -n {vm_name} -g {rg}').get_output_in_json()
        self.kwargs.update({"recovery_vm_id": recovery_vm["id"],
                            "recovery_os_disk": recovery_vm["storageProfile"]["osDisk"]["managedDisk"]["id"]})

        # switch protection
        self.cmd('az site-recovery protection-container switch-protection --fabric-name {fabric1_name} '
                 '-n {container1_name} --protected-item {protected_item_name} -g {rg} '
                 '--vault-name {vault_name} --provider-details {{a2a:{{policy-id:{policy_id},'
                 'recovery-container-id:{container1_id},'
                 'recovery-resource-group-id:{vm_rg_id},'
                 'vm-managed-disks:[{{disk-id:{recovery_os_disk},'
                 'primary-staging-azure-storage-account-id:{storage2_id},'
                 'recovery-resource-group-id:{vm_rg_id}}}]}}}}')

        # wait for protection to fully enabled
        while True:
            protected_item = self.cmd('az site-recovery protected-item show -g {rg} '
                                      '--fabric-name {fabric2_name} -n {protected_item_name} '
                                      '--protection-container {container2_name} '
                                      '--vault-name {vault_name}').get_output_in_json()
            if protected_item["properties"]["protectionState"] == "Protected":
                break
            time.sleep(300)

        # failback
        self.cmd('az site-recovery protected-item unplanned-failover --fabric-name {fabric2_name} '
                 '--protection-container {container2_name} -n {protected_item_name} -g {rg} --vault-name {vault_name} '
                 '--failover-direction PrimaryToRecovery --provider-details {{a2a:{{}}}} '
                 '--source-site-operations NotRequired')

        #  disable protection
        self.cmd('az site-recovery protected-item delete -g {rg} '
                 '--fabric-name {fabric2_name} -n {protected_item_name} --protection-container {container2_name} '
                 '--vault-name {vault_name} -y')

        # delete container mappings
        self.cmd('az site-recovery protection-container mapping delete -g {rg} '
                 '--fabric-name {fabric1_name} -n {container_mapping1_name} --protection-container {container1_name} '
                 '--vault-name {vault_name} -y')
        self.cmd('az site-recovery protection-container mapping delete -g {rg} '
                 '--fabric-name {fabric2_name} -n {container_mapping2_name} --protection-container {container2_name} '
                 '--vault-name {vault_name} -y')

        # delete containers
        self.cmd('az site-recovery protection-container remove -g {rg} '
                 '--fabric-name {fabric1_name} -n {container1_name} --vault-name {vault_name}')
        self.cmd('az site-recovery protection-container remove -g {rg} '
                 '--fabric-name {fabric2_name} -n {container2_name} --vault-name {vault_name}')

        # delete policy
        self.cmd('az site-recovery policy delete -g {rg} '
                 '--vault-name {vault_name} -n {policy_name} -y')

        # delete fabrics
        self.cmd('az site-recovery fabric delete -n {fabric1_name} -g {rg} '
                 '--vault-name {vault_name} -y')
        self.cmd('az site-recovery fabric delete -n {fabric2_name} -g {rg} '
                 '--vault-name {vault_name} -y')


    @record_only()
    @AllowLargeResponse()
    def test_siterecovery_V2A_RCMInMage_scenarios(self):
        self.kwargs.update({
            'rg': 'rgtestsrv2arcm',
            'subscription': '0b1f6471-1bf0-4dda-aec3-cb9272f09590',
            'vault_name': 'vaulttestv2arcm',
            'target_vm_name': 'RCM-Win2K16-01',
            'recovery_loc': 'eastus',
            'fabric_name': 'vaulttestv2arcm-vmwarefabric',
            'policy_name': 'cli-test-policy-V2ARCM-1',
            'container_name': 'vaulttestvf5e8replicationcontainer',
            'container_mapping_name': 'cli-test-container-mapping-V2ARCM-1',
            'vnet_name': 'cli-test-vnet-V2ARCM-1',
            'network_mapping_name': 'cli-test-network-mapping-V2ARCM-1',
            'protectable_item_friendly_name': 'A409-ForAzure-Vm1',
            'protected_item_name': 'cli-test-protected-item-V2ARCM-1',
            'storage_name': 'cliteststoragev2arcm1',
            'recovery_plan_name': 'cli-test-recovery-plan-V2ARCM-1',
            'vcenter_server': 'vcenter65',
            'credential_display_name': 'wincreds'
        })
        # requires service to setup environment
        # set subscription
        # self.cmd('az account set -n {subscription}')

        # prepare vnet and storage account
        # create recovery vnet and network mappings
        self.cmd('az network vnet create -g {rg} -n {vnet_name} -l {recovery_loc} --subnet-name MySubnet '
                 '--subnet-prefix 10.0.0.0/24')
        self.cmd('az storage account create -g {rg} -n {storage_name} -l {recovery_loc}')

        vnet = self.cmd('az network vnet show -g {rg} -n {vnet_name}').get_output_in_json()
        storage_id = self.cmd('az storage account show -g {rg} '
                              '-n {storage_name}').get_output_in_json()["id"]
        rg_id = self.cmd('az group show -n {rg}').get_output_in_json()["id"]
        vault_principal_id = self.cmd('az ad sp list --display-name "myVault"').get_output_in_json()[0]["id"]
        self.kwargs.update({"storage_id": storage_id, "rg_id": rg_id,
                            "vnet_id": vnet["id"], "subnet_id": vnet["subnets"][0]["id"],
                            "vault_principal_id": vault_principal_id})

        # # fabric is automatically created by server, list fabrics
        fabrics = self.cmd('az site-recovery fabric list -g {rg} --vault-name {vault_name}').get_output_in_json()
        for fabric in fabrics:
            if fabric["properties"]["customDetails"]["instanceType"] == "InMageRcm":
                self.kwargs.update({'fabric_name': fabric["name"]})
                break

        # # create a policy
        self.cmd('az site-recovery policy create -g {rg} '
                 '--vault-name {vault_name} -n {policy_name} '
                 '--provider-specific-input {{in-mage-rcm:{{'
                 'app-consistent-frequency-in-minutes:0,crash-consistent-frequency-in-minutes:5,'
                 'enable-multi-vm-sync:true,recovery-point-history-in-minutes:1440}}}}')
        policy_id = self.cmd('az site-recovery policy show -g {rg} '
                             '--vault-name {vault_name} -n {policy_name}').get_output_in_json()["id"]
        self.kwargs.update({"policy_id": policy_id})

        # # # container is automatically created by server
        container_name = self.cmd("az site-recovery protection-container list -g {rg} --vault-name {vault_name} "
                                  "--fabric-name {fabric_name}").get_output_in_json()[0]["name"]
        self.kwargs.update({"container_name": container_name})

        # create container mapping
        self.cmd('az site-recovery protection-container mapping create -g {rg} '
                 '--fabric-name {fabric_name} -n {container_mapping_name} '
                 '--protection-container {container_name} '
                 '--vault-name {vault_name} --policy-id {policy_id} --target-container \"Microsoft Azure\" '
                 '--provider-input {{in-mage-rcm:{{enable-agent-auto-upgrade:true}}}}')

        # get process_server_id
        recovery_services_provider = self.cmd("az site-recovery recovery-services-provider list --fabric-name "
                                              "{fabric_name} -g {rg} --vault-name {vault_name}").get_output_in_json()[0]
        self.kwargs.update({"process_server_id": recovery_services_provider["properties"]["machineId"]})
        # get fabric site name
        fabric = self.cmd('az site-recovery fabric show -g {rg} --vault-name {vault_name} '
                          '--fabric-name {fabric_name}').get_output_in_json()
        site_name = fabric["properties"]["customDetails"]["vmwareSiteId"].split('/')[-1]
        self.kwargs.update({"site_name": site_name})
        # get target vm id
        # vmware_machines = self.cmd('az site-recovery vmware-site machine list -g {rg} '
        #                            '--site-name {site_name}').get_output_in_json()
        # for machine in vmware_machines:
        #     if machine["properties"]["displayName"] == self.kwargs.get("target_vm_name"):
        #         self.kwargs.update({"fabric_discovery_machine_id": machine["id"]})
        #         break
        # for recording
        self.kwargs.update({"fabric_discovery_machine_id": "machineid"})

        # get target vm id
        credentials = self.cmd('az site-recovery vmware-site run-as-account list -g {rg} '
                               '--site-name {site_name}').get_output_in_json()
        for credential in credentials:
            if credential["properties"]["displayName"] == self.kwargs.get("credential_display_name"):
                self.kwargs.update({"run_as_account_id": credential["id"]})
                break

        # # enable protection
        self.cmd('az site-recovery protected-item create -g {rg} '
                 '--fabric-name {fabric_name} -n {protected_item_name} --protection-container {container_name} '
                 '--vault-name {vault_name} --policy-id {policy_id} '
                 '--provider-details {{in-mage-rcm:{{'
                 'fabric-discovery-machine-id:{fabric_discovery_machine_id},'
                 'process-server-id:{process_server_id},'
                 'run-as-account-id:{run_as_account_id},'
                 'target-resource-group-id:{rg_id},'
                 'target-boot-diagnostics-storage-account-id:{storage_id},'
                 'target-network-id:{vnet_id},'
                 'target-subnet-name:MySubnet,'
                 'target-vm-name:{target_vm_name},'
                 'disks-default:{{disk-type:Premium_LRS,log-storage-account-id:{storage_id}}}}}}}')

        # # wait for protection to fully enabled
        while True:
            protected_item = self.cmd('az site-recovery protected-item show -g {rg} '
                                      '--fabric-name {fabric_name} -n {protected_item_name} '
                                      '--protection-container {container_name} '
                                      '--vault-name {vault_name}').get_output_in_json()
            if protected_item["properties"]["protectionState"] == "Protected":
                self.kwargs.update({"protected_item_id": protected_item["id"]})
                break
            time.sleep(300)

        protected_item = self.cmd('az site-recovery protected-item show -g {rg} '
                                  '--fabric-name {fabric_name} -n {protected_item_name} '
                                  '--protection-container {container_name} '
                                  '--vault-name {vault_name}').get_output_in_json()
        self.kwargs.update({"protected_item_id": protected_item["id"],
                            "vm_id": protected_item["properties"]["providerSpecificDetails"]["internalIdentifier"]})

        # recovery-plan
        fabric_id = self.cmd('az site-recovery fabric show -n {fabric_name} -g {rg} '
                             '--vault-name {vault_name}').get_output_in_json()["id"]
        self.kwargs.update({"fabric_id": fabric_id})

        self.cmd('az site-recovery recovery-plan create -n {recovery_plan_name} -g {rg} '
                 '--vault-name {vault_name} --groups [{{group-type:Boot,'
                 'replication-protected-items:[{{id:{protected_item_id},virtual-machine-id:{vm_id}}}]}}] '
                 '--primary-fabric-id {fabric_id} '
                 '--recovery-fabric-id "Microsoft Azure" '
                 '--failover-deployment-model ResourceManager')
        self.cmd('az site-recovery recovery-plan show -n {recovery_plan_name} -g {rg} --vault-name {vault_name}',
                 checks=[self.check('properties.failoverDeploymentModel', 'ResourceManager'),
                         self.check('properties.primaryFabricId', fabric_id),
                         self.check('properties.recoveryFabricId', "Microsoft Azure")])
        self.cmd('az site-recovery recovery-plan list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 1)])
        self.cmd('az site-recovery recovery-plan delete -n {recovery_plan_name} -g {rg} '
                 '--vault-name {vault_name} -y')
        self.cmd('az site-recovery recovery-plan list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 0)])
        #
        # # need to add contributor and blob data contributor role assignment to storage account for the vault
        # self.cmd('az role assignment create --assignee-object-id {vault_principal_id} '
        #          '--role "Contributor" --scope {storage_id}')
        # self.cmd('az role assignment create --assignee-object-id {vault_principal_id} '
        #          '--role "Storage Blob Data Contributor" --scope {storage_id}')
        #
        # # failover
        self.cmd('az site-recovery protected-item unplanned-failover --fabric-name {fabric_name} '
                 '--protection-container {container_name} -n {protected_item_name} -g {rg} --vault-name {vault_name} '
                 '--failover-direction PrimaryToRecovery --provider-details {{in-mage-rcm:{{perform-shutdown:true}}}} '
                 '--source-site-operations NotRequired')

        protected_item = self.cmd('az site-recovery protected-item show -g {rg} '
                                  '--fabric-name {fabric_name} -n {protected_item_name} '
                                  '--protection-container {container_name} '
                                  '--vault-name {vault_name}').get_output_in_json()
        self.kwargs.update({"datastore_name": protected_item["properties"]["providerSpecificDetails"]["discoveredVmDetails"]["datastores"][0]})
        fabric = self.cmd('az site-recovery fabric show -g {rg} --vault-name {vault_name} '
                          '--fabric-name {fabric_name}').get_output_in_json()
        self.kwargs.update({"reprotect_agent_id": fabric["properties"]["customDetails"]["reprotectAgents"][0]["id"]})

        # need to manually enable disk.EnableUUID
        # https://sort.veritas.com/public/documents/sfha/6.2/vmwareesx/productguides/html/sfhas_virtualization/ch10s05s01.htm
        time.sleep(600)

        # # reprotect
        self.cmd("az site-recovery protected-item reprotect --fabric-name {fabric_name} "
                 "--protection-container {container_name} -n {protected_item_name} -g {rg} --vault-name {vault_name} "
                 "--failover-direction RecoveryToPrimary --provider-details "
                 "\"{{in-mage-rcm:{{datastore-name:'{datastore_name}',log-storage-account-id:{storage_id},"
                 "reprotect-agent-id:{reprotect_agent_id}}}}}\"")

        # # wait for protection to fully enabled
        while True:
            protected_item = self.cmd('az site-recovery protected-item show -g {rg} '
                                      '--fabric-name {fabric_name} -n {protected_item_name} '
                                      '--protection-container {container_name} '
                                      '--vault-name {vault_name}').get_output_in_json()
            if protected_item["properties"]["protectionState"] == "Protected":
                self.kwargs.update({"protected_item_id": protected_item["id"]})
                break
            time.sleep(300)

        # failback
        self.cmd('az site-recovery protected-item planned-failover --fabric-name {fabric_name} '
                 '--protection-container {container_name} -n {protected_item_name} -g {rg} --vault-name {vault_name} '
                 '--provider-details '
                 '{{in-mage-rcm-failback:{{recovery-point-type:CrashConsistent}}}}')
        #
        # disable protection
        self.cmd('az site-recovery protected-item remove -g {rg} '
                 '--fabric-name {fabric_name} -n {protected_item_name} --protection-container {container_name} '
                 '--vault-name {vault_name}')

        # delete container mappings
        self.cmd('az site-recovery protection-container mapping delete -g {rg} '
                 '--fabric-name {fabric_name} -n {container_mapping_name} --protection-container {container_name} '
                 '--vault-name {vault_name} -y')

        # delete containers not supported
        #
        # delete policy
        self.cmd('az site-recovery policy delete -g {rg} '
                 '--vault-name {vault_name} -n {policy_name} -y')
        #
        # # delete fabrics not supported

    @record_only()
    @AllowLargeResponse()
    def test_siterecovery_H2A_B2A_selfcreated_scenarios(self):
        self.kwargs.update({
            'rg': 'cli.test.rg.SRVault.H2AB2A',
            'subscription': '0b1f6471-1bf0-4dda-aec3-cb9272f09590',
            'vault_name': 'SRCliVaultH2AB2A',
            'vm_name': 'SRsourcehyperv2',
            'vm_rg': 'cli.test.rg.SRVM.H2AB2A',
            'hypervvm_name': 'VM1',
            'vnet_name': 'cli-test-vnet-H2A-B2A-1',
            'storage': 'cliteststorageh2ab2a',
            'recovery_loc': 'eastus',
            'fabric_name': 'SRsourcehyperv2site',
            'policy_name': 'cli-test-policy-H2A-B2A-1',
            'container_name': 'cloud_b325f4ed-e56d-5769-9226-2d7724ec0fba',
            'container_mapping_name': 'cli-test-container-mapping-H2A-B2A-1',
            'protected_item_name': 'cli-test-protected-item-H2A-B2A-1',
            'recovery_plan_name': 'cli-test-recovery-plan-H2A-B2A-1'
        })
        # set subscription
        # self.cmd('az account set -n {subscription}')
        self.cmd('az group create -l {recovery_loc} -n {rg}')
        self.cmd('az backup vault create -g {rg} -n {vault_name} -l {recovery_loc}')

        # use script to create vm with image Win2022DataCenter and enable hyper v,
        # https://gist.github.com/manicminer/ed16ee6a9496b317d22dd2961e83c6ef

        # use rdp to login and register
        # https://learn.microsoft.com/en-us/azure/site-recovery/hyper-v-azure-tutorial

        # create recovery vnet and storage account
        self.cmd('az network vnet create -g {rg} -n {vnet_name} -l {recovery_loc} --subnet-name MySubnet '
                 '--subnet-prefix 10.0.0.0/24')
        self.cmd('az storage account create -g {rg} -n {storage} -l {recovery_loc}')

        vnet = self.cmd('az network vnet show -g {rg} -n {vnet_name}').get_output_in_json()
        storage_id = self.cmd('az storage account show -g {rg} '
                              '-n {storage}').get_output_in_json()["id"]
        rg_id = self.cmd('az group show -n {rg}').get_output_in_json()["id"]
        vault_principal_id = self.cmd('az ad sp list --display-name "myVault"').get_output_in_json()[0]["id"]
        self.kwargs.update({"storage_id": storage_id, "rg_id": rg_id,
                            "vnet_id": vnet["id"], "subnet_id": vnet["subnets"][0]["id"],
                            "vault_principal_id": vault_principal_id})
        #
        # # fabric is created when hyperv site is added
        #
        # # create a policy
        self.cmd('az site-recovery policy create -g {rg} '
                 '--vault-name {vault_name} -n {policy_name} '
                 '--provider-specific-input {{hyper-v-replica-azure:{{'
                 'application-consistent-snapshot-frequency-in-hours:1,'
                 'recovery-point-history-duration:2,replication-interval:300}}}}')

        policy_id = self.cmd('az site-recovery policy show -g {rg} '
                             '--vault-name {vault_name} -n {policy_name}').get_output_in_json()["id"]
        self.kwargs.update({"policy_id": policy_id})
        #
        # # # container is automatically created by server
        container_name = self.cmd("az site-recovery protection-container list -g {rg} --vault-name {vault_name} "
                                  "--fabric-name {fabric_name}").get_output_in_json()[0]["name"]
        self.kwargs.update({"container_name": container_name})

        # create container mapping
        self.cmd('az site-recovery protection-container mapping create -g {rg} '
                 '--fabric-name {fabric_name} -n {container_mapping_name} '
                 '--protection-container {container_name} '
                 '--vault-name {vault_name} --policy-id {policy_id} --target-container \"Microsoft Azure\" '
                 '--provider-input {{hyper-v-replica-azure:{{}}}}')

        # get protectable_item name
        protectable_item = self.cmd('az site-recovery protectable-item list -g {rg} '
                                    '--fabric-name {fabric_name} --protection-container {container_name} '
                                    '--vault-name {vault_name}').get_output_in_json()[0]
        self.kwargs.update({"protectable_item_name": protectable_item["name"],
                            "protectable_item_id": protectable_item["id"]})

        # get vm info
        self.kwargs.update({"vhd_id": protectable_item["properties"]["customDetails"]["diskDetails"][0]["vhdId"]})


        # # enable protection
        self.cmd('az site-recovery protected-item create -g {rg} '
                 '--fabric-name {fabric_name} -n {protected_item_name} --protection-container {container_name} '
                 '--vault-name {vault_name} --policy-id {policy_id} --protectable-item-id {protectable_item_id} '
                 '--provider-details {{hyper-v-replica-azure:{{'
                 'disks-to-include:[{vhd_id}],'
                 'enable-rdp-on-target-option:Never,'
                 'os-type:Windows,'
                 'target-azure-network-id:{vnet_id},'
                 'target-azure-subnet-id:{subnet_id},'
                 'target-azure-v2-resource-group-id:{rg_id},'
                 'target-azure-vm-name:{hypervvm_name},'
                 'target-storage-account-id:{storage_id},'
                 'use-managed-disks:false,'
                 'vhd-id:{vhd_id}}}}}')
        # #
        # # wait for protection to fully enabled
        while True:
            protected_item = self.cmd('az site-recovery protected-item show -g {rg} '
                                      '--fabric-name {fabric_name} -n {protected_item_name} '
                                      '--protection-container {container_name} '
                                      '--vault-name {vault_name}').get_output_in_json()
            if protected_item["properties"]["protectionState"] == "Protected":
                self.kwargs.update({"protected_item_id": protected_item["id"]})
                break
            time.sleep(300)
        #
        protected_item = self.cmd('az site-recovery protected-item show -g {rg} '
                                     '--fabric-name {fabric_name} -n {protected_item_name} '
                                     '--protection-container {container_name} '
                                     '--vault-name {vault_name}').get_output_in_json()
        self.kwargs.update({"protected_item_id": protected_item["id"]})

        # recovery-plan
        fabric_id = self.cmd('az site-recovery fabric show -n {fabric_name} -g {rg} '
                             '--vault-name {vault_name}').get_output_in_json()["id"]
        self.kwargs.update({"fabric_id": fabric_id})

        self.cmd('az site-recovery recovery-plan create -n {recovery_plan_name} -g {rg} '
                 '--vault-name {vault_name} --groups [{{group-type:Boot,'
                 'replication-protected-items:[{{id:{protected_item_id},virtual-machine-id:{protectable_item_id}}}]}}] '
                 '--primary-fabric-id {fabric_id} '
                 '--recovery-fabric-id "Microsoft Azure" '
                 '--failover-deployment-model ResourceManager')
        self.cmd('az site-recovery recovery-plan show -n {recovery_plan_name} -g {rg} --vault-name {vault_name}',
                 checks=[self.check('properties.failoverDeploymentModel', 'ResourceManager'),
                         self.check('properties.primaryFabricId', fabric_id),
                         self.check('properties.recoveryFabricId', "Microsoft Azure")])
        self.cmd('az site-recovery recovery-plan list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 1)])
        self.cmd('az site-recovery recovery-plan delete -n {recovery_plan_name} -g {rg} '
                 '--vault-name {vault_name} -y')
        self.cmd('az site-recovery recovery-plan list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 0)])


        # need to add contributor and blob data contributor role assignment to storage account for the vault
        # self.cmd('az role assignment create --assignee-object-id {vault_principal_id} '
        #          '--role "Contributor" --scope {storage_id}')
        # self.cmd('az role assignment create --assignee-object-id {vault_principal_id} '
        #          '--role "Storage Blob Data Contributor" --scope {storage_id}')

        # failover
        self.cmd('az site-recovery protected-item unplanned-failover --fabric-name {fabric_name} '
                 '--protection-container {container_name} -n {protected_item_name} -g {rg} --vault-name {vault_name} '
                 '--failover-direction PrimaryToRecovery --provider-details {{hyper-v-replica-azure:{{}}}} '
                 '--source-site-operations NotRequired')

        # commit
        self.cmd('az site-recovery protected-item failover-commit --fabric-name {fabric_name} '
                 '--protection-container {container_name} -n {protected_item_name} -g {rg} --vault-name {vault_name}')

        # failback
        self.cmd('az site-recovery protected-item planned-failover --fabric-name {fabric_name} '
                 '--protection-container {container_name} -n {protected_item_name} -g {rg} --vault-name {vault_name} '
                 '--failover-direction RecoveryToPrimary --provider-details '
                 '{{hyper-v-replica-azure-failback:{{data-sync-option:ForSynchronization,'
                 'recovery-vm-creation-option:NoAction}}}}')

        # disable protection
        self.cmd('az site-recovery protected-item remove -g {rg} '
                 '--fabric-name {fabric_name} -n {protected_item_name} --protection-container {container_name} '
                 '--vault-name {vault_name}')

        # delete container mappings
        self.cmd('az site-recovery protection-container mapping delete -g {rg} '
                 '--fabric-name {fabric_name} -n {container_mapping_name} --protection-container {container_name} '
                 '--vault-name {vault_name} -y')

        # delete containers not supported
        #
        # delete policy
        self.cmd('az site-recovery policy delete -g {rg} '
                 '--vault-name {vault_name} -n {policy_name} -y')

        # delete fabrics
        self.cmd('az site-recovery fabric delete -n {fabric_name} -g {rg} '
                 '--vault-name {vault_name} -y')

    @record_only()
    @AllowLargeResponse()
    def test_siterecovery_H2A_E2A_scenarios(self):
        self.kwargs.update({
            'rg': 'CliTerraformVaultRG',
            'subscription': 'b364ed8d-4279-4bf8-8fd1-56f8fa0ae05c',
            'cli_subscription': '0b1f6471-1bf0-4dda-aec3-cb9272f09590',
            'vault_name': 'clitestingH2A',
            'target_vm_name': 'CliVM2',
            'recovery_loc': 'eastus',
            # 'fabric_name': 'b76fc1d0e0c3b667bd38d41f7ce113a878cd9fa29c3eab6642bd0b7698458a2d',
            'policy_name': 'cli-test-policy-H2A-E2A-1',
            # 'container_name': '28a7b9eb-c2f9-47e8-91ff-697d0d719963',
            'container_mapping_name': 'cli-test-container-mapping-H2A-E2A-1',
            'vnet_name': 'cli-test-vnet-H2A-E2A-3',
            'network_mapping_name': 'cli-test-network-mapping-H2A-E2A-3',
            'protectable_item_friendly_name': 'A409-ForAzure-Vm1',
            'protected_item_name': 'cli-test-protected-item-H2A-E2A-1',
            'storage_name': 'cliteststorageh2ae2a3',
            'recovery_plan_name': 'cli-test-recovery-plan-H2A-E2A-1'
        })
        # requires service to setup environment
        # set subscription
        # self.cmd('az account set -n {subscription}')

        # prepare vnet and storage account
        # create recovery vnet and network mappings
        self.cmd('az network vnet create -g {rg} -n {vnet_name} -l {recovery_loc} --subnet-name MySubnet '
                 '--subnet-prefix 10.0.0.0/24')
        self.cmd('az storage account create -g {rg} -n {storage_name} -l {recovery_loc}')
        vnet = self.cmd('az network vnet show -g {rg} -n {vnet_name}').get_output_in_json()
        storage_id = self.cmd('az storage account show -g {rg} '
                              '-n {storage_name}').get_output_in_json()["id"]
        rg_id = self.cmd('az group show -n {rg}').get_output_in_json()["id"]
        vault_principal_id = self.cmd('az ad sp list --display-name "myVault"').get_output_in_json()[0]["id"]
        self.kwargs.update({"storage_id": storage_id, "rg_id": rg_id,
                            "vnet_id": vnet["id"], "subnet_id": vnet["subnets"][0]["id"],
                            "vault_principal_id": vault_principal_id})


        # # list fabrics
        fabrics = self.cmd('az site-recovery fabric list -g {rg} --vault-name {vault_name}').get_output_in_json()
        for fabric in fabrics:
            if fabric["properties"]["customDetails"]["instanceType"] == "VMM":
                self.kwargs.update({'fabric_name': fabric["name"]})
                break

        # # create a policy
        self.cmd('az site-recovery policy create -g {rg} '
                 '--vault-name {vault_name} -n {policy_name} '
                 '--provider-specific-input {{hyper-v-replica-azure:{{'
                 'application-consistent-snapshot-frequency-in-hours:1,'
                 'recovery-point-history-duration:2,replication-interval:300}}}}')
        policy_id = self.cmd('az site-recovery policy show -g {rg} '
                             '--vault-name {vault_name} -n {policy_name}').get_output_in_json()["id"]
        self.kwargs.update({"policy_id": policy_id})

        # container is automatically created by server
        containers = self.cmd("az site-recovery protection-container list -g {rg} --vault-name {vault_name} "
                                  "--fabric-name {fabric_name}").get_output_in_json()
        for container in containers:
            if container["properties"]["friendlyName"] == 'ForAzure':
                self.kwargs.update({"container_name": container["name"]})

        # create container mapping
        self.cmd('az site-recovery protection-container mapping create -g {rg} '
                 '--fabric-name {fabric_name} -n {container_mapping_name} '
                 '--protection-container {container_name} '
                 '--vault-name {vault_name} --policy-id {policy_id} --target-container \"Microsoft Azure\" '
                 '--provider-input {{hyper-v-replica-azure:{{}}}}')

        # create network mapping
        vnet_source = self.cmd('az site-recovery network list -g {rg} --vault-name {vault_name} '
                               '--fabric-name {fabric_name}').get_output_in_json()
        vnet_recovery = self.cmd('az network vnet show -g {rg} -n {vnet_name}').get_output_in_json()
        self.kwargs.update({"vnet_source_name": vnet_source[0]["name"],
                            "vnet_recovery_id": vnet_recovery["id"]})
        self.cmd('az site-recovery network mapping create -g {rg} --fabric-name {fabric_name} '
                 '-n {network_mapping_name} --network-name {vnet_source_name} --vault-name {vault_name} '
                 '--recovery-network-id "{vnet_recovery_id}" '
                 '--fabric-details {{vmm-to-azure:{{}}}}')

        # get protectable_item name
        protectable_item_list = self.cmd('az site-recovery protectable-item list -g {rg} '
                                         '--fabric-name {fabric_name} --protection-container {container_name} '
                                         '--vault-name {vault_name}').get_output_in_json()

        for protectable_item in protectable_item_list:
            if protectable_item["properties"]["friendlyName"] == self.kwargs.get('protectable_item_friendly_name'):
                self.kwargs.update({"protectable_item_name": protectable_item["name"]})
                break

        protectable_item = self.cmd('az site-recovery protectable-item show '
                                       '-n {protectable_item_name} -g {rg} --fabric-name {fabric_name} '
                                       '--protection-container {container_name} '
                                       '--vault-name {vault_name}').get_output_in_json()
        self.kwargs.update({"protectable_item_name": protectable_item["name"],
                            "protectable_item_id": protectable_item["id"]})

        # get vm info
        self.kwargs.update({"vhd_id": protectable_item["properties"]["customDetails"]["diskDetails"][0]["vhdId"]})

        # # enable protection
        self.cmd('az site-recovery protected-item create -g {rg} '
                 '--fabric-name {fabric_name} -n {protected_item_name} --protection-container {container_name} '
                 '--vault-name {vault_name} --policy-id {policy_id} --protectable-item-id {protectable_item_id} '
                 '--provider-details {{hyper-v-replica-azure:{{'
                 'disks-to-include:[{vhd_id}],'
                 'enable-rdp-on-target-option:Never,'
                 'os-type:Windows,'
                 'target-azure-network-id:{vnet_id},'
                 'target-azure-subnet-id:{subnet_id},'
                 'target-azure-v2-resource-group-id:{rg_id},'
                 'target-azure-vm-name:{target_vm_name},'
                 'target-storage-account-id:{storage_id},'
                 'use-managed-disks:false,'
                 'vhd-id:{vhd_id}}}}}')

        # wait for protection to fully enabled
        while True:
            protected_item = self.cmd('az site-recovery protected-item show -g {rg} '
                                      '--fabric-name {fabric_name} -n {protected_item_name} '
                                      '--protection-container {container_name} '
                                      '--vault-name {vault_name}').get_output_in_json()
            if protected_item["properties"]["protectionState"] == "Protected":
                self.kwargs.update({"protected_item_id": protected_item["id"]})
                break
            time.sleep(300)

        protected_item = self.cmd('az site-recovery protected-item show -g {rg} '
                                  '--fabric-name {fabric_name} -n {protected_item_name} '
                                  '--protection-container {container_name} '
                                  '--vault-name {vault_name}').get_output_in_json()
        self.kwargs.update({"protected_item_id": protected_item["id"]})

        # recovery-plan
        fabric_id = self.cmd('az site-recovery fabric show -n {fabric_name} -g {rg} '
                             '--vault-name {vault_name}').get_output_in_json()["id"]
        self.kwargs.update({"fabric_id": fabric_id})

        self.cmd('az site-recovery recovery-plan create -n {recovery_plan_name} -g {rg} '
                 '--vault-name {vault_name} --groups [{{group-type:Boot,'
                 'replication-protected-items:[{{id:{protected_item_id},virtual-machine-id:{protectable_item_id}}}]}}] '
                 '--primary-fabric-id {fabric_id} '
                 '--recovery-fabric-id "Microsoft Azure" '
                 '--failover-deployment-model ResourceManager')
        self.cmd('az site-recovery recovery-plan show -n {recovery_plan_name} -g {rg} --vault-name {vault_name}',
                 checks=[self.check('properties.failoverDeploymentModel', 'ResourceManager'),
                         self.check('properties.primaryFabricId', fabric_id),
                         self.check('properties.recoveryFabricId', "Microsoft Azure")])
        self.cmd('az site-recovery recovery-plan list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 1)])
        self.cmd('az site-recovery recovery-plan delete -n {recovery_plan_name} -g {rg} '
                 '--vault-name {vault_name} -y')
        self.cmd('az site-recovery recovery-plan list -g {rg} --vault-name {vault_name}',
                 checks=[self.check('length(@)', 0)])

        # need to add contributor and blob data contributor role assignment to storage account for the vault
        # self.cmd('az role assignment create --assignee-object-id {vault_principal_id} '
        #          '--role "Contributor" --scope {storage_id}')
        # self.cmd('az role assignment create --assignee-object-id {vault_principal_id} '
        #          '--role "Storage Blob Data Contributor" --scope {storage_id}')

        # failover
        self.cmd('az site-recovery protected-item unplanned-failover --fabric-name {fabric_name} '
                 '--protection-container {container_name} -n {protected_item_name} -g {rg} --vault-name {vault_name} '
                 '--failover-direction PrimaryToRecovery --provider-details {{hyper-v-replica-azure:{{}}}} '
                 '--source-site-operations NotRequired')

        # commit
        self.cmd('az site-recovery protected-item failover-commit --fabric-name {fabric_name} '
                 '--protection-container {container_name} -n {protected_item_name} -g {rg} --vault-name {vault_name}')

        # failback
        self.cmd('az site-recovery protected-item planned-failover --fabric-name {fabric_name} '
                 '--protection-container {container_name} -n {protected_item_name} -g {rg} --vault-name {vault_name} '
                 '--failover-direction RecoveryToPrimary --provider-details '
                 '{{hyper-v-replica-azure-failback:{{data-sync-option:ForSynchronization,'
                 'recovery-vm-creation-option:NoAction}}}}')

        # disable protection
        self.cmd('az site-recovery protected-item remove -g {rg} '
                 '--fabric-name {fabric_name} -n {protected_item_name} --protection-container {container_name} '
                 '--vault-name {vault_name}')

        # delete network mappings
        self.cmd('az site-recovery network mapping delete -g {rg} --fabric-name {fabric_name} '
                 '-n {network_mapping_name} --network-name {vnet_source_name} --vault-name {vault_name} -y')

        # delete container mappings
        self.cmd('az site-recovery protection-container mapping delete -g {rg} '
                 '--fabric-name {fabric_name} -n {container_mapping_name} --protection-container {container_name} '
                 '--vault-name {vault_name} -y')

        # delete containers not supported
        #
        # delete policy
        self.cmd('az site-recovery policy delete -g {rg} '
                 '--vault-name {vault_name} -n {policy_name} -y')

        # delete fabrics not supported

        # # reset subscription
        # self.cmd('az account set -n {cli_subscription}')