Skip to content

Commit

Permalink
Merged changes of Azure modules from Ansible repo (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleazurebot authored and yuwzho committed May 5, 2019
1 parent afbcc3a commit 0fc8038
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
6 changes: 3 additions & 3 deletions files/sha.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lib/ansible/module_utils/azure_rm_common.py": "204db4d0444b2d1d3929774b5ac11b71893d3fb6",
"lib/ansible/modules/cloud/azure": "8de2acb81979cf09f661a74e1bc25bf4a3f453da",
"lib/ansible/module_utils/azure_rm_common.py": "c7bf3e035b3cc3304b0dcafc3437ba8ea0db30b4",
"lib/ansible/modules/cloud/azure": "fd2ea344445e6f70361d01abfc25236fd337a1ca",
"packaging/requirements/requirements-azure.txt": "8b1b22ddc7dad0d901ecbd96a982e34429bdfdb9",
"test/integration/targets": "0d3d0025055e03f778ef8f13abc4e8adb2f774b8"
"test/integration/targets": "cc3b8b9f729a6176434a6e76d9940869b8b226c5"
}
2 changes: 1 addition & 1 deletion library/azure_rm_roledefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def exec_module(self, **kwargs):

# build scope
def build_scope(self):
subscription_scope = '/subscription/' + self.subscription_id
subscription_scope = '/subscriptions/' + self.subscription_id
if self.scope is None:
return subscription_scope
return self.scope
Expand Down
42 changes: 26 additions & 16 deletions library/azure_rm_virtualnetworkpeering.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@

try:
from msrestazure.azure_exceptions import CloudError
from msrestazure.tools import is_valid_resource_id
from msrest.polling import LROPoller
except ImportError:
# This is handled in azure_rm_common
Expand Down Expand Up @@ -234,7 +235,7 @@ def exec_module(self, **kwargs):
self.fail('Resource group of virtual_network is not same as param resource_group')

# parse remote virtual_network
self.remote_virtual_network = self.parse_resource_to_dict(self.remote_virtual_network)
self.remote_virtual_network = self.format_vnet_id(self.remote_virtual_network)

# get vnet peering
response = self.get_vnet_peering()
Expand All @@ -248,9 +249,7 @@ def exec_module(self, **kwargs):
self.fail("Cannot update virtual_network of Virtual Network Peering!")

# check remote vnet id not changed
exisiting_remote_vnet = self.parse_resource_to_dict(response['remote_virtual_network'])
if exisiting_remote_vnet['resource_group'] != self.remote_virtual_network['resource_group'] or \
exisiting_remote_vnet['name'] != self.remote_virtual_network['name']:
if response['remote_virtual_network'].lower() != self.remote_virtual_network.lower():
self.fail("Cannot update remote_virtual_network of Virtual Network Peering!")

# check if update
Expand All @@ -266,12 +265,6 @@ def exec_module(self, **kwargs):
self.fail("Virtual network {0} in resource group {1} does not exist!".format(
self.virtual_network['name'], self.virtual_network['resource_group']))

# check if remote vnet exists
remote_virtual_network = self.get_vnet(self.remote_virtual_network['resource_group'], self.remote_virtual_network['name'])
if not remote_virtual_network:
self.fail("Virtual network {0} in resource group {1} does not exist!".format(
self.remote_virtual_network['name'], self.remote_virtual_network['resource_group']))

elif self.state == 'absent':
if response:
self.log('Delete Azure Virtual Network Peering')
Expand All @@ -297,6 +290,28 @@ def exec_module(self, **kwargs):

return self.results

def format_vnet_id(self, vnet):
if not vnet:
return vnet
if isinstance(vnet, dict) and vnet.get('name') and vnet.get('resource_group'):
remote_vnet_id = format_resource_id(vnet['name'],
self.subscription_id,
'Microsoft.Network',
'virtualNetworks',
vnet['resource_group'])
elif isinstance(vnet, str):
if is_valid_resource_id(vnet):
remote_vnet_id = vnet
else:
remote_vnet_id = format_resource_id(vnet,
self.subscription_id,
'Microsoft.Network',
'virtualNetworks',
self.resource_group)
else:
self.fail("remote_virtual_network could be a valid resource id, dict of name and resource_group, name of virtual network in same resource group.")
return remote_vnet_id

def check_update(self, exisiting_vnet_peering):
if self.allow_forwarded_traffic != exisiting_vnet_peering['allow_forwarded_traffic']:
return True
Expand Down Expand Up @@ -334,15 +349,10 @@ def create_or_update_vnet_peering(self):
'Microsoft.Network',
'virtualNetworks',
self.virtual_network['resource_group'])
remote_vnet_id = format_resource_id(self.remote_virtual_network['name'],
self.subscription_id,
'Microsoft.Network',
'virtualNetworks',
self.remote_virtual_network['resource_group'])
peering = self.network_models.VirtualNetworkPeering(
id=vnet_id,
name=self.name,
remote_virtual_network=self.network_models.SubResource(id=remote_vnet_id),
remote_virtual_network=self.network_models.SubResource(id=self.remote_virtual_network),
allow_virtual_network_access=self.allow_virtual_network_access,
allow_gateway_transit=self.allow_gateway_transit,
allow_forwarded_traffic=self.allow_forwarded_traffic,
Expand Down
2 changes: 1 addition & 1 deletion module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ def _get_credentials(self, params):

if auth_source == 'credential_file':
self.log("Retrieving credentials from credential file")
profile = params.get('profile', 'default')
profile = params.get('profile') or 'default'
default_credentials = self._get_profile(profile)
return default_credentials

Expand Down

0 comments on commit 0fc8038

Please sign in to comment.