I have two dictionaries and I want to compare their values srvuuid in hosts dictionary and srvuuidorg in backup dictionary.
This is hosts:
hosts = {}
for d in data['servers']['server']:
srvhostname = d['hostname']
srvuuid = d['uuid']
hosts[srvhostname] = srvuuid
This is backup:
backup = {}
for u in backup_list['storages']['storage']:
srvuuidorg = u['origin']
backup_status = u['state']
backup[srvuuidorg] = backup_status
I extract machine hostname, then check if this hostname exist in hosts dictionary and get the output with srvuuid
hostname = gethostname()
print(hostname)
for srvhostname in hosts:
if srvhostname != hostname:
continue
if srvhostname == hostname:
print(srvhostname + " : " + hosts[srvhostname])
break
else:
print("There is no matching hostname or uuid.")
At the end I want to compare srvuuid and srvuuidorg. The code below is not working which means there is no output when executing:
for srvuuidorg in backup:
if srvuuidorg != srvuuid:
continue
if srvuuidorg == srvuuid:
print("Status for " + srvuuidorg + " is " + backup_status)
break
else:
print("No maching uuid found.")
How should I compare two values from this dictionaries or maybe I should change approach to the subject and use something different than comparing dictionaries?