def setTarget(self, netip): """ Set this route target netip in the form 10.0.0.0/24. """ netid, netmask = netip.split('/') if localIpCheck(self, netip) or netmask == '0': self._target = netip else: networks = self.device().getNetworkRoot() net = networks.createNet(netid, netmask) self.target.addRelation(net)
def setIpAddresses(self, ips): """ Set a list of ipaddresses in the form 1.1.1.1/24 on to this interface. If networks for the ips don't exist they will be created. """ if isinstance(ips, basestring): ips = [ips,] if self.clearIps(ips): return ipids = self.ipaddresses.objectIdsAll() localips = copy.copy(self._ipAddresses) for ip in ips: if not ip: continue if localIpCheck(self, ip) or localInterfaceCheck(self, self.id): if not ip in localips: self.addLocalIpAddress(ip) else: localips.remove(ip) else: # do this funky filtering because the id we have # is a primary id /zport/dmd/Networks... etc # and we are looking for just the IP part # we used the full id later when deleting the IPs rawip = ipFromIpMask(ipwrap(ip)) ipmatch = filter(lambda x: x.find(rawip) > -1, ipids) if not ipmatch: try: self.addIpAddress(ip) except IpAddressError: log.info("Ignoring invalid IP address {rawip}".format(rawip=rawip)) elif len(ipmatch) == 1: ipids.remove(ipmatch[0]) #delete ips that are no longer in use dirty = False for ip in ipids: ipobj = self.ipaddresses._getOb(ip) self.removeRelation('ipaddresses', ipobj) dirty = True notify(IndexingEvent(ipobj)) for ip in localips: dirty = True self._ipAddresses.remove(ip) # Invalidate the cache if we removed an ip. if dirty: self._invalidate_ipaddress_cache()
def setNextHopIp(self, nextHopIp): """ If the nexthop is a 127. or 0. address store locally else link to it in the network hierarchy """ if localIpCheck(self, nextHopIp) or not nextHopIp: self._nexthop = nextHopIp else: networks = self.device().getNetworkRoot() ip = networks.findIp(nextHopIp) if not ip: netmask = 24 int = self.interface() if int: intip = int.getIpAddressObj() if intip: netmask = intip.netmask ip = networks.createIp(nextHopIp, netmask) self.addRelation('nexthop', ip)
def setIpAddresses(self, ips): """ Set a list of ipaddresses in the form 1.1.1.1/24 on to this interface. If networks for the ips don't exist they will be created. """ if isinstance(ips, basestring): ips = [ ips, ] if self.clearIps(ips): return ipids = self.ipaddresses.objectIdsAll() localips = copy.copy(self._ipAddresses) for ip in ips: if localIpCheck(self, ip) or localInterfaceCheck(self, self.id): if not ip in localips: self.addLocalIpAddress(ip) else: localips.remove(ip) else: # do this funky filtering because the id we have # is a primary id /zport/dmd/Newtowrks... etc # and we are looking for just the IP part # we used the full id later when deleting the IPs rawip = ipFromIpMask(ip) ipmatch = filter(lambda x: x.find(rawip) > -1, ipids) if not ipmatch: self.addIpAddress(ip) elif len(ipmatch) == 1: ipids.remove(ipmatch[0]) #delete ips that are no longer in use for ip in ipids: ipobj = self.ipaddresses._getOb(ip) self.removeRelation('ipaddresses', ipobj) ipobj.index_object() for ip in localips: self._ipAddresses.remove(ip)
def setIpAddresses(self, ips): """ Set a list of ipaddresses in the form 1.1.1.1/24 on to this interface. If networks for the ips don't exist they will be created. """ if isinstance(ips, basestring): ips = [ips,] if self.clearIps(ips): return ipids = self.ipaddresses.objectIdsAll() localips = copy.copy(self._ipAddresses) for ip in ips: if localIpCheck(self, ip) or localInterfaceCheck(self, self.id): if not ip in localips: self.addLocalIpAddress(ip) else: localips.remove(ip) else: # do this funky filtering because the id we have # is a primary id /zport/dmd/Newtowrks... etc # and we are looking for just the IP part # we used the full id later when deleting the IPs rawip = ipFromIpMask(ip) ipmatch = filter(lambda x: x.find(rawip) > -1, ipids) if not ipmatch: self.addIpAddress(ip) elif len(ipmatch) == 1: ipids.remove(ipmatch[0]) #delete ips that are no longer in use for ip in ipids: ipobj = self.ipaddresses._getOb(ip) self.removeRelation('ipaddresses', ipobj) ipobj.index_object() for ip in localips: self._ipAddresses.remove(ip)