示例#1
0
文件: hp.py 项目: jerryz1982/compass
    def is_this_vendor(self, host, credential):
        """ Determine if the hostname is accociated witH this vendor.
            This example will use snmp sysDescr OID ,regex to extract
            the vendor's name ,and then compare with self.name variable.

            param str host : switch's IP address
            param dict credential : credential to access switch
        """

        if "Version" not in credential or "Community" not in credential:
            # The format of credential is incompatible with this vendor
            err_msg = "[Hp]Missing keyword 'Version' or 'Community' in %r"
            logging.error(err_msg, credential)
            return False

        sys_info = utils.snmp_get(host, credential, "sysDescr.0")
        if not sys_info:
            logging.info("Dismatch vendor information")
            return False

        sys_info = sys_info.lower()
        for name in self.names:
            if re.search(r"\b" + re.escape(name) + r"\b", sys_info):
                return True

        return False
示例#2
0
文件: mac.py 项目: jerryz1982/compass
    def _get_vlan_id(self, port):
        """Get vlan Id"""

        oid = '.'.join(('Q-BRIDGE-MIB::dot1qPvid', port))
        vlan_id = utils.snmp_get(self.host, self.credential, oid).strip()

        return vlan_id
示例#3
0
    def _get_vlan_id(self, port):
        """Get vlan Id"""

        oid = '.'.join(('Q-BRIDGE-MIB::dot1qPvid', port))
        vlan_id = utils.snmp_get(self.host, self.credential, oid).strip()

        return vlan_id
示例#4
0
    def is_this_vendor(self, host, credential):
        """
        Determine if the hostname is accociated witH this vendor.
        This example will use snmp sysDescr OID ,regex to extract
        the vendor's name ,and then compare with self.name variable.

        :param host: swtich's IP address
        :param credential: credential to access switch
        """
        if not utils.valid_ip_format(host):
            #invalid ip address
            return False

        if "Version" not in credential or "Community" not in credential:
            # The format of credential is incompatible with this vendor
            error_msg = "[huawei]Missing 'Version' or 'Community' in %r"
            logging.error(error_msg, credential)
            return False
        sys_info = utils.snmp_get(host, credential, "sysDescr.0")

        if not sys_info:
            return False

        if re.search(r"\b" + re.escape(self.__name) + r"\b", sys_info.lower()):
            return True

        return False
示例#5
0
    def is_this_vendor(self, host, credential):
        """
        Determine if the hostname is accociated witH this vendor.
        This example will use snmp sysDescr OID ,regex to extract
        the vendor's name ,and then compare with self.name variable.

        :param host: swtich's IP address
        :param credential: credential to access switch
        """
        if not utils.valid_ip_format(host):
            #invalid ip address
            return False

        if "Version" not in credential or "Community" not in credential:
            # The format of credential is incompatible with this vendor
            error_msg = "[huawei]Missing 'Version' or 'Community' in %r"
            logging.error(error_msg, credential)
            return False
        sys_info = utils.snmp_get(host, credential, "sysDescr.0")

        if not sys_info:
            return False

        if re.search(r"\b" + re.escape(self.__name) + r"\b", sys_info.lower()):
            return True

        return False
示例#6
0
    def is_this_vendor(self, host, credential):
        """ Determine if the hostname is accociated witH this vendor.
            This example will use snmp sysDescr OID ,regex to extract
            the vendor's name ,and then compare with self.name variable.

            param str host : switch's IP address
            param dict credential : credential to access switch
        """

        if "Version" not in credential or "Community" not in credential:
            # The format of credential is incompatible with this vendor
            err_msg = "[Hp]Missing keyword 'Version' or 'Community' in %r"
            logging.error(err_msg, credential)
            return False

        sys_info = utils.snmp_get(host, credential, "sysDescr.0")
        if not sys_info:
            logging.info("Dismatch vendor information")
            return False

        sys_info = sys_info.lower()
        for name in self.names:
            if re.search(r"\b" + re.escape(name) + r"\b", sys_info):
                return True

        return False
示例#7
0
    def _get_port(self, if_index):
        """Get port number by using snmpget and OID 'IfName'
           :param int if_index:the index of 'IfName'
        """

        if_name = '.'.join(('ifName', if_index))
        result = utils.snmp_get(self.host, self.credential, if_name)
        """result variable will be  like: GigabitEthernet0/0/23"""
        port = result.split("/")[2]
        return port
示例#8
0
    def _get_port(self, if_index):
        """Get port number by using snmpget and OID 'IfName'

        :param int if_index:the index of 'IfName'
        """

        if_name = '.'.join(('ifName', if_index))
        result = utils.snmp_get(self.host, self.credential, if_name)
        """result variable will be  like: GigabitEthernet0/0/23"""
        port = result.split("/")[2]
        return port
示例#9
0
文件: mac.py 项目: jerryz1982/compass
    def _get_port(self, if_index):
        """Get port number"""

        if_name = '.'.join(('ifName', if_index))
        port = utils.snmp_get(self.host, self.credential, if_name).strip()
        return port
示例#10
0
    def _get_port(self, if_index):
        """Get port number"""

        if_name = '.'.join(('ifName', if_index))
        port = utils.snmp_get(self.host, self.credential, if_name).strip()
        return port