Forum Discussion

dihris_116090's avatar
dihris_116090
Icon for Nimbostratus rankNimbostratus
Sep 23, 2014

Script to modify Virtual Servers default pool?

Hello,

 

Is there any way to get the default pool changed for a number of virtual servers?

 

I have the following scenario: We have virtual servers: A, B, C For each of the virtual servers there are two sets of pools created: A-1 and A-2, B-1 and B-2, C-1 and C-2 The default pool for each of the Virtual Servers is A-1, B-1, C-1

 

What would be the best way to be able re-assign the default pool from "$sVirtual-1" to "$sVirtual-2" and vice versa for each of the virtual servers? How to make sure that when the new default pools is re-assigned there are no client connection drop?

 

I'm very new to the iControl scripting so any example would be greatly appreciated. Also based on my search in the forums I think the best way to achieve this modification is via iControl script. If that's not the case I'm open to any suggestion that can help me realize this scenario.

 

11 Replies

  • Here's a simple iControlREST call to change pool assignment:

    curl -sk -u 'admin:admin' -H "Content-Type: application/json" -X PUT https://x.x.x.x/mgmt/tm/ltm/virtual/A-1 -d '{"pool":"sVirtual-2"}'
    
  • Hello Kevin,

     

    I was looking more of an automated script where I can change the default pools to all 3 servers at the same time. For example if A, B, C are the virtual servers and have assigned pools A-1, B-1, C-1 I'd like to be able to assign new default pools A-2, B-2, C-2 in automated way. Do you know how iCR handles connections that are already created to the existing pool before being changed?

     

    After further reading I see that setting the virtual default pool can be done with iRule as well: https://devcentral.f5.com/wiki/iControl.SetVirtualDefaultPool.ashx

     

    Which one is the better way to do it? With iControl or iRule, or maybe there some other way to do the same thing?

     

  • An iControl would create a provisioning change, whereas an iRule would generate a per-user-session change (and not be permanent). Which one you use depends on the use case. If, for example, you want to switch to a different pool based on the user, or something in the request, that would be an iRule. If you wanted to permanently change the pool assignment, that would be an iControl. As for automating the process, an iControl (or any other method) is only going to act on one VIP at a time, so the above iControlREST call, combined with two others in a script would produce an automated method for changing 3 pools on 3 VIPs. And how you do iControl also depends on a few factors. If you're good with Perl/Python/PowerShell/.Net/Java/etc., you can use the traditional iControl API. The iControlREST API allows you to expand that capability into basically any programming construct that supports REST (Bash, cURL, all of the above language variants, etc.).

     

    As for maintaining active sessions after a pool change, that's a tough one. I haven't investigates this, but I think that an active session (depending on persistence) would stick to its original node, but not certain.

     

  • Thanks for the explanation it is very useful. For the use case, yes I'm looking for change that is permanent so iControlREST should do the job. As for the active session I need to verify that too. Basically I would need the behavior should be like this: Once the default pool on the virtual server is changed all new sessions would go to the "new" default pool and all old sessions would remain and on the "old" default pool until they are being terminated from the client side.

     

  • Hey Guys, I need help here. We need to have a script to permantly change the default pool. So that we are able to switch the default pool for a number of Virtual Servers. Therefore I wrote a script to use the curl command which is: curl -sk -u 'admin:admin' -H "Content-Type: application/json" -X PUT -d '{"pool":"sVirtual-2"}'

     

    But for some reason I receive the following error message:

     

    {"code":400,"message":"0107028c:3: The source (::) and destination (123.123.123.123) addresses for virtual server (/Common/VS1) must be be the same type (IPv4 or IPv6).","errorStack":[]}

     

    So I checked the config of the virtual server and the Source IP is IPv4 "0.0.0.0/0"

     

    Any input here?

     

    Or is the curl command maybe wrong?

     

    • Dave_Gibbs_1948's avatar
      Dave_Gibbs_1948
      Icon for Nimbostratus rankNimbostratus

      In v12 we have had to change our PUT method to a PATCH which resolved this issue.

       

    • Philipp_Aeschli's avatar
      Philipp_Aeschli
      Icon for Nimbostratus rankNimbostratus

      Many Thanks to Dave Gibs, this is exaclty the solution to the error msg explained by adavidjan (in case you upgraded to v12)

       

      Best Philipp

       

    • adavidjan_27668's avatar
      adavidjan_27668
      Icon for Nimbostratus rankNimbostratus

      The PATCH method for updating the default pool of a Virtual works fine so far. Now we want to create a user which is allowed to change the default pool only for a couple of Virtual Servers. Therefore we created a role over REST API and granted Restmethod "PATCH" for those Virtual servers. But the user is not allowed to change the default pool and we receive a 401 message saying "Authorization failed" when trying to PATCH the default pool attribute. Using a admin user works fine.