def _interface_query(self, query): assert query netbox = Q(netbox__id=self.netbox.id) result = [] for ifc in manage.Interface.objects.values( 'id', 'ifname', 'ifdescr', 'iftype').filter(netbox & query): ifc = shadows.Interface(**ifc) ifc.netbox = self.netbox result.append(ifc) return result
def _interface_query(self, query): assert query netbox = Q(netbox__id=self.netbox.id) try: ifc = manage.Interface.objects.values( 'id', 'ifname', 'ifdescr', 'iftype').get(netbox & query) except manage.Interface.DoesNotExist: return None ifc = shadows.Interface(**ifc) ifc.netbox = self.netbox return ifc
def _interface_query(self, query): assert query netbox = Q(netbox__id=self.netbox.id) try: ifc = manage.Interface.objects.values('id', 'ifname', 'ifdescr', 'iftype').get(netbox & query) except manage.Interface.DoesNotExist: return None except manage.Interface.MultipleObjectsReturned: self._logger.info( "found multiple matching interfaces on remote, " "cannot decide: %s", netbox & query) return None ifc = shadows.Interface(**ifc) ifc.netbox = self.netbox return ifc
def _get_parent_interface(ifc): # NAV doesn't yet store data from ifStackTable in the database, so we can # only guess at the parent interface based on naming conventions (used by # Cisco). match = SUBIF_PATTERN.match(ifc.ifname) if match: basename = match.group('basename') try: parent = manage.Interface.objects.values( 'id', 'ifname', 'ifdescr', 'iftype').get(netbox__id=ifc.netbox.id, ifname=basename) except manage.Interface.DoesNotExist: pass else: parent = shadows.Interface(**parent) parent.netbox = ifc.netbox return parent return ifc