I am trying to write a runbook that can list all the snapshots created in my azure cloud, using the azure automation account.
Here is my Code:
!/usr/bin/env python3
import azure.mgmt.resource
import azure.mgmt.compute
import automationassets
from azure_automation_utility import get_automation_runas_credential
runas_connection = automationassets.get_automation_connection("AzureRunAsConnection")
azure_credential = get_automation_runas_credential()
compute_client = azure.mgmt.compute.ComputeManagementClient(azure_credential,str(runas_connection["SubscriptionId"]))
snapshots = compute_client.snapshots.list()
print(snapshots)
for item in snapshots:
print(item.name)
But I am getting below mentioned error:
Traceback (most recent call last): File "C:\Temp\s42kmnmn.q1k\51173539-dc9c-4f5a-8d18-fff106f50b80", line 52, in for item in snapshots: File "C:\WPy64-3800\python-3.8.0.amd64\lib\site-packages\azure\core\paging.py", line 128, in next return next(self._page_iterator) File "C:\WPy64-3800\python-3.8.0.amd64\lib\site-packages\azure\core\paging.py", line 76, in next self._response = self._get_next(self.continuation_token) File "C:\WPy64-3800\python-3.8.0.amd64\lib\site-packages\azure\mgmt\compute\v2022_03_02\operations_snapshots_operations.py", line 966, in get_next pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access File "C:\WPy64-3800\python-3.8.0.amd64\lib\site-packages\azure\core\pipeline_base.py", line 211, in run return first_node.send(pipeline_request) # type: ignore File "C:\WPy64-3800\python-3.8.0.amd64\lib\site-packages\azure\core\pipeline_base.py", line 71, in send response = self.next.send(request) File "C:\WPy64-3800\python-3.8.0.amd64\lib\site-packages\azure\core\pipeline_base.py", line 71, in send response = self.next.send(request) File "C:\WPy64-3800\python-3.8.0.amd64\lib\site-packages\azure\core\pipeline_base.py", line 71, in send response = self.next.send(request) [Previous line repeated 2 more times] File "C:\WPy64-3800\python-3.8.0.amd64\lib\site-packages\azure\mgmt\core\policies_base.py", line 47, in send response = self.next.send(request) File "C:\WPy64-3800\python-3.8.0.amd64\lib\site-packages\azure\core\pipeline\policies_redirect.py", line 158, in send response = self.next.send(request) File "C:\WPy64-3800\python-3.8.0.amd64\lib\site-packages\azure\core\pipeline\policies_retry.py", line 446, in send response = self.next.send(request) File "C:\WPy64-3800\python-3.8.0.amd64\lib\site-packages\azure\core\pipeline\policies_authentication.py", line 117, in send self.on_request(request) File "C:\WPy64-3800\python-3.8.0.amd64\lib\site-packages\azure\core\pipeline\policies_authentication.py", line 94, in on_request self._token = self._credential.get_token(*self._scopes)AttributeError: 'AdalAuthentication' object has no attribute 'get_token'
I am using python 3.8.0
azure_automation_utility = 0.0.1
azure-common = 1.1.28
azure-core = 1.25.0
azure-identity = 1.10.0
azure-mgmt-compute = 27.2.0
azure-mgmt-core = 1.3.1
typing-extensions = 4.3.0