Skip to content

Commit

Permalink
Upgrade azure-mgmt-automation to v1.0.0 (#791)
Browse files Browse the repository at this point in the history
* upgrade azure-mgmt-automation to v1.0.0

* fix sanity test fail
  • Loading branch information
Fred-sun authored Mar 30, 2022
1 parent 9759e97 commit fc66c06
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
15 changes: 2 additions & 13 deletions plugins/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,8 @@ def automation_client(self):
self.log('Getting automation client')
if not self._automation_client:
self._automation_client = self.get_mgmt_svc_client(AutomationClient,
base_url=self._cloud_environment.endpoints.resource_manager)
base_url=self._cloud_environment.endpoints.resource_manager,
is_track2=True)
return self._automation_client

@property
Expand All @@ -1319,18 +1320,6 @@ def IoThub_client(self):
def IoThub_models(self):
return IoTHubModels

@property
def automation_client(self):
self.log('Getting automation client')
if not self._automation_client:
self._automation_client = self.get_mgmt_svc_client(AutomationClient,
base_url=self._cloud_environment.endpoints.resource_manager)
return self._automation_client

@property
def automation_models(self):
return AutomationModel

@property
def lock_client(self):
self.log('Getting lock client')
Expand Down
13 changes: 9 additions & 4 deletions plugins/modules/azure_rm_automationaccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@

from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase

try:
from azure.core.exceptions import ResourceNotFoundError
except ImportError:
pass


class AzureRMAutomationAccount(AzureRMModuleBase):

Expand Down Expand Up @@ -139,25 +144,25 @@ def exec_module(self, **kwargs):
def get_account(self):
try:
return self.automation_client.automation_account.get(self.resource_group, self.name)
except self.automation_models.ErrorResponseException:
except ResourceNotFoundError:
pass

def create_or_update(self, param):
try:
return self.automation_client.automation_account.create_or_update(self.resource_group, self.name, param)
except self.automation_models.ErrorResponseException as exc:
except Exception as exc:
self.fail('Error when creating automation account {0}: {1}'.format(self.name, exc.message))

def update_account_tags(self, param):
try:
return self.automation_client.automation_account.update(self.resource_group, self.name, param)
except self.automation_models.ErrorResponseException as exc:
except Exception as exc:
self.fail('Error when updating automation account {0}: {1}'.format(self.name, exc.message))

def delete_account(self):
try:
return self.automation_client.automation_account.delete(self.resource_group, self.name)
except self.automation_models.ErrorResponseException as exc:
except Exception as exc:
self.fail('Error when deleting automation account {0}: {1}'.format(self.name, exc.message))


Expand Down
13 changes: 7 additions & 6 deletions plugins/modules/azure_rm_automationaccount_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@

try:
from msrestazure.tools import parse_resource_id
from azure.core.exceptions import ResourceNotFoundError
except ImportError:
pass

Expand Down Expand Up @@ -311,7 +312,7 @@ def to_dict(self, account):
def get(self):
try:
return self.automation_client.automation_account.get(self.resource_group, self.name)
except self.automation_models.ErrorResponseException as exc:
except ResourceNotFoundError as exc:
self.fail('Error when getting automation account {0}: {1}'.format(self.name, exc.message))

def list_by_resource_group(self):
Expand All @@ -322,7 +323,7 @@ def list_by_resource_group(self):
result.append(resp.next())
except StopIteration:
pass
except self.automation_models.ErrorResponseException as exc:
except Exception as exc:
self.fail('Error when listing automation account in resource group {0}: {1}'.format(self.resource_group, exc.message))
return result

Expand All @@ -334,7 +335,7 @@ def list_all(self):
result.append(resp.next())
except StopIteration:
pass
except self.automation_models.ErrorResponseException as exc:
except Exception as exc:
self.fail('Error when listing automation account: {0}'.format(exc.message))
return result

Expand All @@ -346,7 +347,7 @@ def get_statics(self, resource_group, name):
result.append(resp.next().as_dict())
except StopIteration:
pass
except self.automation_models.ErrorResponseException as exc:
except Exception as exc:
self.fail('Error when getting statics for automation account {0}/{1}: {2}'.format(resource_group, name, exc.message))
return result

Expand All @@ -358,15 +359,15 @@ def get_usages(self, resource_group, name):
result.append(resp.next().as_dict())
except StopIteration:
pass
except self.automation_models.ErrorResponseException as exc:
except Exception as exc:
self.fail('Error when getting usage for automation account {0}/{1}: {2}'.format(resource_group, name, exc.message))
return result

def list_account_keys(self, resource_group, name):
try:
resp = self.automation_client.keys.list_by_automation_account(resource_group, name)
return [x.as_dict() for x in resp.keys]
except self.automation_models.ErrorResponseException as exc:
except Exception as exc:
self.fail('Error when listing keys for automation account {0}/{1}: {2}'.format(resource_group, name, exc.message))


Expand Down
2 changes: 1 addition & 1 deletion requirements-azure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ azure-mgmt-cosmosdb==0.5.2
azure-mgmt-hdinsight==0.1.0
azure-mgmt-devtestlabs==3.0.0
azure-mgmt-loganalytics==1.0.0
azure-mgmt-automation==0.1.1
azure-mgmt-automation==1.0.0
azure-mgmt-iothub==0.7.0
azure-mgmt-recoveryservices==0.4.0
azure-mgmt-recoveryservicesbackup==0.6.0
Expand Down

0 comments on commit fc66c06

Please sign in to comment.