Reply

How to get all subnets within an IPv4 network container ?

New Member
Posts: 2
15356     0

Hi,

 

How to get all subnets within an IPv4 network container, with REST API ?

 

Regards,

Aurelien

Re: How to get all subnets within an IPv4 network container ?

Adviser
Posts: 181
15356     0

Hi Aurelien,

 

You can filter the networks by their container like below:

API Call: 
https://<grid_ip>/wapi/v2.10/network?network_container=10.0.0.0/16&_return_fields%2B=network_container

Sample Output:
[
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTAuMC4xMC4wLzI0LzA:10.0.10.0/24/Company%201",
        "comment": "Lab",
        "network": "10.0.10.0/24",
        "network_container": "10.0.0.0/16",
        "network_view": "Company 1"
    },
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTAuMC4xLjAvMjQvMA:10.0.1.0/24/Company%201",
        "network": "10.0.1.0/24",
        "network_container": "10.0.0.0/16",
        "network_view": "Company 1"
    }
]

Hope this is helpful,

Krishna

 

Re: How to get all subnets within an IPv4 network container ?

[ Edited ]
New Member
Posts: 1
15356     0

How to Get A Docker Container IP Address - Explained with Examples and run an application in a loosely isolated environment called a container.

mypennmedicine

Re: How to get all subnets within an IPv4 network container ?

New Member
Posts: 2
15356     0

Thanks Krishna.

Is there a way to get comment field of an IPv4 network container ?

Re: How to get all subnets within an IPv4 network container ?

[ Edited ]
Adviser
Posts: 181
15356     0

Hi,

 

You can add it to the list of _return_fields like below:

For network:
https://<grid_ip>/wapi/v2.10/network?network_container=10.0.0.0/16&_return_fields%2B=network_container,comment

For network container:
https://<grid_ip>/wapi/v2.10/networkcontainer?_return_fields%2B=comment

 Regards,

Krishna Vasudevan

Re: How to get all subnets within an IPv4 network container ?

Authority
Posts: 33
15356     0

Are you able to return the network container's comments within the output for all networks?

 

https://<grid>/wapi/v2.10/network?network_container=10.0.0.0/8&_return_fields%2B=network_container

plus something...

And get output like this?

[{
"_ref": "network/ZG5z...jgvMA:10.10.10.0/24/default",

"comment": "Example network comment",
"network": "10.10.10.0/24",
"network_container": "10.0.0.0/8",

"network_container:comment": "Example container comment",
"network_view": "default"
}]

Re: How to get all subnets within an IPv4 network container ?

Adviser
Posts: 181
15356     0

Hi,

 

I'm not clear regarding your question.

 

This is the output I get:

[
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTAuMC4xMC4wLzI0LzA:10.0.10.0/24/Company%201",
        "comment": "Lab",
        "network": "10.0.10.0/24",
        "network_container": "10.0.0.0/16",
        "network_view": "Company 1"
    },
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTAuMC4xLjAvMjQvMA:10.0.1.0/24/Company%201",
        "network": "10.0.1.0/24",
        "network_container": "10.0.0.0/16",
        "network_view": "Company 1"
    }
]

The comment field is returned by default if there is a comment added to the network/container.

 

Regards,

Krishna Vasudevan

Re: How to get all subnets within an IPv4 network container ?

Techie
Posts: 9
15356     0

How to query to multiple network container and create a next_available_network using powershell?

 

please help out this much helpful for me

Re: How to get all subnets within an IPv4 network container ?

Adviser
Posts: 181
15356     0

Hi,

 

Here you go:

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Basic YWRtaW46aW5mb2Jsb3g=")
$headers.Add("Content-Type", "application/json")
$body = "{`n    `"network`":`"func:nextavailablenetwork:192.168.0.0/16,27`"`n}"
$response = Invoke-RestMethod 'https://grid-master.lab.com/wapi/v2.12/network' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

You can modify the fields highlighted in bold. 192.168.0.0/16 is the network container. 27 is the CIDR of the new network you want to create.

 

Regards,

Krishna

Re: How to get all subnets within an IPv4 network container ?

Techie
Posts: 9
15356     0

how to check network_container exists, if not create a network container and create network subnet into it using powershell with REST API?

Re: How to get all subnets within an IPv4 network container ?

Moderator
Moderator
Posts: 315
15356     0

You have to develop the logic in your code, and then make separate API calls for each step.

 

Search for the network container, and count the number of results.  If the number of results is zero, then the container does not exist and should be created.

 

10.0.0.0/8 exists in this grid:

 

curl -k1 -u admin:infoblox -X POST 'https://192.168.1.2/wapi/v2.10/request' -H "Content-Type: application/json" -d \
'[
  {
    "method":"GET",
    "object":"networkcontainer",
    "data": {
                "network": "10.0.0.0/8"
        }
  }
]'

returns:

[
    [
        {
            "_ref": "networkcontainer/ZG5zLm5ldHdvcmtfY29udGFpbmVyJDEwLjAuMC4wLzgvMA:10.0.0.0/8/default", 
            "network": "10.0.0.0/8", 
            "network_view": "default"
        }
    ]
]%                

But 10.0.0.0/12 does not:

 

curl -k1 -u admin:infoblox -X POST 'https://192.168.1.2/wapi/v2.10/request' -H "Content-Type: application/json" -d \
'[
  {
    "method":"GET",
    "object":"networkcontainer",
    "data": {
                "network": "10.0.0.0/12"
        }
  }
]'

returns an empty set:

[
    []
]

Subnets can be created directly, or by using a next_available_network function within the network container.

 

Create the next available network inside a network container:  (using the 10.0.0.0/8 from the first example)

 

curl -k1 -u admin:infoblox -X POST 'https://192.168.1.2/wapi/v2.10/request' -H "Content-Type: application/json" -d \
'[
  {
    "method":"POST",
        "object": "network",
        "enable_substitution": true,
        "data": {
      "network": "func:nextavailablenetwork:networkcontainer/ZG5zLm5ldHdvcmtfY29udGFpbmVyJDEwLjAuMC4wLzgvMA:10.0.0.0/8/default,24",
      "comment": "Created by Next Available Network"
        }
  }
]'

returns a reference to the network that was created:
[
    "network/ZG5zLm5ldHdvcmskMTAuMC4yLjAvMjQvMA:10.0.2.0/24/default"
]

Re: How to get all subnets within an IPv4 network container ?

Techie
Posts: 9
15357     0

can you please make the above code into powershell ?

 

please help me to solve this

Re: How to get all subnets within an IPv4 network container ?

Techie
Posts: 9
15357     0

I have used this below code.. it showing an error like 400 bad request

 

$pwd = ConvertTo-SecureString "password" -AsPlainText -Force
$creds = New-Object Management.Automation.PSCredential ("admin", $pwd) -ErrorAction stop

$network_data = @{
network="func:nextavailablenetwork:$network_container,default,$cidr";
comment="PS-TESTAPI";
network_view="default"
}
$body = $network_data | ConvertTo-Json 

$new_network_discovery_url = "https://xx.xx.xxx.xx/wapi/v2.9.7/network"
Invoke-RestMethod -Uri $new_network_discovery_url -Method POST -Body $body -Credential $creds   -ContentType 'application/json'  -UseBasicParsing 

 

Below is the error i am getting 

Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At C:\Users\Desktop\Untitled4.ps1:52 char:1
+ Invoke-RestMethod -Uri $new_network_discovery_url -Method POST -Body  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Please help me to solve this issue.. 

 

Re: How to get all subnets within an IPv4 network container ?

Adviser
Posts: 181
15357     0

Hi,

 

The below powershell code works for me:

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Basic auth")
$headers.Add("Content-Type", "application/json")

$body = "{
`n	`"network`":`"func:nextavailablenetwork:10.0.0.0/8,default,24`",
`n	`"network_view`":`"default`",
`n	`"comment`":`"Test`"
`n}"

$response = Invoke-RestMethod 'https://grid-master/wapi/v2.7/network' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

Regards,

Krishna

Re: How to get all subnets within an IPv4 network container ?

Techie
Posts: 9
15357     0

how to check if particular network container is already utilizing 100% using REST API in powershell?

Re: How to get all subnets within an IPv4 network container ?

Authority
Posts: 33
15357     0

The comment is for the network object and I also want the comment for the network container object. 

Showing results for 
Search instead for 
Did you mean: 

Recommended for You