HuaweiSwitch / CloudEngine-Ansible

Ansible modules to automate HUAWEI CloudEngine switches
GNU General Public License v3.0
144 stars 51 forks source link

你们的正则如何匹配交换机的主机名? #79

Closed Orobas-D closed 4 years ago

Orobas-D commented 4 years ago

CloudEngine-Ansible-master\plugins\terminal\ce.py

class TerminalModule(TerminalBase):

    terminal_stdout_re = [
        re.compile(r'[\r\n]?<.+>(?:\s*)$'), #请问\r\n怎么匹配的?
        re.compile(r'[\r\n]?\[.+\](?:\s*)$'),
    ]

    terminal_stderr_re = [
        re.compile(r"% ?Error: "),
        re.compile(r"^% \w+", re.M),
        re.compile(r"% ?Bad secret"),
        re.compile(r"invalid input", re.I),
        re.compile(r"(?:incomplete|ambiguous) command", re.I),
        re.compile(r"connection timed out", re.I),
        re.compile(r"[^\r\n]+ not found", re.I),
        re.compile(r"'[^']' +returned error code: ?\d+"),
        re.compile(r"syntax error"),
        re.compile(r"unknown command"),
        re.compile(r"Error\[\d+\]: ", re.I),
        re.compile(r"Error:", re.I)
    ]

    def on_open_shell(self):
        try:
            self._exec_cli_command('screen-length 0 temporary')
        except AnsibleConnectionFailure:
            raise AnsibleConnectionFailure('unable to set terminal parameters')

我理解的正确表达式不应该是这样的吗?

r'[\r][\n]?<.+>(?:\s*)$'

交换机返回的应该是 ··· b'\r\n\<Huawei>' ··· 难道不是吗?

Orobas-D commented 4 years ago

重新看了一下,没问题,我自己傻逼了

yanzhangi commented 4 years ago

@Orobas-D 我的ansible ce模块维护人员,后面有问题随时沟通