def platform_detect(self):
     """
     :return platform detect string
     """
     self._platform_detect = linux_common.exec_command(
         '/usr/bin/platform-detect').strip()
     return self._platform_detect
 def platform_detect(self):
     """
     :return platform detect string
     """
     self._platform_detect = linux_common.exec_command(
         '/usr/bin/platform-detect').strip()
     return self._platform_detect
def get_ethtool_output(ifacename):
    """
    :return: ethtool output method used by cumulus provider to get ethtool output of a single interface.
    """
    cmd = '/sbin/ethtool -S %s' % (ifacename)
    try:
        ethtool_output = linux_common.exec_command(cmd)
    except linux_common.ExecCommandException:
        return u''
    return ethtool_output
Exemple #4
0
def get_ethtool_output(ifacename):
    """
    :return: ethtool output method used by cumulus provider to get ethtool output of a single interface.
    """
    cmd = '/sbin/ethtool -S %s' % (ifacename)
    try:
        ethtool_output = linux_common.exec_command(cmd)
    except linux_common.ExecCommandException:
        return u''
    return ethtool_output
    def mstpctl_output(self):
        """
        :returns: mstpctl showall output(raw)
        """

        result = ''
        try:
            result = linux_common.exec_command('/sbin/mstpctl showall')
        except (ValueError, IOError):
            pass
        return result
    def mstpctl_output(self):
        """
        :returns: mstpctl showall output(raw)
        """

        result = ''
        try:
            result = linux_common.exec_command('/sbin/mstpctl showall')
        except (ValueError, IOError):
            pass
        return result
 def parse_lsb_release_exec(self):
     """
     parse lsb release exec
     """
     lsb_output = common.exec_command('/usr/bin/lsb_release -a')
     for _line in lsb_output.split('\n'):
         if _line.startswith('Distributor'):
             self.os_name = _line.split()[2]
         elif _line.startswith('Description'):
             self.os_build = _line.split(':')[1].strip()
         elif _line.startswith('Release'):
             self.version = _line.split(':')[1].strip()
 def parse_lsb_release_exec(self):
     """
     parse lsb release exec
     """
     lsb_output = common.exec_command("/usr/bin/lsb_release -a")
     for _line in lsb_output.split("\n"):
         if _line.startswith("Distributor"):
             self.os_name = _line.split()[2]
         elif _line.startswith("Description"):
             self.os_build = _line.split(":")[1].strip()
         elif _line.startswith("Release"):
             self.version = _line.split(":")[1].strip()
def switching_asic_discovery():
    """ return class instance that matches switching asic
    used on the cumulus switch
    """
    try:
        lspci_output = linux_common.exec_command('lspci -nn')
    except linux_common.ExecCommandException:
        return None

    for _line in lspci_output.decode('utf-8').split('\n'):
        _line = _line.lower()
        if re.search(r'(ethernet|network)\s+controller.*broadcom', _line):
            return BroadcomAsic()
def _exec_lldp(ifacename=None):
    """
     exec lldp and return output from LLDP or None
     """
    lldp_output = None
    exec_str = '/usr/sbin/lldpctl -f xml'
    if ifacename:
        exec_str += ' %s' % (ifacename)
    try:
        lldp_cmd = common.exec_command(exec_str)
        lldp_output = ElementTree.fromstring(lldp_cmd)
    except common.ExecCommandException:
        pass
    return lldp_output
Exemple #11
0
def _exec_lldp(ifacename=None):
    """
     exec lldp and return output from LLDP or None
     """
    lldp_output = None
    exec_str = '/usr/sbin/lldpctl -f xml'
    if ifacename:
        exec_str += ' %s' % (ifacename)
    try:
        lldp_cmd = common.exec_command(exec_str)
        lldp_output = ElementTree.fromstring(lldp_cmd)
    except common.ExecCommandException:
        pass
    return lldp_output
def switching_asic_discovery():
    """ return class instance that matches switching asic
    used on the cumulus switch
    """
    try:
        lspci_output = linux_common.exec_command('lspci -nn')
    except linux_common.ExecCommandException:
        return None

    for _line in lspci_output.decode('utf-8').split('\n'):
        _line = _line.lower()
        if re.search(r'(ethernet|network)\s+controller.*broadcom',
                     _line):
            return BroadcomAsic()
def cacheinfo():
    """
    :return hash of of :class:`IpNeighbor` info by parsing ``ip neighbor show`` output.
    """
    # return empty ip neighbor dict
    ip_dict = {}
    for _iptype in ['4', '6']:
        try:
            _table = common.exec_command("/sbin/ip -%s neighbor show" % (_iptype))
            parse_info(table=_table,
                       iptype="ipv%s" % (_iptype),
                       ip_neigh_dict=ip_dict)
        except common.ExecCommandException:
            continue
    return ip_dict
def cacheinfo():
    """
    :return hash of of :class:`IpNeighbor` info by parsing ``ip neighbor show`` output.
    """
    # return empty ip neighbor dict
    ip_dict = {}
    for _iptype in ['4', '6']:
        try:
            _table = common.exec_command("/sbin/ip -%s neighbor show" %
                                         (_iptype))
            parse_info(table=_table,
                       iptype="ipv%s" % (_iptype),
                       ip_neigh_dict=ip_dict)
        except common.ExecCommandException:
            continue
    return ip_dict
Exemple #15
0
def cacheinfo():
    """
    Cacheinfo function for IP addresses. Collects all IP addresses \
    from the system and in the return hash assigns IP addresses \
    to particular interfaces
    :return: hash of ip addresses with iface names as keys.
    """
    cmd = '/sbin/ip -o addr show'
    try:
        ipaddr_output = common.exec_command(cmd)
    except:
        return {}
    # stringIO in python3 returns byte string, to be python2.x compatible
    # with common.exec_command decode byte string to regular string
    _fileio = io.StringIO(ipaddr_output)

    return parse_ip_cache(_fileio)
def check():
    """
    Linux Provider Check
    :return: name of OS found if check is true
    """

    # if netshowlib.linux.common module is not found..return None
    if not common_mod:
        return None
    try:
        uname_output = common_mod.exec_command('/bin/uname')
    except common_mod.ExecCommandException:
        return None
    os_name = uname_output.decode('utf-8').strip()
    os_name = os_name.lower()
    if os_name == 'linux':
        return os_name
    return None
Exemple #17
0
def test_exec_command():
    _output = common.exec_command('ls')
    if sys.version_info < (3, 0, 0):
        assert_equals(isinstance(_output, unicode), True)
    else:
        assert_equals(isinstance(_output, str), True)