trigger icon indicating copy to clipboard operation
trigger copied to clipboard

No host menu presented with gong when using IP addresses for hostnames in netdevices

Open mhite opened this issue 11 years ago • 2 comments

It would appear that the menu feature of gong does not work when IP addresses are used in netdevices rather than hostnames. For example:

netdevices.csv:

10.1.1.1,juniper,switch
10.1.1.2,juniper,switch
10.1.1.3,juniper,switch
10.1.1.4,a10
10.1.1.5,juniper,firewall

If you launch "gong 10", you should expect to see a menu of all hosts in netdevices which pattern 10 in their hostname pattern. However, it would appear this functionality does not work and instead it picks a single host to connect to.

mhite avatar Jul 31 '14 20:07 mhite

The bug actually exists in trigger.netdevices.NetDevices.find, which returns a result even if it's only a partial match. The issue looks to be with this line, which says, "Hey, I found a 10 followed by a ., this is a match!"

In [1]: from trigger.netdevices import NetDevices, device_match

In [2]: nd = NetDevices()

In [3]: device_match('10')
Out[3]: <NetDevice: 10.254.254.3>

In [4]: nd.find('10')
Out[4]: <NetDevice: 10.254.254.3>

This is probably because it's assuming an FQDN, not an IP address.

There's an argument to be made that all devices should have FQDNs. :)

However, a possible workaround is to first check if it's an IP address. If it's an IP address, only match if it's an exact match, otherwise fallback to trigger.netdevices.NetDevices.search, which appropriately returns a list of possible matches:

In [5]: nd.search('10')
Out[5]: [<NetDevice: 10.254.254.3>, <NetDevice: 10.254.254.2>]

I'd be interested in @jathanism's thoughts on that approach or if he thinks there's a better one.

supertylerc avatar Apr 18 '16 16:04 supertylerc

@supertylerc: Yeah so we've talked about making these "lookup" methods configurable. There are a couple of places where these types of device naming pattern assumptions are made. This is just one of them.

In this case, being able to configure the pattern or condition for returning an object from NetDevices.find() might be simplest. Like a global setting that contains a regex value that's used in a helper function?

Perhaps the default for this pattern be something that supports both IP addresses and standard hostname patterns as you suggested.

jathanism avatar Apr 18 '16 16:04 jathanism