Browse code

refresh azure_rm.py from devel

Matt Davis authored on 2017/03/07 08:52:16
Showing 1 changed files
... ...
@@ -23,7 +23,7 @@
23 23
 Azure External Inventory Script
24 24
 ===============================
25 25
 Generates dynamic inventory by making API requests to the Azure Resource
26
-Manager using the AAzure Python SDK. For instruction on installing the
26
+Manager using the Azure Python SDK. For instruction on installing the
27 27
 Azure Python SDK see http://azure-sdk-for-python.readthedocs.org/
28 28
 
29 29
 Authentication
... ...
@@ -32,7 +32,7 @@ The order of precedence is command line arguments, environment variables,
32 32
 and finally the [default] profile found in ~/.azure/credentials.
33 33
 
34 34
 If using a credentials file, it should be an ini formatted file with one or
35
-more sections, which we refer to as profiles. The script looks for a 
35
+more sections, which we refer to as profiles. The script looks for a
36 36
 [default] section, if a profile is not specified either on the command line
37 37
 or with an environment variable. The keys in a profile will match the
38 38
 list of command line arguments below.
... ...
@@ -42,7 +42,7 @@ in your ~/.azure/credentials file, or a service principal or Active Directory
42 42
 user.
43 43
 
44 44
 Command line arguments:
45
- - profile 
45
+ - profile
46 46
  - client_id
47 47
  - secret
48 48
  - subscription_id
... ...
@@ -61,7 +61,7 @@ Environment variables:
61 61
 
62 62
 Run for Specific Host
63 63
 -----------------------
64
-When run for a specific host using the --host option, a resource group is 
64
+When run for a specific host using the --host option, a resource group is
65 65
 required. For a specific host, this script returns the following variables:
66 66
 
67 67
 {
... ...
@@ -191,7 +191,7 @@ import os
191 191
 import re
192 192
 import sys
193 193
 
194
-from distutils.version import LooseVersion
194
+from packaging.version import Version
195 195
 
196 196
 from os.path import expanduser
197 197
 
... ...
@@ -362,7 +362,11 @@ class AzureRM(object):
362 362
             resource_client = self.rm_client
363 363
             resource_client.providers.register(key)
364 364
         except Exception as exc:
365
-            self.fail("One-time registration of {0} failed - {1}".format(key, str(exc)))
365
+            self.log("One-time registration of {0} failed - {1}".format(key, str(exc)))
366
+            self.log("You might need to register {0} using an admin account".format(key))
367
+            self.log(("To register a provider using the Python CLI: "
368
+                      "https://docs.microsoft.com/azure/azure-resource-manager/"
369
+                      "resource-manager-common-deployment-errors#noregisteredproviderfound"))
366 370
 
367 371
     @property
368 372
     def network_client(self):
... ...
@@ -442,7 +446,7 @@ class AzureInventory(object):
442 442
     def _parse_cli_args(self):
443 443
         # Parse command line arguments
444 444
         parser = argparse.ArgumentParser(
445
-                description='Produce an Ansible Inventory file for an Azure subscription')
445
+            description='Produce an Ansible Inventory file for an Azure subscription')
446 446
         parser.add_argument('--list', action='store_true', default=True,
447 447
                            help='List instances (default: True)')
448 448
         parser.add_argument('--debug', action='store_true', default=False,
... ...
@@ -786,11 +790,11 @@ class AzureInventory(object):
786 786
 
787 787
 def main():
788 788
     if not HAS_AZURE:
789
-        sys.exit("The Azure python sdk is not installed (try 'pip install azure==2.0.0rc5') - {0}".format(HAS_AZURE_EXC))
789
+        sys.exit("The Azure python sdk is not installed (try `pip install 'azure>=2.0.0rc5' --upgrade`) - {0}".format(HAS_AZURE_EXC))
790 790
 
791
-    if LooseVersion(azure_compute_version) != LooseVersion(AZURE_MIN_VERSION):
791
+    if Version(azure_compute_version) < Version(AZURE_MIN_VERSION):
792 792
         sys.exit("Expecting azure.mgmt.compute.__version__ to be {0}. Found version {1} "
793
-                 "Do you have Azure == 2.0.0rc5 installed?".format(AZURE_MIN_VERSION, azure_compute_version))
793
+                 "Do you have Azure >= 2.0.0rc5 installed? (try `pip install 'azure>=2.0.0rc5' --upgrade`)".format(AZURE_MIN_VERSION, azure_compute_version))
794 794
 
795 795
     AzureInventory()
796 796