def scan(self, **kwargs): """Implemnets the scan method in BasePlugin class. .. note:: In this module, mac addesses were retrieved by ssh. """ try: user = self.credential['username'] pwd = self.credential['password'] except KeyError: logging.error("Cannot find username and password in credential") return None cmd = ("BRIDGES=$(ovs-vsctl show |grep Bridge |cut -f 2 -d '\"');" "for br in $BRIDGES; do" "PORTS=$(ovs-ofctl show $br |grep addr |cut -f 1 -d ':' " "|egrep -v 'eth|wlan|LOCAL'|awk -F '(' '{print $1}');" "for port in $PORTS; do" "RESULT=$(ovs-appctl fdb/show $br |" "awk '$1 == '$port' {print $1" "$2" "$3}');" "echo '$RESULT'" "done;" "done;") output = None try: output = utils.ssh_remote_execute(self.host, user, pwd, cmd) except Exception as error: logging.exception(error) return None logging.debug("[scan][output] output is %s", output) if not output: return None fields_arr = ['port', 'vlan', 'mac'] result = [] for line in output: if not line or line == '\n': continue values_arr = line.split() temp = {} for field, value in zip(fields_arr, values_arr): temp[field] = value result.append(temp.copy()) return result
def scan(self, **kwargs): """Implemnets the scan method in BasePlugin class. .. note:: In this module, mac addesses were retrieved by ssh. """ try: user = self.credential['username'] pwd = self.credential['password'] except KeyError: logging.error("Cannot find username and password in credential") return None cmd = ("BRIDGES=$(ovs-vsctl show |grep Bridge |cut -f 2 -d '\"');" "for br in $BRIDGES; do" "PORTS=$(ovs-ofctl show $br |grep addr |cut -f 1 -d ':' " "|egrep -v 'eth|wlan|LOCAL'|awk -F '(' '{print $1}');" "for port in $PORTS; do" "RESULT=$(ovs-appctl fdb/show $br |" "awk '$1 == '$port' {print $1" "$2" "$3}');" "echo '$RESULT'" "done;" "done;") output = None try: output = utils.ssh_remote_execute(self.host, user, pwd, cmd) except Exception as error: logging.exception(error) return None logging.debug("[scan][output] output is %s", output) if not output: return None fields_arr = ['port', 'vlan', 'mac'] result = [] for line in output: if not line or line == '\n': continue values_arr = line.split() temp = {} for field, value in zip(fields_arr, values_arr): temp[field] = value result.append(temp.copy()) return result
def is_this_vendor(self, sys_info, host=None, credential=None, **kwargs): """Determine if the hostname is accociated witH this vendor. :param host: swtich's IP address :param credential: credential to access switch """ result = sys_info if host and credential: if utils.is_valid_ssh_credential(credential): user = credential['username'] pwd = credential['password'] else: msg = ("[OVSwitch]The format of credential %r is not for SSH " "or incorrect Keywords! " % credential) logging.info(msg) return False cmd = "ovs-vsctl -V" result = None try: result = utils.ssh_remote_execute(host, user, pwd, cmd) logging.debug('%s result for %s is %s', cmd, host, result) if not result: return False except Exception as exc: logging.error("No vendor or connection failed to run %s", cmd) logging.exception(exc) return False if isinstance(result, str): result = [result] for line in result: if not line: continue if re.search(r"\b" + re.escape(self.__name) + r"\b", line): return True return False
def is_this_vendor(self, sys_info, host=None, credential=None, **kwargs): """Determine if the hostname is accociated witH this vendor. :param host: swtich's IP address :param credential: credential to access switch """ result = sys_info if host and credential: if utils.is_valid_ssh_credential(credential): user = credential['username'] pwd = credential['password'] else: msg = ("[OVSwitch]The format of credential %r is not for SSH " "or incorrect Keywords! " % credential) logging.info(msg) return False cmd = "ovs-vsctl -V" result = None try: result = utils.ssh_remote_execute(host, user, pwd, cmd) logging.debug('%s result for %s is %s', cmd, host, result) if not result: return False except Exception as exc: logging.error("No vendor or connection failed to run %s", cmd) logging.exception(exc) return False if isinstance(result, str): result = [result] for line in result: if not line: continue if re.search(r"\b" + re.escape(self.__name) + r"\b", line): return True return False
def is_this_vendor(self, host, credential): """Determine if the hostname is accociated witH this vendor. :param host: swtich's IP address :param credential: credential to access switch """ if "username" in credential and "password" in credential: user = credential['username'] pwd = credential['password'] else: logging.error('either username or password key is not in %s', credential) return False cmd = "ovs-vsctl -V" result = None try: result = utils.ssh_remote_execute(host, user, pwd, cmd) logging.debug('%s result for %s is %s', cmd, host, result) if not result: return False except Exception as exc: logging.error("vendor incorrect or connection failed to run %s", cmd) logging.exception(exc) return False if isinstance(result, str): result = [result] for line in result: if not line: continue if re.search(r"\b" + re.escape(self.__name) + r"\b", line): return True return False
def is_this_vendor(self, host, credential): """ Determine if the hostname is accociated witH this vendor. param str host : swtich's IP address param dict credential : credential to access switch """ if "username" in credential and "password" in credential: user = credential['username'] pwd = credential['password'] else: logging.error('either username or password key is not in %s', credential) return False cmd = "ovs-vsctl -V" result = None try: result = utils.ssh_remote_execute(host, user, pwd, cmd) logging.debug('%s result for %s is %s', cmd, host, result) if not result: return False except Exception as exc: logging.error("vendor incorrect or connection failed to run %s", cmd) logging.exception(exc) return False if isinstance(result, str): result = [result] for line in result: if not line: continue if re.search(r"\b" + re.escape(self.__name) + r"\b", line): return True return False