mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 13:50:22 -07:00
Adds description param to bigip_data_group (#49527)
This commit is contained in:
parent
60b75c2cfd
commit
1c644fb042
1 changed files with 66 additions and 11 deletions
|
@ -25,6 +25,10 @@ options:
|
||||||
description:
|
description:
|
||||||
- Specifies the name of the data group.
|
- Specifies the name of the data group.
|
||||||
required: True
|
required: True
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- The description of the monitor.
|
||||||
|
version_added: 2.8
|
||||||
type:
|
type:
|
||||||
description:
|
description:
|
||||||
- The type of records in this data group.
|
- The type of records in this data group.
|
||||||
|
@ -274,6 +278,7 @@ try:
|
||||||
from library.module_utils.compat.ipaddress import ip_network
|
from library.module_utils.compat.ipaddress import ip_network
|
||||||
from library.module_utils.compat.ipaddress import ip_interface
|
from library.module_utils.compat.ipaddress import ip_interface
|
||||||
from library.module_utils.network.f5.icontrol import upload_file
|
from library.module_utils.network.f5.icontrol import upload_file
|
||||||
|
from library.module_utils.network.f5.compare import cmp_str_with_none
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from ansible.module_utils.network.f5.bigip import F5RestClient
|
from ansible.module_utils.network.f5.bigip import F5RestClient
|
||||||
from ansible.module_utils.network.f5.common import F5ModuleError
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||||
|
@ -288,6 +293,7 @@ except ImportError:
|
||||||
from ansible.module_utils.compat.ipaddress import ip_network
|
from ansible.module_utils.compat.ipaddress import ip_network
|
||||||
from ansible.module_utils.compat.ipaddress import ip_interface
|
from ansible.module_utils.compat.ipaddress import ip_interface
|
||||||
from ansible.module_utils.network.f5.icontrol import upload_file
|
from ansible.module_utils.network.f5.icontrol import upload_file
|
||||||
|
from ansible.module_utils.network.f5.compare import cmp_str_with_none
|
||||||
|
|
||||||
|
|
||||||
LINE_LIMIT = 65000
|
LINE_LIMIT = 65000
|
||||||
|
@ -502,19 +508,25 @@ class RecordsDecoder(object):
|
||||||
|
|
||||||
class Parameters(AnsibleF5Parameters):
|
class Parameters(AnsibleF5Parameters):
|
||||||
api_map = {
|
api_map = {
|
||||||
'externalFileName': 'external_file_name'
|
'externalFileName': 'external_file_name',
|
||||||
}
|
}
|
||||||
|
|
||||||
api_attributes = [
|
api_attributes = [
|
||||||
'records', 'type'
|
'records',
|
||||||
|
'type',
|
||||||
|
'description',
|
||||||
]
|
]
|
||||||
|
|
||||||
returnables = [
|
returnables = [
|
||||||
'type', 'records'
|
'type',
|
||||||
|
'records',
|
||||||
|
'description',
|
||||||
]
|
]
|
||||||
|
|
||||||
updatables = [
|
updatables = [
|
||||||
'records', 'checksum'
|
'records',
|
||||||
|
'checksum',
|
||||||
|
'description',
|
||||||
]
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -533,11 +545,15 @@ class Parameters(AnsibleF5Parameters):
|
||||||
return self._values['records_src']
|
return self._values['records_src']
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if self._values['records_src']:
|
if self._values['records_src']:
|
||||||
records = open(self._values['records_src'])
|
records = open(self._values['records_src'])
|
||||||
else:
|
else:
|
||||||
records = self._values['records']
|
records = self._values['records']
|
||||||
|
|
||||||
|
if records is None:
|
||||||
|
return None
|
||||||
|
|
||||||
# There is a 98% chance that the user will supply a data group that is < 1MB.
|
# There is a 98% chance that the user will supply a data group that is < 1MB.
|
||||||
# 99.917% chance it is less than 10 MB. This is well within the range of typical
|
# 99.917% chance it is less than 10 MB. This is well within the range of typical
|
||||||
# memory available on a system.
|
# memory available on a system.
|
||||||
|
@ -581,12 +597,28 @@ class ApiParameters(Parameters):
|
||||||
def records_list(self):
|
def records_list(self):
|
||||||
return self.records
|
return self.records
|
||||||
|
|
||||||
|
@property
|
||||||
|
def description(self):
|
||||||
|
if self._values['description'] in [None, 'none']:
|
||||||
|
return None
|
||||||
|
return self._values['description']
|
||||||
|
|
||||||
|
|
||||||
class ModuleParameters(Parameters):
|
class ModuleParameters(Parameters):
|
||||||
|
@property
|
||||||
|
def description(self):
|
||||||
|
if self._values['description'] is None:
|
||||||
|
return None
|
||||||
|
elif self._values['description'] in ['none', '']:
|
||||||
|
return ''
|
||||||
|
return self._values['description']
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def checksum(self):
|
def checksum(self):
|
||||||
if self._values['checksum']:
|
if self._values['checksum']:
|
||||||
return self._values['checksum']
|
return self._values['checksum']
|
||||||
|
if self.records_src is None:
|
||||||
|
return None
|
||||||
result = hashlib.sha1()
|
result = hashlib.sha1()
|
||||||
records = self.records_src
|
records = self.records_src
|
||||||
while True:
|
while True:
|
||||||
|
@ -613,6 +645,8 @@ class ModuleParameters(Parameters):
|
||||||
@property
|
@property
|
||||||
def records(self):
|
def records(self):
|
||||||
results = []
|
results = []
|
||||||
|
if self.records_src is None:
|
||||||
|
return None
|
||||||
decoder = RecordsDecoder(record_type=self.type, separator=self.separator)
|
decoder = RecordsDecoder(record_type=self.type, separator=self.separator)
|
||||||
for record in self.records_src:
|
for record in self.records_src:
|
||||||
result = decoder.decode(record)
|
result = decoder.decode(record)
|
||||||
|
@ -693,9 +727,15 @@ class Difference(object):
|
||||||
def checksum(self):
|
def checksum(self):
|
||||||
if self.want.internal:
|
if self.want.internal:
|
||||||
return None
|
return None
|
||||||
|
if self.want.checksum is None:
|
||||||
|
return None
|
||||||
if self.want.checksum != self.have.checksum:
|
if self.want.checksum != self.have.checksum:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def description(self):
|
||||||
|
return cmp_str_with_none(self.want.description, self.have.description)
|
||||||
|
|
||||||
|
|
||||||
class BaseManager(object):
|
class BaseManager(object):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -911,7 +951,7 @@ class ExternalManager(BaseManager):
|
||||||
self.have = self.read_current_from_device()
|
self.have = self.read_current_from_device()
|
||||||
if not self.should_update():
|
if not self.should_update():
|
||||||
return False
|
return False
|
||||||
if zero_length(self.want.records_src):
|
if self.changes.records_src and zero_length(self.want.records_src):
|
||||||
raise F5ModuleError(
|
raise F5ModuleError(
|
||||||
"An external data group cannot be empty."
|
"An external data group cannot be empty."
|
||||||
)
|
)
|
||||||
|
@ -1035,8 +1075,11 @@ class ExternalManager(BaseManager):
|
||||||
params = dict(
|
params = dict(
|
||||||
name=self.want.name,
|
name=self.want.name,
|
||||||
partition=self.want.partition,
|
partition=self.want.partition,
|
||||||
externalFileName=external_file
|
externalFileName=external_file,
|
||||||
)
|
)
|
||||||
|
if self.want.description:
|
||||||
|
params['description'] = self.want.description
|
||||||
|
|
||||||
uri = "https://{0}:{1}/mgmt/tm/ltm/data-group/external/".format(
|
uri = "https://{0}:{1}/mgmt/tm/ltm/data-group/external/".format(
|
||||||
self.client.provider['server'],
|
self.client.provider['server'],
|
||||||
self.client.provider['server_port']
|
self.client.provider['server_port']
|
||||||
|
@ -1057,16 +1100,25 @@ class ExternalManager(BaseManager):
|
||||||
self.remove_file_on_device(remote_path)
|
self.remove_file_on_device(remote_path)
|
||||||
|
|
||||||
def update_on_device(self):
|
def update_on_device(self):
|
||||||
name = self.want.external_file_name
|
params = {}
|
||||||
remote_path = '/var/config/rest/downloads/{0}'.format(name)
|
|
||||||
external_file = self._upload_to_file(name, self.have.type, remote_path, update=True)
|
if self.want.records_src is not None:
|
||||||
|
name = self.want.external_file_name
|
||||||
|
remote_path = '/var/config/rest/downloads/{0}'.format(name)
|
||||||
|
external_file = self._upload_to_file(name, self.have.type, remote_path, update=True)
|
||||||
|
params['externalFileName'] = external_file
|
||||||
|
if self.changes.description is not None:
|
||||||
|
params['description'] = self.changes.description
|
||||||
|
|
||||||
|
if not params:
|
||||||
|
return
|
||||||
|
|
||||||
uri = "https://{0}:{1}/mgmt/tm/ltm/data-group/external/{2}".format(
|
uri = "https://{0}:{1}/mgmt/tm/ltm/data-group/external/{2}".format(
|
||||||
self.client.provider['server'],
|
self.client.provider['server'],
|
||||||
self.client.provider['server_port'],
|
self.client.provider['server_port'],
|
||||||
transform_name(self.want.partition, self.want.name)
|
transform_name(self.want.partition, self.want.name)
|
||||||
)
|
)
|
||||||
params = {'externalFileName': external_file}
|
|
||||||
resp = self.client.api.patch(uri, json=params)
|
resp = self.client.api.patch(uri, json=params)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -1165,7 +1217,9 @@ class ExternalManager(BaseManager):
|
||||||
raise F5ModuleError(response['message'])
|
raise F5ModuleError(response['message'])
|
||||||
else:
|
else:
|
||||||
raise F5ModuleError(resp.content)
|
raise F5ModuleError(resp.content)
|
||||||
return ApiParameters(params=response)
|
result = ApiParameters(params=response)
|
||||||
|
result.update({'description': response_dg.get('description', None)})
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
class ModuleManager(object):
|
class ModuleManager(object):
|
||||||
|
@ -1209,6 +1263,7 @@ class ArgumentSpec(object):
|
||||||
records_src=dict(type='path'),
|
records_src=dict(type='path'),
|
||||||
external_file_name=dict(),
|
external_file_name=dict(),
|
||||||
separator=dict(default=':='),
|
separator=dict(default=':='),
|
||||||
|
description=dict(),
|
||||||
state=dict(choices=['absent', 'present'], default='present'),
|
state=dict(choices=['absent', 'present'], default='present'),
|
||||||
partition=dict(
|
partition=dict(
|
||||||
default='Common',
|
default='Common',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue