Adds partition support to bigip_asm_policy (#32519)

This functionality requires version 3.0.4 of the f5-sdk
pull/32522/head
Tim Rupp 7 years ago committed by GitHub
parent 64871470e2
commit 9a13bf9bff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -93,11 +93,16 @@ options:
- SharePoint 2010 (https)
- Vulnerability Assessment Baseline
- Wordpress
partition:
description:
- Device partition to manage resources on.
default: Common
extends_documentation_fragment: f5
requirements:
- f5-sdk
- f5-sdk >= 3.0.4
author:
- Wojciech Wypior (@wojtek0806)
- Tim Rupp (@caphrim007)
'''
EXAMPLES = r'''
@ -283,10 +288,19 @@ class Parameters(AnsibleF5Parameters):
return dict(link=resource.selfLink)
return None
@property
def full_path(self):
return self._fqdn_name(self.name)
def _templates_from_device(self):
collection = self.client.api.tm.asm.policy_templates_s.get_collection()
return collection
def _fqdn_name(self, value):
if value is not None and not value.startswith('/'):
return '/{0}/{1}'.format(self.partition, value)
return value
def to_return(self):
result = {}
for returnable in self.returnables:
@ -538,7 +552,7 @@ class BaseManager(object):
def exists(self):
policies = self.client.api.tm.asm.policies_s.get_collection()
if any(p.name == self.want.name for p in policies):
if any(p.name == self.want.name and p.partition == self.want.partition for p in policies):
return True
return False
@ -602,7 +616,9 @@ class BaseManager(object):
def update_on_device(self):
params = self.changes.api_params()
policies = self.client.api.tm.asm.policies_s.get_collection()
resource = next((p for p in policies if p.name == self.want.name), None)
name = self.want.name
partition = self.want.partition
resource = next((p for p in policies if p.name == name and p.partition == partition), None)
if resource:
if not params['active']:
resource.modify(**params)
@ -635,7 +651,7 @@ class BaseManager(object):
def read_current_from_device(self):
policies = self.client.api.tm.asm.policies_s.get_collection()
for policy in policies:
if policy.name == self.want.name:
if policy.name == self.want.name and policy.partition == self.want.partition:
params = policy.attrs
params.update(dict(self_link=policy.selfLink))
return Parameters(params)
@ -647,7 +663,9 @@ class BaseManager(object):
name = os.path.split(self.want.file)[1]
tasks = self.client.api.tm.asm.tasks
result = tasks.import_policy_s.import_policy.create(
name=self.want.name, filename=name
name=self.want.name,
partition=self.want.partition,
filename=name
)
return result
@ -662,19 +680,23 @@ class BaseManager(object):
tasks = self.client.api.tm.asm.tasks
result = tasks.import_policy_s.import_policy.create(
name=self.want.name,
partition=self.want.partition,
policyTemplateReference=self.want.template_link
)
return result
def create_on_device(self):
result = self.client.api.tm.asm.policies_s.policy.create(
name=self.want.name
name=self.want.name,
partition=self.want.partition
)
return result
def remove_from_device(self):
policies = self.client.api.tm.asm.policies_s.get_collection()
resource = next((p for p in policies if p.name == self.want.name), None)
name = self.want.name
partition = self.want.partition
resource = next((p for p in policies if p.name == name and p.partition == partition), None)
if resource:
resource.delete()

Loading…
Cancel
Save