mso_anp: Idempotency fixes (#51313)

This commit is contained in:
Dag Wieers 2019-01-25 03:53:43 +01:00 committed by GitHub
parent 6f63ba6520
commit fc4e93f1a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -161,47 +161,43 @@ def main():
mso.fail_json(msg="ANP '{anp}' not found".format(anp=anp)) mso.fail_json(msg="ANP '{anp}' not found".format(anp=anp))
mso.exit_json() mso.exit_json()
anps_path = '/templates/{0}/anps'.format(template)
anp_path = '/templates/{0}/anps/{1}'.format(template, anp)
ops = []
mso.previous = mso.existing mso.previous = mso.existing
if state == 'absent': if state == 'absent':
if mso.existing: if mso.existing:
mso.sent = mso.existing = {} mso.sent = mso.existing = {}
operation = [dict( ops.append(dict(op='remove', path=anp_path))
op='remove',
path='/templates/{template}/anps/{anp}'.format(template=template, anp=anp),
)]
if not module.check_mode:
mso.request(path, method='PATCH', data=operation)
elif state == 'present': elif state == 'present':
if display_name is None and not mso.existing: if display_name is None and not mso.existing:
display_name = anp display_name = anp
epgs = []
if mso.existing:
epgs = None
payload = dict( payload = dict(
name=anp, name=anp,
displayName=display_name, displayName=display_name,
# FIXME: This may cause your existing EPGs to be removed epgs=epgs,
epgs=[],
) )
mso.sanitize(payload, collate=True) mso.sanitize(payload, collate=True)
if mso.existing: if mso.existing:
operation = [dict( if display_name is not None:
op='replace', ops.append(dict(op='replace', path=anp_path + '/displayName', value=display_name))
path='/templates/{template}/anps/{anp}'.format(template=template, anp=anp),
value=mso.sent,
)]
else: else:
operation = [dict( ops.append(dict(op='add', path=anps_path + '/-', value=mso.sent))
op='add',
path='/templates/{template}/anps/-'.format(template=template),
value=mso.sent,
)]
mso.existing = mso.proposed mso.existing = mso.proposed
if not module.check_mode:
mso.request(path, method='PATCH', data=operation) if not module.check_mode:
mso.request(path, method='PATCH', data=ops)
mso.exit_json() mso.exit_json()