Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_recoveryservicesvaultconfig_info.py

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2025 Klaas Demter (@Klaas-)
4 #
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8 __metaclass__ = type
9
10 DOCUMENTATION = '''
11 ---
12 module: azure_rm_recoveryservicesvaultconfig_info
13 version_added: "3.4.0"
14 short_description: Get Info on Azure Backup Vault Configs
15 description:
16 - Get Azure Backup Vault Config
17 - Most of the information here is also part of azure_rm_recoveryservicesvault_info
18 - it's seperated out because of https://github.com/Azure/azure-rest-api-specs/issues/34218
19
20 options:
21 vault_name:
22 description:
23 - The name of the Recovery Services Vault the vault config belongs to.
24 required: true
25 type: str
26 resource_group:
27 description:
28 - The name of the resource group the vault is in.
29 required: true
30 type: str
31 extends_documentation_fragment:
32 - azure.azcollection.azure
33
34 author:
35 - Klaas Demter (@Klaas-)
36 '''
37
38 EXAMPLES = '''
39 - name: Get backup vault config information
40 azure.azcollection.azure_rm_recoveryservicesvaultconfig_info:
41 vault_name: Vault_Name
42 resource_group: Resource_Group_Name
43 '''
44
45 RETURN = '''
46 id:
47 description:
48 - Id of specified backup vault config.
49 returned: always
50 type: str
51 sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/yyyyyyyyy/
52 providers/Microsoft.RecoveryServices/vaults/zzzzzzzzzz/backupconfig/vaultconfig"
53 name:
54 description:
55 - always returns "vaultconfig"
56 type: str
57 returned: always
58 sample: "vaultconfig"
59 type:
60 description:
61 - Type of backup vault config.
62 type: str
63 returned: always
64 sample: "Microsoft.RecoveryServices/vaults/backupconfig"
65 properties:
66 description:
67 - Attributes of the backup vault config.
68 type: dict
69 returned: always
70 sample: {
71 "enhanced_security_state": "Enabled",
72 "is_soft_delete_feature_state_editable": true,
73 "soft_delete_feature_state": "Enabled",
74 "soft_delete_retention_period_in_days": 14
75 }
76 '''
77
78 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
79
80 try:
81 from azure.core.exceptions import ResourceNotFoundError
82
83 except ImportError:
84 # This is handled in azure_rm_common
85 pass
86
87
88 class AzureRMBackupVaultConfigInfo(AzureRMModuleBase):
89 """Information class for an Azure RM Backup Vault Configs"""
90
91 def __init__(self):
92 self.module_arg_spec = dict(
93 vault_name=dict(type='str', required=True),
94 resource_group=dict(type='str', required=True),
95 )
96
97 self.vault_name = None
98 self.resource_group = None
99 self.log_path = None
100 self.log_mode = None
101
102 self.results = dict(
103 id=None,
104 changed=False
105 )
106
107 super(AzureRMBackupVaultConfigInfo, self).__init__(derived_arg_spec=self.module_arg_spec,
108 supports_check_mode=True,
109 supports_tags=False,
110 facts_module=True)
111
112 def exec_module(self, **kwargs):
113 """Main module execution method"""
114
115 for key in self.module_arg_spec:
116 setattr(self, key, kwargs[key])
117
118 existing_backup_vault_config = None
119 response = None
120
121 existing_backup_vault_config = self.get_vault_config()
122
123 self.set_results(existing_backup_vault_config)
124
125 return self.results
126
127 def get_vault_config(self):
128 '''
129 Gets the properties of the specified backup vault config.
130 https://learn.microsoft.com/en-us/python/api/azure-mgmt-recoveryservicesbackup/azure.mgmt.recoveryservicesbackup.activestamp.aio.operations.backupresourcevaultconfigsoperations?view=azure-python
131
132 :return: BackupResourceVaultConfigResource
133 '''
134 self.log("Checking for vault config of vault {0} in resource group {1}".format(self.vault_name, self.resource_group))
135
136 vault_config = None
137
138 try:
139 vault_config = self.recovery_services_backup_client.backup_resource_vault_configs.get(vault_name=self.vault_name,
140 resource_group_name=self.resource_group)
141 except ResourceNotFoundError as ex:
142 self.log("Could not find vault {0} in resource group {1}".format(self.vault_name, self.resource_group))
143
144 return vault_config
145
146 def set_results(self, vault_config):
147 if vault_config:
148 self.results['id'] = vault_config.id
149 # Not properly returned by sdk nor API
150 # https://github.com/Azure/azure-rest-api-specs/issues/34530#issuecomment-2862950321
151 # self.results['location'] = vault_config.location
152 self.results['name'] = vault_config.name
153 self.results['type'] = vault_config.type
154 self.results['properties'] = vault_config.properties.as_dict()
155
156 else:
157 self.results['id'] = None
158 self.results['name'] = None
159 self.results['type'] = None
160
161
162 def main():
163 """Main execution"""
164 AzureRMBackupVaultConfigInfo()
165
166
167 if __name__ == '__main__':
168 main()