mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-04 15:29:10 -07:00
add new module: azure_rm_rediscachefirewallrule (#53161)
This commit is contained in:
parent
bc4ef99533
commit
9e42038747
5 changed files with 499 additions and 75 deletions
|
@ -17,9 +17,9 @@ DOCUMENTATION = '''
|
|||
---
|
||||
module: azure_rm_rediscache
|
||||
version_added: "2.8"
|
||||
short_description: Manage Azure Redis Cache instance.
|
||||
short_description: Manage Azure Cache for Redis instance.
|
||||
description:
|
||||
- Create, update and delete instance of Azure Redis Cache.
|
||||
- Create, update and delete instance of Azure Cache for Redis.
|
||||
|
||||
options:
|
||||
resource_group:
|
||||
|
@ -28,17 +28,16 @@ options:
|
|||
required: True
|
||||
name:
|
||||
description:
|
||||
- Unique name of the redis cache to create or update. To create or update a deployment slot, use the {slot} parameter.
|
||||
- Unique name of the Azure Cache for Redis to create or update.
|
||||
required: True
|
||||
|
||||
location:
|
||||
description:
|
||||
- Resource location. If not set, location from the resource group will be used as default.
|
||||
sku:
|
||||
description: Sku info of redis cache.
|
||||
description: Sku info of Azure Cache for Redis.
|
||||
suboptions:
|
||||
name:
|
||||
description: Type of redis cache to deploy
|
||||
description: Type of Azure Cache for Redis to deploy
|
||||
choices:
|
||||
- basic
|
||||
- standard
|
||||
|
@ -46,7 +45,7 @@ options:
|
|||
required: True
|
||||
size:
|
||||
description:
|
||||
- Size of redis cache to deploy.
|
||||
- Size of Azure Cache for Redis to deploy.
|
||||
- When I(sku) is C(basic) or C(standard), allowed values are C0, C1, C2, C3, C4, C5, C6.
|
||||
- When I(sku) is C(premium), allowed values are P1, P2, P3, P4.
|
||||
- Please see U(https://docs.microsoft.com/en-us/rest/api/redis/redis/create#sku) for allowed values.
|
||||
|
@ -97,10 +96,10 @@ options:
|
|||
type: int
|
||||
static_ip:
|
||||
description:
|
||||
- Static IP address. Required when deploying a redis cache inside an existing Azure virtual network.
|
||||
- Static IP address. Required when deploying an Azure Cache for Redis inside an existing Azure virtual network.
|
||||
subnet:
|
||||
description:
|
||||
- Subnet in a virtual network to deploy the redis cache in.
|
||||
- Subnet in a virtual network to deploy the Azure Cache for Redis in.
|
||||
- "It can be resource id of subnet, eg.
|
||||
/subscriptions/{subid}/resourceGroups/{resourceGroupName}/Microsoft.{Network|ClassicNetwork}/VirtualNetworks/vnet1/subnets/subnet1"
|
||||
- It can be a dictionary where contains C(name), C(virtual_network_name) and C(resource_group).
|
||||
|
@ -112,8 +111,8 @@ options:
|
|||
- Dict of tenant settings.
|
||||
state:
|
||||
description:
|
||||
- Assert the state of the redis cache.
|
||||
- Use C(present) to create or update a redis cache and C(absent) to delete it.
|
||||
- Assert the state of the Azure Cache for Redis.
|
||||
- Use C(present) to create or update an Azure Cache for Redis and C(absent) to delete it.
|
||||
default: present
|
||||
choices:
|
||||
- absent
|
||||
|
@ -129,7 +128,7 @@ author:
|
|||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Create a redis cache
|
||||
- name: Create an Azure Cache for Redis
|
||||
azure_rm_rediscache:
|
||||
resource_group: myResourceGroup
|
||||
name: myRedis
|
||||
|
@ -138,7 +137,7 @@ EXAMPLES = '''
|
|||
size: C1
|
||||
|
||||
|
||||
- name: Scale up the redis cache
|
||||
- name: Scale up the Azure Cache for Redis
|
||||
azure_rm_rediscache:
|
||||
resource_group: myResourceGroup
|
||||
name: myRedis
|
||||
|
@ -148,7 +147,7 @@ EXAMPLES = '''
|
|||
tags:
|
||||
testing: foo
|
||||
|
||||
- name: Create redis with subnet
|
||||
- name: Create Azure Cache for Redis with subnet
|
||||
azure_rm_rediscache:
|
||||
resource_group: myResourceGroup
|
||||
name: myRedis
|
||||
|
@ -162,14 +161,14 @@ EXAMPLES = '''
|
|||
|
||||
RETURN = '''
|
||||
id:
|
||||
description: Id of the redis cache.
|
||||
description: Id of the Azure Cache for Redis.
|
||||
returned: always
|
||||
type: str
|
||||
sample: {
|
||||
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Cache/Redis/myRedis"
|
||||
}
|
||||
host_name:
|
||||
description: Host name of the redis cache.
|
||||
description: Host name of the Azure Cache for Redis.
|
||||
returned: state is present
|
||||
type: str
|
||||
sample: {
|
||||
|
@ -242,7 +241,7 @@ class Actions:
|
|||
|
||||
|
||||
class AzureRMRedisCaches(AzureRMModuleBase):
|
||||
"""Configuration class for an Azure RM Redis Cache resource"""
|
||||
"""Configuration class for an Azure RM Cache for Redis resource"""
|
||||
|
||||
def __init__(self):
|
||||
self.module_arg_spec = dict(
|
||||
|
@ -329,8 +328,6 @@ class AzureRMRedisCaches(AzureRMModuleBase):
|
|||
self.state = None
|
||||
self.to_do = Actions.NoAction
|
||||
|
||||
self.frameworks = None
|
||||
|
||||
super(AzureRMRedisCaches, self).__init__(derived_arg_spec=self.module_arg_spec,
|
||||
supports_check_mode=True,
|
||||
supports_tags=True)
|
||||
|
@ -365,7 +362,7 @@ class AzureRMRedisCaches(AzureRMModuleBase):
|
|||
if self.subnet:
|
||||
self.subnet = self.parse_subnet()
|
||||
|
||||
# get existing redis cache
|
||||
# get existing Azure Cache for Redis
|
||||
old_response = self.get_rediscache()
|
||||
|
||||
if old_response:
|
||||
|
@ -374,17 +371,17 @@ class AzureRMRedisCaches(AzureRMModuleBase):
|
|||
if self.state == 'present':
|
||||
# if redis not exists
|
||||
if not old_response:
|
||||
self.log("Redis cache instance doesn't exist")
|
||||
self.log("Azure Cache for Redis instance doesn't exist")
|
||||
|
||||
to_be_updated = True
|
||||
self.to_do = Actions.Create
|
||||
|
||||
if not self.sku:
|
||||
self.fail("Please specify sku to creating new redis cache.")
|
||||
self.fail("Please specify sku to creating new Azure Cache for Redis.")
|
||||
|
||||
else:
|
||||
# redis exists already, do update
|
||||
self.log("Redis cache instance already exists")
|
||||
self.log("Azure Cache for Redis instance already exists")
|
||||
|
||||
update_tags, self.tags = self.update_tags(old_response.get('tags', None))
|
||||
|
||||
|
@ -399,16 +396,16 @@ class AzureRMRedisCaches(AzureRMModuleBase):
|
|||
|
||||
elif self.state == 'absent':
|
||||
if old_response:
|
||||
self.log("Delete Redis cache instance")
|
||||
self.log("Delete Azure Cache for Redis instance")
|
||||
self.results['id'] = old_response['id']
|
||||
to_be_updated = True
|
||||
self.to_do = Actions.Delete
|
||||
else:
|
||||
self.results['changed'] = False
|
||||
self.log("Redis cache {0} not exists.".format(self.name))
|
||||
self.log("Azure Cache for Redis {0} not exists.".format(self.name))
|
||||
|
||||
if to_be_updated:
|
||||
self.log('Need to Create/Update redis cache')
|
||||
self.log('Need to Create/Update Azure Cache for Redis')
|
||||
self.results['changed'] = True
|
||||
|
||||
if self.check_mode:
|
||||
|
@ -426,7 +423,7 @@ class AzureRMRedisCaches(AzureRMModuleBase):
|
|||
|
||||
if self.to_do == Actions.Delete:
|
||||
self.delete_rediscache()
|
||||
self.log('Redis cache instance deleted')
|
||||
self.log('Azure Cache for Redis instance deleted')
|
||||
|
||||
return self.results
|
||||
|
||||
|
@ -461,12 +458,12 @@ class AzureRMRedisCaches(AzureRMModuleBase):
|
|||
|
||||
def create_rediscache(self):
|
||||
'''
|
||||
Creates redis cache instance with the specified configuration.
|
||||
Creates Azure Cache for Redis instance with the specified configuration.
|
||||
|
||||
:return: deserialized redis cache instance state dictionary
|
||||
:return: deserialized Azure Cache for Redis instance state dictionary
|
||||
'''
|
||||
self.log(
|
||||
"Creating redis cache instance {0}".format(self.name))
|
||||
"Creating Azure Cache for Redis instance {0}".format(self.name))
|
||||
|
||||
try:
|
||||
redis_config = dict()
|
||||
|
@ -493,19 +490,19 @@ class AzureRMRedisCaches(AzureRMModuleBase):
|
|||
response = self.get_poller_result(response)
|
||||
|
||||
except CloudError as exc:
|
||||
self.log('Error attempting to create the redis cache instance.')
|
||||
self.log('Error attempting to create the Azure Cache for Redis instance.')
|
||||
self.fail(
|
||||
"Error creating the redis cache instance: {0}".format(str(exc)))
|
||||
"Error creating the Azure Cache for Redis instance: {0}".format(str(exc)))
|
||||
return rediscache_to_dict(response)
|
||||
|
||||
def update_rediscache(self):
|
||||
'''
|
||||
Updates redis cache instance with the specified configuration.
|
||||
Updates Azure Cache for Redis instance with the specified configuration.
|
||||
|
||||
:return: redis cache instance state dictionary
|
||||
:return: Azure Cache for Redis instance state dictionary
|
||||
'''
|
||||
self.log(
|
||||
"Updating redis cache instance {0}".format(self.name))
|
||||
"Updating Azure Cache for Redis instance {0}".format(self.name))
|
||||
|
||||
try:
|
||||
redis_config = dict()
|
||||
|
@ -529,34 +526,34 @@ class AzureRMRedisCaches(AzureRMModuleBase):
|
|||
response = self.get_poller_result(response)
|
||||
|
||||
except CloudError as exc:
|
||||
self.log('Error attempting to update the redis cache instance.')
|
||||
self.log('Error attempting to update the Azure Cache for Redis instance.')
|
||||
self.fail(
|
||||
"Error updating the redis cache instance: {0}".format(str(exc)))
|
||||
"Error updating the Azure Cache for Redis instance: {0}".format(str(exc)))
|
||||
return rediscache_to_dict(response)
|
||||
|
||||
def delete_rediscache(self):
|
||||
'''
|
||||
Deletes specified redis cache instance in the specified subscription and resource group.
|
||||
Deletes specified Azure Cache for Redis instance in the specified subscription and resource group.
|
||||
|
||||
:return: True
|
||||
'''
|
||||
self.log("Deleting the redis cache instance {0}".format(self.name))
|
||||
self.log("Deleting the Azure Cache for Redis instance {0}".format(self.name))
|
||||
try:
|
||||
response = self._client.redis.delete(resource_group_name=self.resource_group,
|
||||
name=self.name)
|
||||
except CloudError as e:
|
||||
self.log('Error attempting to delete the redis cache instance.')
|
||||
self.log('Error attempting to delete the Azure Cache for Redis instance.')
|
||||
self.fail(
|
||||
"Error deleting the redis cache instance: {0}".format(str(e)))
|
||||
"Error deleting the Azure Cache for Redis instance: {0}".format(str(e)))
|
||||
return True
|
||||
|
||||
def get_rediscache(self):
|
||||
'''
|
||||
Gets the properties of the specified redis cache instance.
|
||||
Gets the properties of the specified Azure Cache for Redis instance.
|
||||
|
||||
:return: redis cache instance state dictionary
|
||||
:return: Azure Cache for Redis instance state dictionary
|
||||
'''
|
||||
self.log("Checking if the redis cache instance {0} is present".format(self.name))
|
||||
self.log("Checking if the Azure Cache for Redis instance {0} is present".format(self.name))
|
||||
|
||||
response = None
|
||||
|
||||
|
@ -565,11 +562,11 @@ class AzureRMRedisCaches(AzureRMModuleBase):
|
|||
name=self.name)
|
||||
|
||||
self.log("Response : {0}".format(response))
|
||||
self.log("Redis cache instance : {0} found".format(response.name))
|
||||
self.log("Azure Cache for Redis instance : {0} found".format(response.name))
|
||||
return rediscache_to_dict(response)
|
||||
|
||||
except CloudError as ex:
|
||||
self.log("Didn't find redis cache {0} in resource group {1}".format(
|
||||
self.log("Didn't find Azure Cache for Redis {0} in resource group {1}".format(
|
||||
self.name, self.resource_group))
|
||||
|
||||
return False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue