def find_supervisor(fses): ''' find the admin who has the full control over all the flowspace elements in the fses. It does this selection by finding the admin whose flowspace is a superset of fses but is not a superviosr of another admin who also owns a flowspace that is a superset of fses. @param fses: the list of flowspaces we want to find an admin for @type fses: list of FlowSpace objects @return: the User object for the admin who has full control over fses ''' admins_list = UserProfile.objects.filter(is_net_admin=True).order_by('-id') intersected_admins = [] intersected_supervisors = [] for admin in admins_list: adminfs = AdminFlowSpace.objects.filter(user=admin.user) if multifs_is_subset_of(fses, adminfs): intersected_admins.append(admin) intersected_supervisors.append(admin.supervisor) selected_admin = None super_admin = None for admin in intersected_admins: if (admin.user not in intersected_supervisors): selected_admin = admin break if (admin.supervisor == admin.user): super_admin = admin if (selected_admin): return selected_admin.user elif (super_admin): return super_admin.user else: return None
def find_supervisor(fses): ''' find the admin who has the full control over all the flowspace elements in the fses. It does this selection by finding the admin whose flowspace is a superset of fses but is not a superviosr of another admin who also owns a flowspace that is a superset of fses. @param fses: the list of flowspaces we want to find an admin for @type fses: list of FlowSpace objects @return: the User object for the admin who has full control over fses ''' admins_list = UserProfile.objects.filter(is_net_admin=True).order_by('-id') intersected_admins = [] intersected_supervisors = [] for admin in admins_list: adminfs = AdminFlowSpace.objects.filter(user=admin.user) if multifs_is_subset_of(fses,adminfs): intersected_admins.append(admin) intersected_supervisors.append(admin.supervisor) selected_admin = None super_admin = None for admin in intersected_admins: if (admin.user not in intersected_supervisors): selected_admin = admin break if (admin.supervisor==admin.user): super_admin = admin if (selected_admin): return selected_admin.user elif (super_admin): return super_admin.user else: return None
def test_multifs_is_subset_of(self): f1 = FlowSpace(ip_src_s=2, ip_src_e=4) f2 = FlowSpace(ip_src_s=5, ip_src_e=9) f3 = FlowSpace(ip_src_s=1, ip_src_e=6) f4 = FlowSpace(ip_src_s=7, ip_src_e=11) self.assertTrue(multifs_is_subset_of([f1,f2],[f3,f4]))
def test_multifs_is_subset_of(self): f1 = FlowSpace(ip_src_s=2, ip_src_e=4) f2 = FlowSpace(ip_src_s=5, ip_src_e=9) f3 = FlowSpace(ip_src_s=1, ip_src_e=6) f4 = FlowSpace(ip_src_s=7, ip_src_e=11) self.assertTrue(multifs_is_subset_of([f1, f2], [f3, f4]))