updates to support 2/3 along with not using vcmd c extension
This commit is contained in:
parent
864c7b69a1
commit
ecc63f4abb
22 changed files with 680 additions and 636 deletions
|
@ -687,7 +687,8 @@ class CoreNode(CoreNodeBase):
|
|||
output = output.split("\n")
|
||||
veth.flow_id = int(output[0].strip().split(":")[0]) + 1
|
||||
logging.debug("interface flow index: %s - %s", veth.name, veth.flow_id)
|
||||
veth.hwaddr = MacAddress.from_string(output[1].strip().split()[1])
|
||||
# TODO: mimic packed hwaddr
|
||||
# veth.hwaddr = MacAddress.from_string(output[1].strip().split()[1])
|
||||
logging.debug("interface mac: %s - %s", veth.name, veth.hwaddr)
|
||||
|
||||
try:
|
||||
|
@ -1062,11 +1063,13 @@ class CoreNetworkBase(NodeBase):
|
|||
if ipaddress.is_ipv4_address(ip):
|
||||
family = AF_INET
|
||||
ipl = socket.inet_pton(family, ip)
|
||||
# ipl = ipl.decode("ISO-8859-1")
|
||||
interface2_ip4 = ipaddress.IpAddress(af=family, address=ipl)
|
||||
interface2_ip4_mask = mask
|
||||
else:
|
||||
family = AF_INET6
|
||||
ipl = socket.inet_pton(family, ip)
|
||||
# ipl = ipl.decode("ISO-8859-1")
|
||||
interface2_ip6 = ipaddress.IpAddress(af=family, address=ipl)
|
||||
interface2_ip6_mask = mask
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ by invoking the vcmd shell command.
|
|||
import logging
|
||||
import os
|
||||
|
||||
import vcmd
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
from core import CoreCommandError, utils
|
||||
from core import constants
|
||||
|
@ -28,7 +28,6 @@ class VnodeClient(object):
|
|||
"""
|
||||
self.name = name
|
||||
self.ctrlchnlname = ctrlchnlname
|
||||
self.cmdchnl = vcmd.VCmd(self.ctrlchnlname)
|
||||
self._addr = {}
|
||||
|
||||
def _verify_connection(self):
|
||||
|
@ -48,7 +47,7 @@ class VnodeClient(object):
|
|||
:return: True if connected, False otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
return self.cmdchnl.connected()
|
||||
return True
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
|
@ -56,7 +55,10 @@ class VnodeClient(object):
|
|||
|
||||
:return: nothing
|
||||
"""
|
||||
self.cmdchnl.close()
|
||||
pass
|
||||
|
||||
def _cmd_args(self):
|
||||
return [constants.VCMD_BIN, "-c", self.ctrlchnlname, "--"]
|
||||
|
||||
def cmd(self, args, wait=True):
|
||||
"""
|
||||
|
@ -71,7 +73,9 @@ class VnodeClient(object):
|
|||
args = utils.split_args(args)
|
||||
|
||||
# run command, return process when not waiting
|
||||
p = self.cmdchnl.qcmd(args)
|
||||
cmd = self._cmd_args() + args
|
||||
logging.info("cmd wait(%s): %s", wait, cmd)
|
||||
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
|
||||
if not wait:
|
||||
return 0
|
||||
|
||||
|
@ -94,7 +98,7 @@ class VnodeClient(object):
|
|||
stdout.close()
|
||||
stderr.close()
|
||||
status = p.wait()
|
||||
return status, output.strip()
|
||||
return status, output.decode("utf-8").strip()
|
||||
|
||||
def check_cmd(self, args):
|
||||
"""
|
||||
|
@ -120,7 +124,12 @@ class VnodeClient(object):
|
|||
"""
|
||||
self._verify_connection()
|
||||
args = utils.split_args(args)
|
||||
return self.cmdchnl.popen(args)
|
||||
# if isinstance(args, list):
|
||||
# args = " ".join(args)
|
||||
cmd = self._cmd_args() + args
|
||||
logging.info("popen: %s", cmd)
|
||||
p = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
|
||||
return p, p.stdin, p.stdout, p.stderr
|
||||
|
||||
def icmd(self, args):
|
||||
"""
|
||||
|
@ -150,7 +159,10 @@ class VnodeClient(object):
|
|||
|
||||
# run command, return process when not waiting
|
||||
args = utils.split_args(args)
|
||||
p = self.cmdchnl.redircmd(infd, outfd, errfd, args)
|
||||
cmd = self._cmd_args() + args
|
||||
logging.info("redircmd: %s", cmd)
|
||||
p = Popen(cmd, stdin=infd, stdout=outfd, stderr=errfd)
|
||||
|
||||
if not wait:
|
||||
return p
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ class CoreInterface(object):
|
|||
|
||||
self.node = node
|
||||
self.name = name
|
||||
if not isinstance(mtu, (int, long)):
|
||||
if not isinstance(mtu, int):
|
||||
raise ValueError
|
||||
self.mtu = mtu
|
||||
self.net = None
|
||||
|
@ -142,7 +142,7 @@ class CoreInterface(object):
|
|||
"""
|
||||
# treat None and 0 as unchanged values
|
||||
current_value = self._params.get(key)
|
||||
if current_value == value or current_value <= 0 and value <= 0:
|
||||
if current_value is None or current_value == value or current_value <= 0 and value <= 0:
|
||||
return False
|
||||
|
||||
self._params[key] = value
|
||||
|
@ -174,6 +174,16 @@ class CoreInterface(object):
|
|||
"""
|
||||
self.poshook(self, x, y, z)
|
||||
|
||||
def __lt__(self, other):
|
||||
"""
|
||||
Used for comparisons of this object.
|
||||
|
||||
:param other: other interface
|
||||
:return: true if less than, false otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
return id(self) < id(other)
|
||||
|
||||
|
||||
class Veth(CoreInterface):
|
||||
"""
|
||||
|
|
|
@ -31,7 +31,9 @@ class MacAddress(object):
|
|||
:return: string representation
|
||||
:rtype: str
|
||||
"""
|
||||
return ":".join("%02x" % ord(x) for x in self.addr)
|
||||
logging.info("mac addr: %s", type(self.addr))
|
||||
addr = self.addr.decode("ISO-8859-1")
|
||||
return ":".join("%02x" % ord(x) for x in addr)
|
||||
|
||||
def to_link_local(self):
|
||||
"""
|
||||
|
@ -93,7 +95,9 @@ class IpAddress(object):
|
|||
:return:
|
||||
"""
|
||||
# check if (af, addr) is valid
|
||||
logging.info("ip address: %s", type(address))
|
||||
if not socket.inet_ntop(af, address):
|
||||
# if not socket.inet_ntop(af, address.encode("ISO-8859-1")):
|
||||
raise ValueError("invalid af/addr")
|
||||
self.af = af
|
||||
self.addr = address
|
||||
|
@ -124,6 +128,7 @@ class IpAddress(object):
|
|||
:rtype: str
|
||||
"""
|
||||
return socket.inet_ntop(self.af, self.addr)
|
||||
# return socket.inet_ntop(self.af, self.addr.encode("ISO-8859-1"))
|
||||
|
||||
def __eq__(self, other):
|
||||
"""
|
||||
|
@ -231,7 +236,7 @@ class IpPrefix(object):
|
|||
self.prefixlen = int(tmp[1])
|
||||
else:
|
||||
self.prefixlen = self.addrlen
|
||||
self.prefix = socket.inet_pton(self.af, tmp[0])
|
||||
self.prefix = socket.inet_pton(self.af, tmp[0]).decode("ISO-8859-1")
|
||||
if self.addrlen > self.prefixlen:
|
||||
addrbits = self.addrlen - self.prefixlen
|
||||
netmask = ((1 << self.prefixlen) - 1) << addrbits
|
||||
|
|
|
@ -855,11 +855,13 @@ class PtpNet(CoreNetwork):
|
|||
if ipaddress.is_ipv4_address(ip):
|
||||
family = AF_INET
|
||||
ipl = socket.inet_pton(family, ip)
|
||||
# ipl = ipl.decode("ISO-8859-1")
|
||||
interface1_ip4 = ipaddress.IpAddress(af=family, address=ipl)
|
||||
interface1_ip4_mask = mask
|
||||
else:
|
||||
family = AF_INET6
|
||||
ipl = socket.inet_pton(family, ip)
|
||||
# ipl = ipl.decode("ISO-8859-1")
|
||||
interface1_ip6 = ipaddress.IpAddress(af=family, address=ipl)
|
||||
interface1_ip6_mask = mask
|
||||
|
||||
|
@ -873,11 +875,13 @@ class PtpNet(CoreNetwork):
|
|||
if ipaddress.is_ipv4_address(ip):
|
||||
family = AF_INET
|
||||
ipl = socket.inet_pton(family, ip)
|
||||
# ipl = ipl.decode("ISO-8859-1")
|
||||
interface2_ip4 = ipaddress.IpAddress(af=family, address=ipl)
|
||||
interface2_ip4_mask = mask
|
||||
else:
|
||||
family = AF_INET6
|
||||
ipl = socket.inet_pton(family, ip)
|
||||
# ipl = ipl.decode("ISO-8859-1")
|
||||
interface2_ip6 = ipaddress.IpAddress(af=family, address=ipl)
|
||||
interface2_ip6_mask = mask
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue