Skip to content

Create backup instance, Azure Python Sdk: "Method not allowed" #23166

Closed
@Leon1201-spec

Description

After a lot of changing and figuring out, how to create a backup instance in Azure Python SDK via the Azure dataprotection management CLI I'm still running into the following error:

  File "C:\Program Files\JetBrains\PyCharm 2021.1.3\plugins\python\helpers\pydev\pydevd.py", line 1500, in _exec
    runpy._run_module_as_main(module_name, alter_argv=False)
  File "C:\Users\***\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\***\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\***\azure-setup-py-lib\azsetup\__main__.py", line 95, in <module>
    setup.apply()
  File "C:\Users\***\azure-setup-py-lib\azsetup\__main__.py", line 91, in apply
    self._apply_setup(comp)
  File "C:\Users\***\azure-setup-py-lib\azsetup\__main__.py", line 81, in _apply_setup
    inst.setup()
  File "C:\Users\***\azure-setup-py-lib\azsetup\setup_backup_instances.py", line 50, in setup
    self._create_instance(db, resource_group, client, server)
  File "C:\Users\***\azure-setup-py-lib\azsetup\setup_backup_instances.py", line 111, in _create_instance
    create_instance = data_clt.backup_instances.begin_create_or_update(vault_name=backup.name,
  File "C:\Users\***\AppData\Local\Programs\Python\Python39\lib\site-packages\azure\mgmt\dataprotection\operations\_backup_instances_operations.py", line 285, in begin_create_or_update
    raw_result = self._create_or_update_initial(
  File "C:\Users\***\AppData\Local\Programs\Python\Python39\lib\site-packages\azure\mgmt\dataprotection\operations\_backup_instances_operations.py", line 234, in _create_or_update_initial
    raise HttpResponseError(response=response, error_format=ARMErrorFormat)
azure.core.exceptions.HttpResponseError: Operation returned an invalid status 'Method Not Allowed'

My Code to create the backup instance looks like the following:

def _create_instance(self, databases, resource_group, client, server):
        cfg, az = self.cfg, self.az
        for backup in databases.backup or []:
            log.info("Create backup instance '%s' for database: '%s' ", backup.name, databases.name)
            if backup.datasource_type == "db_for_postgres":
                # type = "Microsoft.DataProtection/backupVaults/backupInstances"
                datasource_type = "Microsoft.DBforPostgreSQL/servers/databases"
                resource_type = "Microsoft.DBforPostgreSQL/servers/databases"
                resource_set_type = "Microsoft.DBforPostgreSQL/servers"
                resource_id = "/subscriptions/***/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/servers/{}/databases/{}".format(resource_group, server.name, databases.name)
                resource_set_id = "/subscriptions/***/resourceGroups/{}/providers/Microsoft.DBForPostgreSQL/servers/{}".format(resource_group, server.name)
                policy_id = "/subscriptions/***/resourceGroups/{}/providers/Microsoft.DataProtection/backupVaults/{}/backupPolicies/{}".format(backup.resource_group, backup.name, backup.policies)
                instance_name = "{}/{}".format(server.name, databases.name)
            else:
                log.info("Other datasource types are not configured yet, please contact your DevOps Administrator")
                return
            auth_secret = client.get_secret(backup.secret_name)
            secret_store = data_clt.backup_instances.models.SecretStoreResource(secret_store_type="AzureKeyVault",
                                                                                uri=auth_secret.id)
            auth_credentials = data_clt.backup_instances.models.SecretStoreBasedAuthCredentials(secret_store_resource=secret_store)
            data_source = data_clt.backup_instances.models.Datasource(resource_id=resource_id,
                                                                      datasource_type=datasource_type,
                                                                      object_type="Datasource", resource_location=location,
                                                                      resource_name=databases.name,
                                                                      resource_type=resource_type,
                                                                      resource_uri={}
                                                                      )
            data_source_set = data_clt.backup_instances.models.DatasourceSet(resource_id=resource_set_id,
                                                                             datasource_type=datasource_type,
                                                                             object_type="DatasourceSet",
                                                                             resource_location=location,
                                                                             resource_name=server.name,
                                                                             resource_type=resource_set_type,
                                                                             resource_uri={}
                                                                             )
            data_store_parameter = data_clt.backup_instances.models.DataStoreParameters(data_store_type="VaultStore")
            data_parameters_list = data_clt.backup_instances.models.PolicyParameters(data_store_parameters_list=[data_store_parameter])
            policy_info = data_clt.backup_instances.models.PolicyInfo(policy_id=policy_id,
                                                                      policy_parameters=data_parameters_list
                                                                      )
            instance_properties = data_clt.backup_instances.models.BackupInstance(data_source_info=data_source,
                                                                                  friendly_name=backup.friendly_name,
                                                                                  data_source_set_info=data_source_set,
                                                                                  datasource_auth_credentials=auth_credentials,
                                                                                  policy_info=policy_info,
                                                                                  object_type="BackupInstance"
                                                                                  )
            instance_resource = data_clt.backup_instances.models.BackupInstanceResource(properties=instance_properties)
            create_instance = data_clt.backup_instances.begin_create_or_update(vault_name=backup.name,
                                                                               resource_group_name=backup.resource_group,
                                                                               backup_instance_name=instance_name,
                                                                               parameters=instance_resource
                                                                               )
            create_instance_result = create_instance.result()

The properties are fetched from a .yaml file in the repository. Backup.name and backup.resource_group define the name and resource group of the existing backup vault. ADO.net String was created before and will be read out of the Azure Keyvault. Does maybe someone have an idea how to fix this issue?

Metadata

Assignees

Labels

MgmtThis issue is related to a management-plane library.customer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions