Skip to content

Commit

Permalink
Implement diff in ceph_orch_apply.py
Browse files Browse the repository at this point in the history
  • Loading branch information
foyerunix committed May 24, 2024
1 parent e71eba4 commit 3d37038
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions library/ceph_orch_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ def retrieve_current_spec(module: AnsibleModule, expected_spec: Dict) -> Dict:
""" retrieve current config of the service """
service: str = expected_spec["service_type"]
cmd = build_base_cmd_orch(module)
cmd.extend(['ls', service, '--format=yaml'])
cmd.extend(['ls', service])
if 'service_name' in expected_spec:
cmd.extend([expected_spec["service_name"]])
cmd.extend(['--format=yaml'])
out = module.run_command(cmd)
if isinstance(out, str):
# if there is no existing service, cephadm returns the string 'No services reported'
Expand Down Expand Up @@ -137,6 +140,14 @@ def run_module() -> None:
expected = parse_spec(module.params.get('spec'))
current_spec = retrieve_current_spec(module, expected)

# Remove dynamic attributes
if current_spec and 'status' in current_spec:
del current_spec["status"]
if current_spec and 'events' in current_spec:
del current_spec["events"]

diff = dict(before=yaml.safe_dump(current_spec), after=yaml.safe_dump(expected))

if not current_spec or current_spec != expected:
rc, cmd, out, err = apply_spec(module, spec)
changed = True
Expand All @@ -154,7 +165,8 @@ def run_module() -> None:
cmd=cmd,
err=err,
startd=startd,
changed=changed
changed=changed,
diff=diff
)


Expand Down

0 comments on commit 3d37038

Please sign in to comment.