Are you interested in our Early Access Program (EAP)? This program allows you to preview code, test in your lab and provide feedback prior to General Availability (GA) release of all Infoblox products. If so, please click the link here.

API Examples

Reply

WAPI: Create Network Container with Active Directory Site assigned

Techie
Posts: 7
392     0

Hello everybody,

 

I create a network container in Powershell with:

$domain = "gridmaster.example"
$network = "10.1.2.0/24"
$name = "Test Network"
$api_call = https://$domain/wapi/v2.10/networkcontainer
$body = '{"network":"' + $network + '","comment":"' +$name + '"}'
$api_results = Invoke-RestMethod -Uri $api_call -Method POST -ContentType
'application/json' -WebSession $authcookie -Body $body

But I would also like to assign an Active Directory Site, but I have no idea how to do that. Can somebody point me into the right direction? 

Re: WAPI: Create Network Container with Active Directory Site assigned

[ Edited ]
Techie
Posts: 7
393     0

I think I have to use the "move_subnets" function after creating the network container, but sadly my code does not work (HTTP 400):

$search_url = "https://$domain/wapi/v2.10/msserver:adsites:site?name=Test-AD"
$search_results = Invoke-RestMethod -Uri $search_url -Method GET  -WebSession $authcookie
$ref = $search_results._ref

$change_url = "https://$domain/wapi/v2.10/" + $ref +"?_function=move_subnets"
$body = '{"networkcontainer":["10.1.2.0/24"]}'
$change_results = Invoke-RestMethod -Uri $change_url -Method POST -ContentType 'application/json' -WebSession $authcookie -Body $body

 I think there is an error on how I parse the array with the "networkcontainer" IP. Can sombody give me a hint on how to correctly input the Network Container IP? 

Re: WAPI: Create Network Container with Active Directory Site assigned

Superuser
Posts: 82
393     0

Hello Julian,

 

Can you try this & see if it works ?

 

$body = '{"networkcontainer":[{"10.1.2.0/24"}]}'

 

Best regards,

Mohammed Alman

Re: WAPI: Create Network Container with Active Directory Site assigned

Techie
Posts: 7
393     0

Hi Mohammed,

 

sadly still HTTP 400. 

Re: WAPI: Create Network Container with Active Directory Site assigned

Moderator
Moderator
Posts: 191
393     0

it would be good to see what the error response is, with the 400 error.

Try replacing your last line, where the request is being made, with a try/catch section, to extract and display the error content returned with the http error response:

try {
$change_results = Invoke-RestMethod -Uri $change_url -Method POST -ContentType 'application/json' -WebSession $authcookie -Body $body
}
catch {
$result_stream = $change_results.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($result_stream)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd();
$responseError = $responseBody | ConvertFrom-Json
$responseError.text
}

 

 

Re: WAPI: Create Network Container with Active Directory Site assigned

[ Edited ]
Techie
Posts: 7
393     0

Hi, with

$body = '{"networkcontainer":["10.1.2.0/24"]}' 

the Error is: AdmConProtoError: required function parameter missing: networks

 


With 

$body = '{"networks":["10.1.2.0/24"]}'

the Error is: AdmConProtoError: Invalid reference: 10.1.2.0/24

 

10.1.2.0/24 is a container, but the function is requesting the parameter "networks" even though the WAPI documentation says it also accepts "networkcontainer" and in the GUI it is possible to assign an AD Site to a network container too. I am very puzzled. 

 

Showing results for 
Search instead for 
Did you mean: 

Recommended for You