Forum Discussion

Michael_Jenkins's avatar
Michael_Jenkins
Icon for Cirrostratus rankCirrostratus
Jan 20, 2015

iControlREST - Update virtual access profile

I've got a bunch of virtuals set up that reference the same Access Profile. Instead of having to go through one by one and change the profile to a different one, I'd like to try to script it with iControlREST.

I'm working in powershell, and so far I've got this

 

$u = "https://example.com/mgmt/tm/ltm/virtual/MY_VIRTUAL";
$a = Invoke-RESTMethod -method GET -uri $u -credential $f5credentials;
 Now I have the virtual configuration

$u = $a.profilesReference.link -replace @("localhost", "example.com");
$b = Invoke-RESTMethod -method GET -uri "$u" -credential $f5credentials
$i = ($b.items | ?{$_.name -eq "MY_APM_PROFILE"});
 Now I have the profiles (all of them) and parsed out the one I'm trying to replace

$u = $i.selfLink -replace @("localhost", "example.com");
$c = Invoke-RESTMethod -method GET -uri $u -credential $f5credentials
 This was the configuration for the profile (MY_APM_PROFILE)

 

This is where I'm stuck. I can't figure out the right command to either replace the profile with a different one (e.g. MY_OTHER_APM_PROFILE) or remove the old and add the new (since you get an error trying to remove an APM profile when you have other profiles there)

Anyone done this? Any ideas on how?

2 Replies

  • Hello Michael, i'm not a powershell user, so limited help here. What i can tell you is that apm profile is attached as a ... profile so you will find it here : https://example.com/mgmt/tm/ltm/virtual/MY_VIRTUAL/profiles

     

    i think you will need :

     

    • to get the item list, because you will have multiple profiles (http, tcp, ssl ...)
    • remove the existing profile entry from the list
    • add your new profile to it
    • post back to the uri your updated profile list

    will try to play a little bit with ps to see how it works.

     

  • Found a way to do it. I take the profileReference object array (had to use the expandSubcollections=true query param on the GET) and get the kind and name and update the one I want to update, then use a PUT on the virtual, wrapping the array in {"profiles": ARRRAY_HERE}.

    Just thought I'd share. I may try to update this answer with the code itself.