Changes exists() method logic in asm policy fetch, corrects documentation (#50560)

This commit is contained in:
Wojciech Wypior 2019-01-04 20:47:56 +01:00 committed by Tim Rupp
parent 8b1214596a
commit 7362c1d6ca

View file

@ -27,7 +27,6 @@ options:
dest: dest:
description: description:
- A directory to save the policy file into. - A directory to save the policy file into.
- Di
- This option is ignored when C(inline) is set to c(yes). - This option is ignored when C(inline) is set to c(yes).
type: path type: path
file: file:
@ -61,7 +60,7 @@ options:
type: bool type: bool
partition: partition:
description: description:
- Device partition to which contain ASM policy to export. - Device partition which contains ASM policy to export.
default: Common default: Common
extends_documentation_fragment: f5 extends_documentation_fragment: f5
author: author:
@ -396,11 +395,10 @@ class ModuleManager(object):
return self.create() return self.create()
def update(self): def update(self):
if os.path.exists(self.want.dest): if not self.want.force:
if not self.want.force: raise F5ModuleError(
raise F5ModuleError( "File '{0}' already exists.".format(self.want.fulldest)
"File '{0}' already exists".format(self.want.fulldest) )
)
self.execute() self.execute()
def create(self): def create(self):
@ -434,37 +432,9 @@ class ModuleManager(object):
return True return True
def exists(self): def exists(self):
name = '{0}~{1}'.format(self.client.provider['user'], self.want.file) if not self.want.inline:
tpath = '/ts/var/rest/{0}'.format( if os.path.exists(self.want.fulldest):
name, return True
)
params = dict(
command='run',
utilCmdArgs=tpath
)
uri = "https://{0}:{1}/mgmt/tm/util/unix-ls/".format(
self.client.provider['server'],
self.client.provider['server_port']
)
resp = self.client.api.post(uri, json=params)
try:
response = resp.json()
except ValueError as ex:
raise F5ModuleError(str(ex))
if 'code' in response and response['code'] in [400, 403]:
if 'message' in response:
raise F5ModuleError(response['message'])
else:
raise F5ModuleError(resp.content)
if 'commandResult' in response:
if 'cannot access' in response['commandResult']:
return False
return True
return False return False
def create_on_device(self): def create_on_device(self):