Forum Discussion
iControl Rest Add Vlans to VCMP guest
Hello All,
I have been working automating some of our L2 and L3 tasks and running into a an issue where I am unable to add the created vlans to VCMP Guest. I am using powershell to do that. My understanding is that because the vlans properties in the VCMP guest is not a sub-collection in the guest object then we'll have to query the vlans into a variable, add the new vlans to that variable and add that back to the guest
Get vlans current vlans from Guest
$GuestVlans = Invoke-RestMethod "https://BigIPMgmtIP/mgmt/tm/vcmp/guest/GuestName" -Credential $creds -Method GET -ContentType application/json | select -ExpandProperty vlans``
Add new vlans to $GuestVlans
$GuestVlans += "Common/Newvlan1"
$GuestVlans += "Common/Newvlan2"
Invoke-RestMethod "https://BigIPMgmtIP/mgmt/tm/vcmp/guest/GuestName" -Credential $creds -Method PATCH -ContentType application/json -Body $GuestVlans
Add the vlans back seems not be working and I am getting the following error
Invoke-RestMethod : {"code":400,"message":"Found invalid JSON body in the request.","errorStack":[]}I am new to this and trying to learn as much as I can so any of your help will be very welcomed.
Thank you
3 Replies
- connors_233630Historic F5 Account
It looks like you are attempting to patch the contents of the vlans property, when the rest method expects a vcmp guest object. I think you need to stick $GuestVlans back into a guest-like object like (pseudocode)
, and that may do the trick.{"vlans":$GuestVlans}I'm also not certain about the way you are adding vlans, which looks like it will just result in one long string
, but I'm not familiar enough with these powershell commands to be certain."Common/OriginalVlanCommon/NewVlan1Common/NewVlan2"- The_Y
Cirrus
Good call. I 'll definitely give it a try. Thanks for the answer
- Greg_Jewett
Cirrus
All..
If you are dumbfounded with the error "", then you are not alone. I just spent the last couple of days yelling at my computer and the F5 API.
If you are using "Requests: HTTP for Humans" (https://2.python-requests.org/en/master/) module/library within Python to perform http requests to the API, and you are sending JSON objects as part of the data, then they must use the syntax:
NOT:
Example:
Perform a "Config-Sync" with the API, and using "data=postData" you will receive
{u'errorStack': [], u'message': u'Found invalid JSON body in the request.', u'code': 400, u'apiError': 1}
Changing that to "json=postData", removes the error as it properly encodes the json data into the request.
Hope this helps!
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com