Exemple #1
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
Exemple #2
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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #9
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
Exemple #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