napalm-automation / napalm-junos

Apache License 2.0
22 stars 42 forks source link

implement find operation in cli #216

Closed ckishimo closed 6 years ago

ckishimo commented 6 years ago

Just for completeness, implementation of the find operation, same as match, last, except....using the find operation in junos cli was not giving the right output. With the following configuration:

carles@vmx> show configuration protocols bgp 
local-as 1111;
group internal {
    type internal;
    local-address 10.99.1.2;
    neighbor 10.10.10.10 {
        description routerA;
        cluster 2.2.2.2;
    }
    neighbor 20.20.20.20 {
        description routerB;
    }
}

the output should be:

carles@vmx> show configuration protocols bgp | find cluster 
        cluster 2.2.2.2;
    }
    neighbor 20.20.20.20 {
        description routerB;
    }
}

and not:

res = dev.cli(["show configuration protocols bgp | find cluster"])
{
    "show configuration protocols bgp | find cluster": "\nlocal-as 1111;\ngroup internal {\n    type internal;\n    local-address 10.99.1.2;\n    neighbor 10.10.10.10 {\n        description routerA;\n        cluster 2.2.2.2;\n    }\n    neighbor 20.20.20.20 {\n        description routerB;\n    }\n}\n"
}

with the new operation the output is:

{
    "show configuration protocols bgp | find cluster": "cluster 2.2.2.2;\n    }\n    neighbor 20.20.20.20 {\n        description routerB;\n    }\n}\n"
}

If the pattern does not exist we return the same junos message:

{
    "show configuration protocols bgp | find napalm": "\nPattern not found"
}

and in junos cli:

carles@vmx> show configuration protocols bgp | find napalm     

Pattern not found
carles@vmx> 
coveralls commented 6 years ago

Coverage Status

Coverage decreased (-0.5%) to 77.756% when pulling 1425d3bfc3bf5c0df4488e2065ebac387dd28b00 on ckishimo:devel-hop into ab33fbc685ab89750abf541ffd89575fd6b5b3ff on napalm-automation:develop.