def alias_process_diff(result, aliases, c_aliases): """ return the diff from expected aliases vs. current aliases :param aliases: list of expected aliases :type aliases: list :param c_aliases: list of current aliases :type c_aliases: list :return: indicate if diff or the same :rtype: bool :return: list of aliases with to be added members :rtype: list :return: list of aliases with to be removed members :rtype: list """ post_aliases = [] remove_aliases = [] common_aliases = [] for alias in aliases: found_in_c = False for c_alias in c_aliases: if alias["name"] == c_alias["alias-name"]: found_in_c = True added_members, removed_members, common_members = process_member_diff( result, alias["members"], c_alias["member-entry"]["alias-entry-name"]) if len(added_members) > 0: post_alias = {} post_alias["name"] = alias["name"] post_alias["members"] = added_members post_aliases.append(post_alias) if len(removed_members) > 0: remove_alias = {} remove_alias["name"] = alias["name"] remove_alias["members"] = removed_members remove_aliases.append(remove_alias) if len(common_members) > 0: common_alias = {} common_alias["name"] = alias["name"] common_alias["members"] = common_members common_aliases.append(common_alias) continue if not found_in_c: post_aliases.append(alias) return 0, post_aliases, remove_aliases, common_aliases
def cfg_process_diff(result, cfgs, c_cfgs): """ return the diff from expected cfgs vs. current cfgs :param cfgs: list of expected cfgs :type cfgs: list :param c_cfgs: list of current cfgs :type c_cfgs: list :return: indicate if diff or the same :rtype: bool :return: list of cfgs with to be added members :rtype: list :return: list of cfgs with to be removed members :rtype: list """ post_cfgs = [] remove_cfgs = [] common_cfgs = [] for cfg in cfgs: found_in_c = False for c_cfg in c_cfgs: if cfg["name"] == c_cfg["cfg-name"]: found_in_c = True added_members, removed_members, common_members = process_member_diff( result, cfg["members"], c_cfg["member-zone"]["zone-name"]) if len(added_members) > 0: post_cfg = {} post_cfg["name"] = cfg["name"] post_cfg["members"] = added_members post_cfgs.append(post_cfg) if len(removed_members) > 0: remove_cfg = {} remove_cfg["name"] = cfg["name"] remove_cfg["members"] = removed_members remove_cfgs.append(remove_cfg) if len(common_members) > 0: common_cfg = {} common_cfg["name"] = cfg["name"] common_cfg["members"] = common_members common_cfgs.append(common_cfg) continue if not found_in_c: post_cfgs.append(cfg) return 0, post_cfgs, remove_cfgs, common_cfgs
def zone_process_diff(result, zones, c_zones): """ return the diff from expected zones vs. current zones :param zones: list of expected zones :type zones: list :param c_zones: list of current zones :type c_zones: list :return: indicate if diff or the same :rtype: bool :return: list of zones with to be added members :rtype: list :return: list of zones with to be removed members :rtype: list """ post_zones = [] remove_zones = [] for zone in zones: found_in_c = False for c_zone in c_zones: if zone["name"] == c_zone["zone-name"]: found_in_c = True added_members, removed_members = process_member_diff( result, zone["members"], c_zone["member-entry"]["entry-name"]) if ( "principal_members" in zone and "principal-entry-name" in c_zone["member-entry"]): added_pmembers, removed_pmembers = process_member_diff( result, zone["principal_members"], c_zone["member-entry"] ["principal-entry-name"]) elif ( "principal_members" in zone and "principal-entry-name" not in c_zone["member-entry"]): added_pmembers, removed_pmembers = process_member_diff( result, zone["principal_members"], []) elif ( "principal_members" not in zone and "principal-entry-name" in c_zone["member-entry"]): added_pmembers, removed_pmembers = process_member_diff( result, [], c_zone["member-entry"] ["principal-entry-name"]) else: added_pmembers = [] removed_pmembers = [] if len(added_members) > 0 or len(added_pmembers): post_zone = {} post_zone["name"] = zone["name"] if added_members: post_zone["members"] = added_members if added_pmembers: post_zone["principal_members"] = added_pmembers post_zones.append(post_zone) if len(removed_members) > 0: remove_zone = {} remove_zone["name"] = zone["name"] if removed_members: remove_zone["members"] = removed_members if removed_pmembers: remove_zone["members"] = removed_pmembers remove_zones.append(remove_zone) continue if not found_in_c: post_zones.append(zone) return 0, post_zones, remove_zones