@classmethod<EOL><INDENT>def get_link(cls, source, target, topology=None):<DEDENT>
a = source<EOL>b = target<EOL>if not (valid_ipv4(a) and valid_ipv4(b)) and not (valid_ipv6(a) and valid_ipv6(b)) and not (valid_mac(a) and valid_mac(b)):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>a = cls._get_link_interface(a)<EOL>b = cls._get_link_interface(b)<EOL>not_found = []<EOL>if a is None:<EOL><INDENT>not_found.append(source)<EOL><DEDENT>if b is None:<EOL><INDENT>not_found.append(target)<EOL><DEDENT>if not_found:<EOL><INDENT>msg = '<STR_LIT>'.format('<STR_LIT:U+002CU+0020>'.join(not_found))<EOL>raise LinkDataNotFound(msg)<EOL><DEDENT>q = (Q(interface_a=a, interface_b=b) | Q(interface_a=b, interface_b=a))<EOL>if topology:<EOL><INDENT>q = q & Q(topology=topology)<EOL><DEDENT>link = Link.objects.filter(q).first()<EOL>if link is None:<EOL><INDENT>raise LinkNotFound('<STR_LIT>',<EOL>interface_a=a,<EOL>interface_b=b,<EOL>topology=topology)<EOL><DEDENT>return link<EOL>
Find link between source and target, (or vice versa, order is irrelevant).
:param source: ip or mac addresses
:param target: ip or mac addresses
:param topology: optional topology relation
:returns: Link object
:raises: LinkNotFound