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

adding new clients to common #44804

Merged
merged 3 commits into from
Aug 29, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/ansible/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@
from adal.authentication_context import AuthenticationContext
from azure.mgmt.rdbms.postgresql import PostgreSQLManagementClient
from azure.mgmt.rdbms.mysql import MySQLManagementClient
from azure.mgmt.containerregistry import ContainerRegistryManagementClient
from azure.mgmt.containerinstance import ContainerInstanceManagementClient
except ImportError as exc:
HAS_AZURE_EXC = exc
HAS_AZURE = False
Expand Down Expand Up @@ -276,6 +278,8 @@ def __init__(self, derived_arg_spec, bypass_checks=False, no_log=False,
self._containerservice_client = None
self._mysql_client = None
self._postgresql_client = None
self._containerregistry_client = None
self._containerinstance_client = None
self._adfs_authority_url = None
self._resource = None

Expand Down Expand Up @@ -1075,3 +1079,23 @@ def mysql_client(self):
self._mysql_client = self.get_mgmt_svc_client(MySQLManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager)
return self._mysql_client

@property
def containerregistry_client(self):
self.log('Getting container registry mgmt client')
if not self._containerregistry_client:
self._containerregistry_client = self.get_mgmt_svc_client(ContainerRegistryManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
api_version='2017-10-01')

return self._containerregistry_client

@property
def containerinstance_client(self):
self.log('Getting container instance mgmt client')
if not self._containerinstance_client:
self._containerinstance_client = self.get_mgmt_svc_client(ContainerInstanceManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
api_version='2018-06-01')

return self._containerinstance_client
15 changes: 6 additions & 9 deletions lib/ansible/modules/cloud/azure/azure_rm_containerinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ def __init__(self):
self.containers = None

self.results = dict(changed=False, state=dict())
self.client = None
self.cgmodels = None

super(AzureRMContainerInstance, self).__init__(derived_arg_spec=self.module_arg_spec,
Expand All @@ -274,10 +273,8 @@ def exec_module(self, **kwargs):
response = None
results = dict()

self.client = self.get_mgmt_svc_client(ContainerInstanceManagementClient)

# since this client hasn't been upgraded to expose models directly off the OperationClass, fish them out
self.cgmodels = self.client.container_groups.models
self.cgmodels = self.containerinstance_client.container_groups.models

resource_group = self.get_resource_group(self.resource_group)

Expand Down Expand Up @@ -380,9 +377,9 @@ def create_update_containerinstance(self):
os_type=self.os_type,
volumes=None)

response = self.client.container_groups.create_or_update(resource_group_name=self.resource_group,
container_group_name=self.name,
container_group=parameters)
response = self.containerinstance_client.container_groups.create_or_update(resource_group_name=self.resource_group,
container_group_name=self.name,
container_group=parameters)

if isinstance(response, AzureOperationPoller):
response = self.get_poller_result(response)
Expand All @@ -396,7 +393,7 @@ def delete_containerinstance(self):
:return: True
'''
self.log("Deleting the container instance {0}".format(self.name))
response = self.client.container_groups.delete(resource_group_name=self.resource_group, container_group_name=self.name)
response = self.containerinstance_client.container_groups.delete(resource_group_name=self.resource_group, container_group_name=self.name)
return True

def get_containerinstance(self):
Expand All @@ -408,7 +405,7 @@ def get_containerinstance(self):
self.log("Checking if the container instance {0} is present".format(self.name))
found = False
try:
response = self.client.container_groups.get(resource_group_name=self.resource_group, container_group_name=self.name)
response = self.containerinstance_client.container_groups.get(resource_group_name=self.resource_group, container_group_name=self.name)
found = True
self.log("Response : {0}".format(response))
self.log("Container instance : {0} found".format(response.name))
Expand Down
29 changes: 8 additions & 21 deletions lib/ansible/modules/cloud/azure/azure_rm_containerregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ def __init__(self):
self.state = None
self.sku = None
self.tags = None
self._containerregistry_mgmt_client = None

self.results = dict(changed=False, state=dict())

Expand Down Expand Up @@ -315,9 +314,9 @@ def create_update_containerregistry(self, to_do):
try:
if to_do != Actions.NoAction:
if to_do == Actions.Create:
name_status = self.containerregistry_mgmt_client.registries.check_name_availability(self.name)
name_status = self.containerregistry_client.registries.check_name_availability(self.name)
if name_status.name_available:
poller = self.containerregistry_mgmt_client.registries.create(
poller = self.containerregistry_client.registries.create(
resource_group_name=self.resource_group,
registry_name=self.name,
registry=Registry(
Expand All @@ -332,9 +331,9 @@ def create_update_containerregistry(self, to_do):
else:
raise Exception("Invalid registry name. reason: " + name_status.reason + " message: " + name_status.message)
else:
registry = self.containerregistry_mgmt_client.registries.get(self.resource_group, self.name)
registry = self.containerregistry_client.registries.get(self.resource_group, self.name)
if registry is not None:
poller = self.containerregistry_mgmt_client.registries.update(
poller = self.containerregistry_client.registries.update(
resource_group_name=self.resource_group,
registry_name=self.name,
registry_update_parameters=RegistryUpdateParameters(
Expand All @@ -349,7 +348,7 @@ def create_update_containerregistry(self, to_do):
raise Exception("Update registry failed as registry '" + self.name + "' doesn't exist.")
response = self.get_poller_result(poller)
if self.admin_user_enabled:
credentials = self.containerregistry_mgmt_client.registries.list_credentials(self.resource_group, self.name)
credentials = self.containerregistry_client.registries.list_credentials(self.resource_group, self.name)
else:
self.log('Cannot perform credential operations as admin user is disabled')
credentials = None
Expand All @@ -369,7 +368,7 @@ def delete_containerregistry(self):
'''
self.log("Deleting the container registry instance {0}".format(self.name))
try:
self.containerregistry_mgmt_client.registries.delete(self.resource_group, self.name).wait()
self.containerregistry_client.registries.delete(self.resource_group, self.name).wait()
except CloudError as e:
self.log('Error attempting to delete the container registry instance.')
self.fail("Error deleting the container registry instance: {0}".format(str(e)))
Expand All @@ -385,7 +384,7 @@ def get_containerregistry(self):
self.log("Checking if the container registry instance {0} is present".format(self.name))
found = False
try:
response = self.containerregistry_mgmt_client.registries.get(self.resource_group, self.name)
response = self.containerregistry_client.registries.get(self.resource_group, self.name)
found = True
self.log("Response : {0}".format(response))
self.log("Container registry instance : {0} found".format(response.name))
Expand All @@ -397,7 +396,7 @@ def get_containerregistry(self):
response = None
if found is True and self.admin_user_enabled is True:
try:
credentials = self.containerregistry_mgmt_client.registries.list_credentials(self.resource_group, self.name)
credentials = self.containerregistry_client.registries.list_credentials(self.resource_group, self.name)
except CloudError as e:
self.fail('List registry credentials failed: {0}'.format(str(e)))
credentials = None
Expand All @@ -407,18 +406,6 @@ def get_containerregistry(self):
return None
return create_containerregistry_dict(response, credentials)

@property
def containerregistry_mgmt_client(self):
self.log('Getting container registry mgmt client')
if not self._containerregistry_mgmt_client:
self._containerregistry_mgmt_client = self.get_mgmt_svc_client(
ContainerRegistryManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
api_version='2017-10-01'
)

return self._containerregistry_mgmt_client


def main():
"""Main execution"""
Expand Down