mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 21:31:26 -07:00
initial cutover to API profiles (#35538)
* hardcoded API profiles in azure_rm_common * changed azure_rm_securitygroup module to use api_profiles, dynamic models, kwargs on all SDK methods * changed azure_rm_containerinstance module to use api_profiles, dynamic models, kwargs on all SDK methods * fixed polling performance issue in azure_rm_securitygroup (default poll interval was 30s)
This commit is contained in:
parent
fd33dc6cd1
commit
26f551d1c3
6 changed files with 171 additions and 91 deletions
|
@ -145,14 +145,6 @@ from ansible.module_utils.azure_rm_common import AzureRMModuleBase
|
|||
|
||||
try:
|
||||
from msrestazure.azure_exceptions import CloudError
|
||||
from azure.mgmt.containerinstance.models import (ContainerGroup,
|
||||
Container,
|
||||
ResourceRequirements,
|
||||
ResourceRequests,
|
||||
ImageRegistryCredential,
|
||||
IpAddress,
|
||||
Port,
|
||||
ContainerPort)
|
||||
from azure.mgmt.containerinstance import ContainerInstanceManagementClient
|
||||
except ImportError:
|
||||
# This is handled in azure_rm_common
|
||||
|
@ -264,7 +256,8 @@ class AzureRMContainerInstance(AzureRMModuleBase):
|
|||
self.containers = None
|
||||
|
||||
self.results = dict(changed=False, state=dict())
|
||||
self.mgmt_client = None
|
||||
self.client = None
|
||||
self.cgmodels = None
|
||||
|
||||
super(AzureRMContainerInstance, self).__init__(derived_arg_spec=self.module_arg_spec,
|
||||
supports_check_mode=True,
|
||||
|
@ -280,8 +273,10 @@ class AzureRMContainerInstance(AzureRMModuleBase):
|
|||
response = None
|
||||
results = dict()
|
||||
|
||||
self.mgmt_client = self.get_mgmt_svc_client(ContainerInstanceManagementClient,
|
||||
base_url=self._cloud_environment.endpoints.resource_manager)
|
||||
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
|
||||
|
||||
resource_group = self.get_resource_group(self.resource_group)
|
||||
|
||||
|
@ -341,9 +336,9 @@ class AzureRMContainerInstance(AzureRMModuleBase):
|
|||
registry_credentials = None
|
||||
|
||||
if self.registry_login_server is not None:
|
||||
registry_credentials = [ImageRegistryCredential(server=self.registry_login_server,
|
||||
username=self.registry_username,
|
||||
password=self.registry_password)]
|
||||
registry_credentials = [self.cgmodels.ImageRegistryCredential(server=self.registry_login_server,
|
||||
username=self.registry_username,
|
||||
password=self.registry_password)]
|
||||
|
||||
ip_address = None
|
||||
|
||||
|
@ -352,8 +347,8 @@ class AzureRMContainerInstance(AzureRMModuleBase):
|
|||
if self.ports:
|
||||
ports = []
|
||||
for port in self.ports:
|
||||
ports.append(Port(port=port, protocol="TCP"))
|
||||
ip_address = IpAddress(ports=ports, ip=self.ip_address)
|
||||
ports.append(self.cgmodels.Port(port=port, protocol="TCP"))
|
||||
ip_address = self.cgmodels.IpAddress(ports=ports, ip=self.ip_address)
|
||||
|
||||
containers = []
|
||||
|
||||
|
@ -367,22 +362,26 @@ class AzureRMContainerInstance(AzureRMModuleBase):
|
|||
port_list = container_def.get("ports")
|
||||
if port_list:
|
||||
for port in port_list:
|
||||
ports.append(ContainerPort(port))
|
||||
ports.append(self.cgmodels.ContainerPort(port=port))
|
||||
|
||||
containers.append(Container(name=name,
|
||||
image=image,
|
||||
resources=ResourceRequirements(ResourceRequests(memory_in_gb=memory, cpu=cpu)),
|
||||
ports=ports))
|
||||
containers.append(self.cgmodels.Container(name=name,
|
||||
image=image,
|
||||
resources=self.cgmodels.ResourceRequirements(
|
||||
requests=self.cgmodels.ResourceRequests(memory_in_gb=memory, cpu=cpu)
|
||||
),
|
||||
ports=ports))
|
||||
|
||||
parameters = ContainerGroup(location=self.location,
|
||||
containers=containers,
|
||||
image_registry_credentials=registry_credentials,
|
||||
restart_policy=None,
|
||||
ip_address=ip_address,
|
||||
os_type=self.os_type,
|
||||
volumes=None)
|
||||
parameters = self.cgmodels.ContainerGroup(location=self.location,
|
||||
containers=containers,
|
||||
image_registry_credentials=registry_credentials,
|
||||
restart_policy=None,
|
||||
ip_address=ip_address,
|
||||
os_type=self.os_type,
|
||||
volumes=None)
|
||||
|
||||
response = self.mgmt_client.container_groups.create_or_update(self.resource_group, self.name, parameters)
|
||||
response = self.client.container_groups.create_or_update(resource_group_name=self.resource_group,
|
||||
container_group_name=self.name,
|
||||
container_group=parameters)
|
||||
|
||||
return response.as_dict()
|
||||
|
||||
|
@ -393,7 +392,7 @@ class AzureRMContainerInstance(AzureRMModuleBase):
|
|||
:return: True
|
||||
'''
|
||||
self.log("Deleting the container instance {0}".format(self.name))
|
||||
response = self.mgmt_client.container_groups.delete(self.resource_group, self.name)
|
||||
response = self.client.container_groups.delete(resource_group_name=self.resource_group, container_group_name=self.name)
|
||||
return True
|
||||
|
||||
def get_containerinstance(self):
|
||||
|
@ -405,7 +404,7 @@ class AzureRMContainerInstance(AzureRMModuleBase):
|
|||
self.log("Checking if the container instance {0} is present".format(self.name))
|
||||
found = False
|
||||
try:
|
||||
response = self.mgmt_client.container_groups.get(self.resource_group, self.name)
|
||||
response = self.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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue