updates for Azure SDK 2.0.0rc4

pull/16135/head
nitzmahone 9 years ago
parent 77e82adf61
commit d1b611a730

@ -8,12 +8,12 @@ Requirements
------------ ------------
Using the Azure Resource Manager modules requires having `Azure Python SDK <https://github.com/Azure/azure-sdk-for-python>`_ Using the Azure Resource Manager modules requires having `Azure Python SDK <https://github.com/Azure/azure-sdk-for-python>`_
installed on the host running Ansible. You will need to have >= v2.0.0RC2 installed. The simplest way to install the installed on the host running Ansible. You will need to have >= v2.0.0RC4 installed. The simplest way to install the
SDK is via pip: SDK is via pip:
.. code-block:: bash .. code-block:: bash
$ pip install azure==2.0.0rc2 $ pip install azure>=2.0.0rc4
Authenticating with Azure Authenticating with Azure

@ -66,8 +66,6 @@ CIDR_PATTERN = re.compile("(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){
AZURE_SUCCESS_STATE = "Succeeded" AZURE_SUCCESS_STATE = "Succeeded"
AZURE_FAILED_STATE = "Failed" AZURE_FAILED_STATE = "Failed"
AZURE_MIN_VERSION = "2016-03-30"
HAS_AZURE = True HAS_AZURE = True
HAS_AZURE_EXC = None HAS_AZURE_EXC = None
@ -75,18 +73,14 @@ try:
from enum import Enum from enum import Enum
from msrest.serialization import Serializer from msrest.serialization import Serializer
from msrestazure.azure_exceptions import CloudError from msrestazure.azure_exceptions import CloudError
from azure.mgmt.compute import __version__ as azure_compute_version # from azure.mgmt.compute import __version__ as azure_compute_version
from azure.mgmt.network.models import PublicIPAddress, NetworkSecurityGroup, SecurityRule, NetworkInterface, \ from azure.mgmt.network.models import PublicIPAddress, NetworkSecurityGroup, SecurityRule, NetworkInterface, \
NetworkInterfaceIPConfiguration, Subnet NetworkInterfaceIPConfiguration, Subnet
from azure.common.credentials import ServicePrincipalCredentials, UserPassCredentials from azure.common.credentials import ServicePrincipalCredentials, UserPassCredentials
from azure.mgmt.network.network_management_client import NetworkManagementClient,\ from azure.mgmt.network.network_management_client import NetworkManagementClient
NetworkManagementClientConfiguration from azure.mgmt.resource.resources.resource_management_client import ResourceManagementClient
from azure.mgmt.resource.resources.resource_management_client import ResourceManagementClient,\ from azure.mgmt.storage.storage_management_client import StorageManagementClient
ResourceManagementClientConfiguration from azure.mgmt.compute.compute_management_client import ComputeManagementClient
from azure.mgmt.storage.storage_management_client import StorageManagementClient,\
StorageManagementClientConfiguration
from azure.mgmt.compute.compute_management_client import ComputeManagementClient,\
ComputeManagementClientConfiguration
from azure.storage.cloudstorageaccount import CloudStorageAccount from azure.storage.cloudstorageaccount import CloudStorageAccount
except ImportError as exc: except ImportError as exc:
HAS_AZURE_EXC = exc HAS_AZURE_EXC = exc
@ -136,9 +130,10 @@ class AzureRMModuleBase(object):
if not HAS_AZURE: if not HAS_AZURE:
self.fail("The Azure Python SDK is not installed (try 'pip install azure') - {0}".format(HAS_AZURE_EXC)) self.fail("The Azure Python SDK is not installed (try 'pip install azure') - {0}".format(HAS_AZURE_EXC))
if azure_compute_version < AZURE_MIN_VERSION: # re-enable after SDK hits release
self.fail("Expecting azure.mgmt.compute.__version__ to be >= {0}. Found version {1} " # if azure_compute_version < AZURE_MIN_VERSION:
"Do you have Azure >= 2.0.0rc2 installed?".format(AZURE_MIN_VERSION, azure_compute_version)) # self.fail("Expecting azure.mgmt.compute.__version__ to be >= {0}. Found version {1} "
# "Do you have Azure >= 2.0.0rc2 installed?".format(AZURE_MIN_VERSION, azure_compute_version))
self._network_client = None self._network_client = None
self._storage_client = None self._storage_client = None
@ -405,7 +400,7 @@ class AzureRMModuleBase(object):
serializer = Serializer() serializer = Serializer()
return serializer.body(obj, class_name) return serializer.body(obj, class_name)
def get_poller_result(self, poller, wait=20): def get_poller_result(self, poller, wait=5):
''' '''
Consistent method of waiting on and retrieving results from Azure's long poller Consistent method of waiting on and retrieving results from Azure's long poller
@ -596,9 +591,8 @@ class AzureRMModuleBase(object):
def storage_client(self): def storage_client(self):
self.log('Getting storage client...') self.log('Getting storage client...')
if not self._storage_client: if not self._storage_client:
config = StorageManagementClientConfiguration(self.azure_credentials, self.subscription_id) config = StorageManagementClientConfiguration()
config.add_user_agent(ANSIBLE_USER_AGENT) self._storage_client = StorageManagementClient(self.azure_credentials, self.subscription_id)
self._storage_client = StorageManagementClient(config)
self._register('Microsoft.Storage') self._register('Microsoft.Storage')
return self._storage_client return self._storage_client
@ -606,9 +600,7 @@ class AzureRMModuleBase(object):
def network_client(self): def network_client(self):
self.log('Getting network client') self.log('Getting network client')
if not self._network_client: if not self._network_client:
config = NetworkManagementClientConfiguration(self.azure_credentials, self.subscription_id) self._network_client = NetworkManagementClient(self.azure_credentials, self.subscription_id)
config.add_user_agent(ANSIBLE_USER_AGENT)
self._network_client = NetworkManagementClient(config)
self._register('Microsoft.Network') self._register('Microsoft.Network')
return self._network_client return self._network_client
@ -616,17 +608,13 @@ class AzureRMModuleBase(object):
def rm_client(self): def rm_client(self):
self.log('Getting resource manager client') self.log('Getting resource manager client')
if not self._resource_client: if not self._resource_client:
config = ResourceManagementClientConfiguration(self.azure_credentials, self.subscription_id) self._resource_client = ResourceManagementClient(self.azure_credentials, self.subscription_id)
config.add_user_agent(ANSIBLE_USER_AGENT)
self._resource_client = ResourceManagementClient(config)
return self._resource_client return self._resource_client
@property @property
def compute_client(self): def compute_client(self):
self.log('Getting compute client') self.log('Getting compute client')
if not self._compute_client: if not self._compute_client:
config = ComputeManagementClientConfiguration(self.azure_credentials, self.subscription_id) self._compute_client = ComputeManagementClient(self.azure_credentials, self.subscription_id)
config.add_user_agent(ANSIBLE_USER_AGENT)
self._compute_client = ComputeManagementClient(config)
self._register('Microsoft.Compute') self._register('Microsoft.Compute')
return self._compute_client return self._compute_client

Loading…
Cancel
Save