From 2b7f4395d6919d57ea012a6631861ca99eb01497 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Thu, 21 Apr 2016 23:18:45 -0400 Subject: [PATCH] Allow to work with latest Azure Python SDK (#15467) * Allow to work with latest Azure Python SDK * Fixed so that errors are sent to stderr --- contrib/inventory/windows_azure.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/contrib/inventory/windows_azure.py b/contrib/inventory/windows_azure.py index d566b0c4d3..d2999f1876 100755 --- a/contrib/inventory/windows_azure.py +++ b/contrib/inventory/windows_azure.py @@ -47,13 +47,9 @@ except ImportError: import simplejson as json try: - import azure - from azure import WindowsAzureError from azure.servicemanagement import ServiceManagementService except ImportError as e: - print("failed=True msg='`azure` library required for this script'") - sys.exit(1) - + sys.exit("ImportError: {0}".format(str(e))) # Imports for ansible import ConfigParser @@ -194,11 +190,8 @@ class AzureInventory(object): try: for cloud_service in self.sms.list_hosted_services(): self.add_deployments(cloud_service) - except WindowsAzureError as e: - print("Looks like Azure's API is down:") - print("") - print(e) - sys.exit(1) + except Exception as e: + sys.exit("Error: Failed to access cloud services - {0}".format(str(e))) def add_deployments(self, cloud_service): """Makes an Azure API call to get the list of virtual machines @@ -207,11 +200,8 @@ class AzureInventory(object): try: for deployment in self.sms.get_hosted_service_properties(cloud_service.service_name,embed_detail=True).deployments.deployments: self.add_deployment(cloud_service, deployment) - except WindowsAzureError as e: - print("Looks like Azure's API is down:") - print("") - print(e) - sys.exit(1) + except Exception as e: + sys.exit("Error: Failed to access deployments - {0}".format(str(e))) def add_deployment(self, cloud_service, deployment): """Adds a deployment to the inventory and index"""