cleanup for core.misc and core.netns
This commit is contained in:
parent
05a5574155
commit
eb04e0a79f
7 changed files with 29 additions and 29 deletions
|
@ -155,7 +155,8 @@ class EventLoop(object):
|
||||||
schedule = True
|
schedule = True
|
||||||
break
|
break
|
||||||
event = heapq.heappop(self.queue)
|
event = heapq.heappop(self.queue)
|
||||||
assert event.time <= now
|
if event.time > now:
|
||||||
|
raise ValueError("invalid event time: %s > %s", event.time, now)
|
||||||
event.run()
|
event.run()
|
||||||
|
|
||||||
with self.lock:
|
with self.lock:
|
||||||
|
@ -170,11 +171,13 @@ class EventLoop(object):
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
with self.lock:
|
with self.lock:
|
||||||
assert self.running
|
if not self.running:
|
||||||
|
raise ValueError("scheduling event while not running")
|
||||||
if not self.queue:
|
if not self.queue:
|
||||||
return
|
return
|
||||||
delay = self.queue[0].time - time.time()
|
delay = self.queue[0].time - time.time()
|
||||||
assert self.timer is None
|
if self.timer:
|
||||||
|
raise ValueError("timer was already set")
|
||||||
self.timer = Timer(delay, self.__run_events)
|
self.timer = Timer(delay, self.__run_events)
|
||||||
self.timer.daemon = True
|
self.timer.daemon = True
|
||||||
self.timer.start()
|
self.timer.start()
|
||||||
|
|
|
@ -31,7 +31,7 @@ class MacAddress(object):
|
||||||
:return: string representation
|
:return: string representation
|
||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
return ":".join(map(lambda x: "%02x" % ord(x), self.addr))
|
return ":".join("%02x" % ord(x) for x in self.addr)
|
||||||
|
|
||||||
def to_link_local(self):
|
def to_link_local(self):
|
||||||
"""
|
"""
|
||||||
|
@ -61,7 +61,7 @@ class MacAddress(object):
|
||||||
:return: mac address class
|
:return: mac address class
|
||||||
:rtype: MacAddress
|
:rtype: MacAddress
|
||||||
"""
|
"""
|
||||||
addr = "".join(map(lambda x: chr(int(x, 16)), s.split(":")))
|
addr = "".join(chr(int(x, 16)) for x in s.split(":"))
|
||||||
return cls(addr)
|
return cls(addr)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -154,14 +154,14 @@ class IpAddress(object):
|
||||||
logger.exception("error during addition")
|
logger.exception("error during addition")
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
tmp = map(lambda x: ord(x), self.addr)
|
tmp = [ord(x) for x in self.addr]
|
||||||
for i in xrange(len(tmp) - 1, -1, -1):
|
for i in xrange(len(tmp) - 1, -1, -1):
|
||||||
x = tmp[i] + carry
|
x = tmp[i] + carry
|
||||||
tmp[i] = x & 0xff
|
tmp[i] = x & 0xff
|
||||||
carry = x >> 8
|
carry = x >> 8
|
||||||
if carry == 0:
|
if carry == 0:
|
||||||
break
|
break
|
||||||
addr = "".join(map(lambda x: chr(x), tmp))
|
addr = "".join(chr(x) for x in tmp)
|
||||||
return self.__class__(self.af, addr)
|
return self.__class__(self.af, addr)
|
||||||
|
|
||||||
def __sub__(self, other):
|
def __sub__(self, other):
|
||||||
|
@ -200,8 +200,8 @@ class IpAddress(object):
|
||||||
:return: integer value
|
:return: integer value
|
||||||
:rtype: int
|
:rtype: int
|
||||||
"""
|
"""
|
||||||
bin = socket.inet_pton(AF_INET, s)
|
value = socket.inet_pton(AF_INET, s)
|
||||||
return struct.unpack("!I", bin)[0]
|
return struct.unpack("!I", value)[0]
|
||||||
|
|
||||||
|
|
||||||
class IpPrefix(object):
|
class IpPrefix(object):
|
||||||
|
|
|
@ -293,10 +293,10 @@ def file_demunge(pathname, header):
|
||||||
start = None
|
start = None
|
||||||
end = None
|
end = None
|
||||||
|
|
||||||
for i in range(len(lines)):
|
for i, line in enumerate(lines):
|
||||||
if lines[i] == "# BEGIN %s\n" % header:
|
if line == "# BEGIN %s\n" % header:
|
||||||
start = i
|
start = i
|
||||||
elif lines[i] == "# END %s\n" % header:
|
elif line == "# END %s\n" % header:
|
||||||
end = i + 1
|
end = i + 1
|
||||||
|
|
||||||
if start is None or end is None:
|
if start is None or end is None:
|
||||||
|
|
|
@ -211,9 +211,7 @@ class PtpNet(LxBrNet):
|
||||||
if len(self._netif) != 2:
|
if len(self._netif) != 2:
|
||||||
return all_links
|
return all_links
|
||||||
|
|
||||||
if1, if2 = self._netif.items()
|
if1, if2 = self._netif.values()
|
||||||
if1 = if1[1]
|
|
||||||
if2 = if2[1]
|
|
||||||
|
|
||||||
unidirectional = 0
|
unidirectional = 0
|
||||||
if if1.getparams() != if2.getparams():
|
if if1.getparams() != if2.getparams():
|
||||||
|
@ -224,7 +222,7 @@ class PtpNet(LxBrNet):
|
||||||
interface1_ip6 = None
|
interface1_ip6 = None
|
||||||
interface1_ip6_mask = None
|
interface1_ip6_mask = None
|
||||||
for address in if1.addrlist:
|
for address in if1.addrlist:
|
||||||
ip, sep, mask = address.partition("/")
|
ip, _sep, mask = address.partition("/")
|
||||||
mask = int(mask)
|
mask = int(mask)
|
||||||
if ipaddress.is_ipv4_address(ip):
|
if ipaddress.is_ipv4_address(ip):
|
||||||
family = AF_INET
|
family = AF_INET
|
||||||
|
@ -242,7 +240,7 @@ class PtpNet(LxBrNet):
|
||||||
interface2_ip6 = None
|
interface2_ip6 = None
|
||||||
interface2_ip6_mask = None
|
interface2_ip6_mask = None
|
||||||
for address in if2.addrlist:
|
for address in if2.addrlist:
|
||||||
ip, sep, mask = address.partition("/")
|
ip, _sep, mask = address.partition("/")
|
||||||
mask = int(mask)
|
mask = int(mask)
|
||||||
if ipaddress.is_ipv4_address(ip):
|
if ipaddress.is_ipv4_address(ip):
|
||||||
family = AF_INET
|
family = AF_INET
|
||||||
|
|
|
@ -449,9 +449,7 @@ class OvsPtpNet(OvsNet):
|
||||||
if len(self._netif) != 2:
|
if len(self._netif) != 2:
|
||||||
return all_links
|
return all_links
|
||||||
|
|
||||||
if1, if2 = self._netif.items()
|
if1, if2 = self._netif.values()
|
||||||
if1 = if1[1]
|
|
||||||
if2 = if2[1]
|
|
||||||
|
|
||||||
unidirectional = 0
|
unidirectional = 0
|
||||||
if if1.getparams() != if2.getparams():
|
if if1.getparams() != if2.getparams():
|
||||||
|
@ -462,7 +460,7 @@ class OvsPtpNet(OvsNet):
|
||||||
interface1_ip6 = None
|
interface1_ip6 = None
|
||||||
interface1_ip6_mask = None
|
interface1_ip6_mask = None
|
||||||
for address in if1.addrlist:
|
for address in if1.addrlist:
|
||||||
ip, sep, mask = address.partition("/")
|
ip, _sep, mask = address.partition("/")
|
||||||
mask = int(mask)
|
mask = int(mask)
|
||||||
if ipaddress.is_ipv4_address(ip):
|
if ipaddress.is_ipv4_address(ip):
|
||||||
family = AF_INET
|
family = AF_INET
|
||||||
|
@ -480,7 +478,7 @@ class OvsPtpNet(OvsNet):
|
||||||
interface2_ip6 = None
|
interface2_ip6 = None
|
||||||
interface2_ip6_mask = None
|
interface2_ip6_mask = None
|
||||||
for address in if2.addrlist:
|
for address in if2.addrlist:
|
||||||
ip, sep, mask = address.partition("/")
|
ip, _sep, mask = address.partition("/")
|
||||||
mask = int(mask)
|
mask = int(mask)
|
||||||
if ipaddress.is_ipv4_address(ip):
|
if ipaddress.is_ipv4_address(ip):
|
||||||
family = AF_INET
|
family = AF_INET
|
||||||
|
|
|
@ -140,11 +140,9 @@ class EbtablesQueue(object):
|
||||||
while self.doupdateloop:
|
while self.doupdateloop:
|
||||||
with self.updatelock:
|
with self.updatelock:
|
||||||
for wlan in self.updates:
|
for wlan in self.updates:
|
||||||
"""
|
# Check if wlan is from a previously closed session. Because of the
|
||||||
Check if wlan is from a previously closed session. Because of the
|
# rate limiting scheme employed here, this may happen if a new session
|
||||||
rate limiting scheme employed here, this may happen if a new session
|
# is started soon after closing a previous session.
|
||||||
is started soon after closing a previous session.
|
|
||||||
"""
|
|
||||||
# TODO: if these are WlanNodes, this will never throw an exception
|
# TODO: if these are WlanNodes, this will never throw an exception
|
||||||
try:
|
try:
|
||||||
wlan.session
|
wlan.session
|
||||||
|
|
|
@ -364,7 +364,7 @@ class SimpleLxcNode(PyCoreNode):
|
||||||
if self.up:
|
if self.up:
|
||||||
self.check_cmd([constants.IP_BIN, "addr", "del", str(addr), "dev", self.ifname(ifindex)])
|
self.check_cmd([constants.IP_BIN, "addr", "del", str(addr), "dev", self.ifname(ifindex)])
|
||||||
|
|
||||||
def delalladdr(self, ifindex, address_types=valid_address_types):
|
def delalladdr(self, ifindex, address_types=None):
|
||||||
"""
|
"""
|
||||||
Delete all addresses from an interface.
|
Delete all addresses from an interface.
|
||||||
|
|
||||||
|
@ -373,6 +373,9 @@ class SimpleLxcNode(PyCoreNode):
|
||||||
:return: nothing
|
:return: nothing
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
:raises CoreCommandError: when a non-zero exit status occurs
|
||||||
"""
|
"""
|
||||||
|
if not address_types:
|
||||||
|
address_types = self.valid_address_types
|
||||||
|
|
||||||
interface_name = self.ifname(ifindex)
|
interface_name = self.ifname(ifindex)
|
||||||
addresses = self.client.getaddr(interface_name, rescan=True)
|
addresses = self.client.getaddr(interface_name, rescan=True)
|
||||||
|
|
||||||
|
@ -570,7 +573,7 @@ class LxcNode(SimpleLxcNode):
|
||||||
:rtype: file
|
:rtype: file
|
||||||
"""
|
"""
|
||||||
hostfilename = self.hostfilename(filename)
|
hostfilename = self.hostfilename(filename)
|
||||||
dirname, basename = os.path.split(hostfilename)
|
dirname, _basename = os.path.split(hostfilename)
|
||||||
if not os.path.isdir(dirname):
|
if not os.path.isdir(dirname):
|
||||||
os.makedirs(dirname, mode=0755)
|
os.makedirs(dirname, mode=0755)
|
||||||
return open(hostfilename, mode)
|
return open(hostfilename, mode)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue