Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify azure_rm_common, Support SDK track2 #670

Merged
merged 1 commit into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions plugins/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def default_api_version(self):
import azure.mgmt.datalake.store.models as DataLakeStoreAccountModel
from azure.mgmt.notificationhubs import NotificationHubsManagementClient
from azure.mgmt.eventhub import EventHubManagementClient
from azure.identity._credentials import client_secret

except ImportError as exc:
Authentication = object
Expand Down Expand Up @@ -724,7 +725,7 @@ def create_default_pip(self, resource_group, location, public_ip_name, allocatio
self.log("Check to see if public IP {0} exists".format(public_ip_name))
try:
pip = self.network_client.public_ip_addresses.get(resource_group, public_ip_name)
except CloudError:
except Exception:
pass

if pip:
Expand Down Expand Up @@ -764,7 +765,7 @@ def create_default_securitygroup(self, resource_group, location, security_group_
self.log("Check to see if security group {0} exists".format(security_group_name))
try:
group = self.network_client.network_security_groups.get(resource_group, security_group_name)
except CloudError:
except Exception:
pass

if group:
Expand Down Expand Up @@ -875,7 +876,7 @@ def get_graphrbac_client(self, tenant_id):

return client

def get_mgmt_svc_client(self, client_type, base_url=None, api_version=None, suppress_subscription_id=False):
def get_mgmt_svc_client(self, client_type, base_url=None, api_version=None, suppress_subscription_id=False, is_track2=False):
self.log('Getting management service client {0}'.format(client_type.__name__))
self.check_client_version(client_type)

Expand All @@ -887,9 +888,15 @@ def get_mgmt_svc_client(self, client_type, base_url=None, api_version=None, supp

# Some management clients do not take a subscription ID as parameters.
if suppress_subscription_id:
client_kwargs = dict(credentials=self.azure_auth.azure_credentials, base_url=base_url)
if is_track2:
client_kwargs = dict(credential=self.azure_auth.azure_credential_track2, base_url=base_url)
else:
client_kwargs = dict(credentials=self.azure_auth.azure_credentials, base_url=base_url)
else:
client_kwargs = dict(credentials=self.azure_auth.azure_credentials, subscription_id=self.azure_auth.subscription_id, base_url=base_url)
if is_track2:
client_kwargs = dict(credential=self.azure_auth.azure_credential_track2, subscription_id=self.azure_auth.subscription_id, base_url=base_url)
else:
client_kwargs = dict(credentials=self.azure_auth.azure_credentials, subscription_id=self.azure_auth.subscription_id, base_url=base_url)

api_profile_dict = {}

Expand Down Expand Up @@ -923,7 +930,8 @@ def _ansible_get_models(self, *arg, **kwarg):
setattr(client, '_ansible_models', importlib.import_module(client_type.__module__).models)
client.models = types.MethodType(_ansible_get_models, client)

client.config = self.add_user_agent(client.config)
if not is_track2:
client.config = self.add_user_agent(client.config)

if self.azure_auth._cert_validation_mode == 'ignore':
client.config.session_configuration_callback = self._validation_ignore_callback
Expand Down Expand Up @@ -1483,6 +1491,9 @@ def __init__(self, auth_source=None, profile=None, subscription_id=None, client_
cloud_environment=self._cloud_environment,
resource=graph_resource if self.is_ad_resource else rm_resource,
verify=self._cert_validation_mode == 'validate')
self.azure_credential_track2 = client_secret.ClientSecretCredential(client_id=self.credentials['client_id'],
client_secret=self.credentials['secret'],
tenant_id=self.credentials['tenant'])

elif self.credentials.get('ad_user') is not None and \
self.credentials.get('password') is not None and \
Expand Down
3 changes: 2 additions & 1 deletion requirements-azure.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
packaging
requests[security]
xmltodict
azure-cli-core==2.11.1
azure-cli-core==2.26.1
azure-common==1.1.11
azure-identity==1.7.0
azure-mgmt-apimanagement==0.2.0
azure-mgmt-authorization==0.51.1
azure-mgmt-batch==5.0.1
Expand Down