Adds partition support to bigip_asm_policy (#32519)

This functionality requires version 3.0.4 of the f5-sdk
This commit is contained in:
Tim Rupp 2017-11-02 13:23:59 -07:00 committed by GitHub
parent 64871470e2
commit 9a13bf9bff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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