API & Integration

Reply

Regular expression search on network prefixes isn't working as expected

aziule
Techie
Posts: 8
366     0

Hi,

 

Using regular expressions to find networks based on their prefix is not working as expected. If we want to find all networks that are between /27 and /30, one option for a regular expression would be

 

 

^.*/(27|28|29|30)$

 

Note: there is only one 10.10.10.64/27 network in the view I use for my tests.

 

 

Problem 1

 

Using the abovementioned regex won't work:

 

GET /wapi/v2.6/network?network_view=test&network~=^.*/(27|28|29|30)$

{
    "Error": "AdmConProtoError: Bad value for network: '^.*/(27|28|29|30)$'",
    "code": "Client.Ibap.Proto",
    "text": "Bad value for network: '^.*/(27|28|29|30)$'"
}

 

Problem 2

 

 

Removing the "/" from the regex and running again will give an empty response:

 

GET /wapi/v2.6/network?network_view=test&network~=^.*(27|28|29|30)$

[]

It looks like the prefix isn't included when doing a regex search.

 

 

 

Problem 3

 

 

When searching with a single prefix, the behaviour changes. As we can see below, looking for a single /27 network will return the expected result:

GET: /wapi/v2.6/network?network_view=test&network~=/27

[
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTAuMTAuMTAuNjQvMjcvNzY2Ng:10.10.10.64/27/test",
        "network": "10.10.10.64/27",
        "network_view": "test"
    }
]

If we want to look for multiple prefixes, using a leading "/", then the regular expression will not work:

GET /wapi/v2.6/network?network_view=test&network~=/(27|28)

{
    "Error": "AdmConProtoError: Bad value for network: '/(27|28)'",
    "code": "Client.Ibap.Proto",
    "text": "Bad value for network: '/(27|28)'"
}

 

It doesn't work if I use an overly simplified version of the regex (it will not only look for prefixes but if any network contains 27 or 28, even in its IP):

GET /wapi/v2.6/network?network_view=test&network~=(27|28)

[]

 

I also came across something funny: when using leading and trailing "/", the regex is ignored:

GET /wapi/v2.6/network?network_view=test&network~=/some r4nd0m text here! [] () -=/

[
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTAuMTAuMTAuNjQvMjcvNzY2Ng:10.10.10.64/27/test",
        "network": "10.10.10.64/27",
        "network_view": "test"
    }
]

 

Deductions

* Even though "network" returns the IP + prefix (x.x.x.x/x), the regular expression search is only done on the IP part

* Regular expressions on prefixes will "work" only if we use them like "/x" => we can consider we cannot use regular expressions for prefixes

* Regular expressions are broken if we start them with a leading "/"

* Regular expressions are broken if we use both leading and trailing "/"

 

Unless I am writing bad regex, it would be great to see this fixed so that we can ensure a common behaviour between the various resources of the API. Otherwise it is very confusing and we need to find unconvenient workarounds.

 

Moreover, if the Infoblox team could add it to the doc it would be perfect - the doc contains lots of information and that's great, but it lacks some specificities.

 

Cheers,

 

Will

Re: Regular expression search on network prefixes isn't working as expected

Authority
Posts: 16
366     0

Hello Will,

 

I was runing a quick test and I believe you are right about the last deduction. I saw similar behavior across different WAPI versions too.

 

When I tried adding the leading and trailing " / ", I see that the character behaves like a delimiter. I reached this theory because I saw a similar behavior when I tried using other characters like " # " in place of " / ".

 

The expression within the delimiter seems to be ignored. I also do not see why the use of parentheses " ( ) " fail here. 

 

Regarding the first three deductions mentioned, I would like to propose a slight modification to get the desired output.

 

To get the Networks for the desired list of prefixes, I was successful with the below expression:

 

 

GET  /wapi/v2.7/network?network_view=default&network~=/{27,28,29,30}

[
{
"_ref": "network/ZG5zLm5ldHdvcmskMjcuMC4wLjAvMjcvMA:27.0.0.0/27/default",
"network": "7.0.0.0/27",
"network_view": "default"
}
][
{
"_ref": "network/ZG5zLm5ldHdvcmskMjguMC4wLjAvMjgvMA:28.0.0.0/28/default",
"network": "8.0.0.0/28",
"network_view": "default"
}
][
{
"_ref": "network/ZG5zLm5ldHdvcmskMjkuMC4wLjAvMjkvMA:29.0.0.0/29/default",
"network": "9.0.0.0/29",
"network_view": "default"
}
][
{
"_ref": "network/ZG5zLm5ldHdvcmskMzAuMC4wLjAvMzAvMA:30.0.0.0/30/default",
"network": "3.0.0.0/30",
"network_view": "default"
}
]

 

From this we can confirm that regular expressions do work with a leading " / ".

 

 

I also do get the expected output if I remove the " / " from the regex, like so:

 

 

GET  /wapi/v2.7/network?network_view=default&network~={27,28,29,30}

[
{
"_ref": "network/ZG5zLm5ldHdvcmskMjcuMC4wLjAvMjcvMA:27.0.0.0/27/default",
"network": "7.0.0.0/27",
"network_view": "default"
}
][
{
"_ref": "network/ZG5zLm5ldHdvcmskMjguMC4wLjAvMjgvMA:28.0.0.0/28/default",
"network": "8.0.0.0/28",
"network_view": "default"
}
][
{
"_ref": "network/ZG5zLm5ldHdvcmskMjkuMC4wLjAvMjkvMA:29.0.0.0/29/default",
"network": "9.0.0.0/29",
"network_view": "default"
},
{
"_ref": "network/ZG5zLm5ldHdvcmskMTAuMjkuMC4wLzIzLzA:10.29.0.0/23/default",
"network": "10.29.0.0/23",
"network_view": "default"
}
][
{
"_ref": "network/ZG5zLm5ldHdvcmskMTAuODguMTMwLjAvMjQvMA:10.88.130.0/24/default",
"network": "10.88.130.0/24",
"network_view": "default"
},
{
"_ref": "network/ZG5zLm5ldHdvcmskMzAuMC4wLjAvMzAvMA:30.0.0.0/30/default",
"network": "3.0.0.0/30",
"network_view": "default"
}
]

 

 

 

So this confirms that the scope of the regular expression includes the prefix as well as the IP portion.

 

I hope you find this helpful.

 

Best regards,

Nithin

Highlighted

Re: Regular expression search on network prefixes isn't working as expected

aziule
Techie
Posts: 8
366     0

Hi nedward,

 

I tested your solution against v2.6 and v2.9 and it does not work:

 

GET /wapi/v2.6/network?network_view=default&network~=/{27,28,29,30}

{
    "Error": "AdmConProtoError: Bad value for network: '/{27,28,29,30}'",
    "code": "Client.Ibap.Proto",
    "text": "Bad value for network: '/{27,28,29,30}'"
}

v2.9 is funny as it returns the trace (which indicates there's a bug in their API):

GET {{domain}}/wapi/v2.9/network?network_view=default&network~=/{27,28,29,30}

{
    "Error": "AdmConProtoError: Bad value for network: '/{27,28,29,30}'",
    "code": "Client.Ibap.Proto",
    "text": "Bad value for network: '/{27,28,29,30}'",
    "trace": "  File \"ibapapachemod.py\", line 449, in handlerequest\n  File \"/infoblox/common/lib/python/infoblox/one/admin_conn/wapibase.py\", line 1429, in execute\n  File \"/infoblox/common/lib/python/infoblox/one/admin_conn/wapibase.py\", line 1384, in _exec_handler\n  File \"/infoblox/common/lib/python/infoblox/one/admin_conn/wapihandler.py\", line 713, in execute\n  File \"/infoblox/common/lib/python/infoblox/one/wapibaseobj.py\", line 1248, in read\n  File \"/infoblox/common/lib/python/infoblox/one/wapibaseobj.py\", line 317, in make_searchfields_dict\n  File \"/infoblox/common/lib/python/infoblox/one/wapibaseobj.py\", line 298, in add_search_info\n  File \"/infoblox/common/lib/python/infoblox/dns/wapi/dhcp.py\", line 1031, in w2i\n"
}

Moreover, your 2nd example, without the leading slash, returns 

"10.88.130.0/24",

=> Your regex does not look for prefixes but for anything containing  27, 28, 29 or 30.

 

Can we have an answer from the Infoblox team please? Can we expect this feature to be handled in a future patch?

 

Thanks!

Re: Regular expression search on network prefixes isn't working as expected

Adviser
Posts: 61
367     0

Hi Will, please open a support case with Infoblox Support on this issue.  The community site is a great place to discuss examples and capabilities, and exchange knowledge, but is not intended to replace the Infoblox support team for product issues.

 

Best,

Matt

Showing results for 
Search instead for 
Do you mean 

Recommended for You