Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Leon1201-spec opened this issue Feb 22, 2022 · 3 comments
Closed

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

Leon1201-spec opened this issue Feb 22, 2022 · 3 comments
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@Leon1201-spec
Copy link

Leon1201-spec commented Feb 22, 2022

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?

@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Feb 22, 2022
@azure-sdk
Copy link
Collaborator

Label prediction was below confidence level 0.6 for Model:ServiceLabels: 'Storage:0.18298085,Service Bus:0.06008966,Event Hubs:0.03932615'

@annatisch annatisch added CXP Attention Mgmt This issue is related to a management-plane library. labels Feb 23, 2022
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Feb 23, 2022
@annatisch
Copy link
Member

Thanks so much @Leon1201-spec for taking the time to report this!

I have tagged the appropriate team to help diagnose this issue ASAP :)

@Leon1201-spec
Copy link
Author

Thank you, for your help. I noticed that the backup_instance_name needs to be defined as a string without any extra signs. I'm sorry for the extra work.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

4 participants