Forum Discussion

Richard_Milner-'s avatar
Richard_Milner-
Icon for Nimbostratus rankNimbostratus
Aug 14, 2012

Creating Profiles / available methods list on iControl?

Hi Folks,

 

 

I suspect I've just missed a large chunk of the documentation, so any pointers would be handy...

 

 

 

I've already used iControl briefly in a couple of other tools, mainly to query the status of pool members and to adjust it as required, language of choice is Powershell at the moment.

 

 

 

I have a task to automate our provisioning of new customer configurations, we are in the middle of a greenfield build with a data centre move and I need to move around 150 virtual servers from a Zeus traffic manager to a lovely new F5 Big-Ip.

 

 

 

The manual process is something like:

 

 

 

- Create a OneConnect profile for the customer

 

- Create a ClientSSL profile for the customer (with the default certs is fine initially)

 

- Create a few HTTP profiles for the new customer (depending on the web site usage)

 

- Create various pools with associated members

 

- Create various virtual servers

 

- Ideally create an ASM profile (I suspect this isn't practical, not a huge deal)

 

- Assign some standard iRules I've written to various virtual servers as appropriate

 

 

 

I've found lots of examples on how to create pools and virtual servers, but no-one seems to talk about creating profiles... of any sort.

 

 

 

I've seen various strings being appended to Get-F5.iControl such as "LocalLBPool" or "LocalLBVirtualServerVirtualServerProfile", but I've not been able to find an exhaustive list of these, nor anything on how to actually use them!

 

 

 

Can anyone point me in the right direction r.e. the documentation, or even better post a usage example on how to create these profiles?

 

 

 

Many thanks for any help you can provide,

 

Richard.

 

  • Hi Richard, from the looks of it you are using the PowerShell library to make your iControl calls. The Get-F5.iControl CmdLet will return a instance of an iControl.Interfaces object. In that object, there are members for each of the iControl Interfaces. You can find a listing of the modules and interfaces in the iControl API reference in the iControl wiki

     

     

    https://devcentral.f5.com/wiki/iControl.APIReference.ashx

     

     

    The interfaces contained in the iControl.Interfaces object are named "ModuleInterface". So, if you are looking for profiles, you can browse through the wiki under LocalLB and see all the Profile* interfaces. To get a programmatic pointer to the OneConnect Profile Object, you will see the ProfileOneConnect interface in the LocalLB interface listing in the wiki. You can then call the (Get-F5.iControl).LocalLBProfileOneConnect.create() method to create a OneConnect Profile. Here's the link to the documentation for that method.

     

     

    https://devcentral.f5.com/wiki/iControl.LocalLB__ProfileOneConnect__create.ashx

     

     

    The API reference is modeled after the admin GUI so if you have administered a device, then it should be fairly easy for you to navigate to what you want.

     

     

    Hope this helps. Feel free to post if you have any more questions...

     

     

    -Joe

     

  • That's just what I was after Joe, thanks. In case it's of any use to anyone:

    
    -------------------------------------------------------------------------
    function Create-OneConnectProfile()
    
     Check whether a OneConnect Profile exists, create it if required
    -------------------------------------------------------------------------
    {
      Param([string] $profileName);
      $OneConnectArray = @()
      $OneConnectArray = (Get-F5.iControl).LocalLBProfileOneConnect.get_list()
      If ($OneConnectArray -contains $profileName) {
        Write-Host "OneConnect Profile: $profileName already exists" -ForegroundColor Cyan
      } Else {
        try {
      (Get-F5.iControl).LocalLBProfileOneConnect.Create( $profileName )
      Write-Host "Created OneConnect Profile: $profileName" -ForegroundColor Green
    } catch {
      Write-Host "There was an exception thrown creating OneConnect Profile: $profileName" -ForegroundColor Red
      $Error[0]
    }
      }
    }
    
     
  • I'll post the rest of the functions I end up creating in case they will be of use to anyone. This one was a little more interesting as I had to learn what a struct was. It may be worth beefing up the documentation around New-Object -TypeName iControl.LocalLBProfileString; to a non-programmer this stuff isn't very obvious, translating the one example I found from Java to Powershell wasn't simple for me.

    I'm also still not clear why I need to insert the LocalLBProfileString into an Array before I can use it?

    -------------------------------------------------------------------------
    function Create-ClientSSLProfile()
    
     Check whether a ClientSSL Profile exists, create it if required
    -------------------------------------------------------------------------
    {
      Param([string] $profileName);
      $ClientSSLArray = @()
      $ClientSSLArray = (Get-F5.iControl).LocalLBProfileClientSSL.get_list()
      If ($ClientSSLArray -contains $profileName) {
        Write-Host "ClientSSL Profile: $profileName already exists" -ForegroundColor Cyan
      } Else {
        try {
       Create LocalLBProfileString Structs for certificate and keys
      $defaultCert = New-Object -TypeName iControl.LocalLBProfileString;
      $defaultCert.value = "default";
              $defaultCert.default_flag = "true";
              $defaultCerts = (, $defaultCert);
              $defaultKey = New-Object -TypeName iControl.LocalLBProfileString;
              $defaultKey.value = "default";
              $defaultKey.default_flag = "true";
              $defaultKeys = (, $defaultKey);
       Create ClientSSL profile
      (Get-F5.iControl).LocalLBProfileClientSSL.create( $profileName, $defaultCerts, $defaultKeys )
      Write-Host "Created ClientSSL Profile: $profileName" -ForegroundColor Green
    } catch {
      Write-Host "There was an exception thrown creating ClientSSL Profile: $profileName" -ForegroundColor Red
      $Error[0]
    }
      }
    }
    
  • Anyone have any thoughts on why the following isn't working? No errors are thrown, yet it doesn't change the value for insert_xforwarded_for_header_mode.

     

     

      $ProfileMode = New-Object -TypeName iControl.LocalLBProfileProfileMode;
      $ProfileMode.value = "PROFILE_MODE_ENABLED";
      $ProfileMode.default_flag = "False";
      $ProfileModes = (, $ProfileMode);
    
    (Get-F5.iControl).LocalLBProfileHttp.set_insert_xforwarded_for_header_mode( "test_http_profile", $ProfileModes )
    (Get-F5.iControl).LocalLBProfileHttp.get_insert_xforwarded_for_header_mode( "test_http_profile" ) 

     

     

     

     

     

     

    EDIT: I fixed it myself, spend two hours playing with this and then find a solution 2 minutes after I post... typical.

     

     

     

    If I don't set default_flag to anything (true or false) then the code works. It's not obvious from the documentation but I'm guessing this is a system flag that I'm not meant to set myself, i.e. I can use it too tell whether the value is inherited but not to control inheritence??

     

     

     

    << A little confused

     

  • Create HTTP Profile function:

    
    -------------------------------------------------------------------------
    function Create-HTTPProfile()
    
     Check whether a HTTP Profile exists, create it if required and set its parent profile
     We also explicitly turn on the X-FORWARDED-FOR header
    -------------------------------------------------------------------------
    {
      Param([string] $profileName, [string] $parentProfile);
      $HTTPProfileArray = @()
      $HTTPProfileArray = (Get-F5.iControl).LocalLBProfileHttp.get_list()
      If ($HTTPProfileArray -contains $profileName) {
        Write-Host "HTTP Profile: $profileName already exists" -ForegroundColor Cyan
      } Else {
        try {
       Create LocalLBProfileMode Structs for the X-FORWARDED-FOR change
          $ProfileMode = New-Object -TypeName iControl.LocalLBProfileProfileMode;
          $ProfileMode.value = "PROFILE_MODE_ENABLED";
          $ProfileModes = (, $ProfileMode);
           Create profile
      (Get-F5.iControl).LocalLBProfileHttp.create( $profileName )
       Set parent profile
      (Get-F5.iControl).LocalLBProfileHttp.set_default_profile( $profileName, $parentProfile )
           Enable the X-FORWARDED-FOR header
      (Get-F5.iControl).LocalLBProfileHttp.set_insert_xforwarded_for_header_mode( $profileName, $ProfileModes )
      Write-Host "Created HTTP Profile: $profileName" -ForegroundColor Green
    } catch {
      Write-Host "There was an exception thrown creating HTTP Profile: $profileName" -ForegroundColor Red
      $Error[0]
    }
      }
    }
     
  • Hi Richard, Glad you got things going. Java and PowerShell are 2 different beasts but they both require you to allocate custom objects. Java uses "new" and PowerShell uses "New-Object". It's a little beyond the scope for us to give tutorials on all the languages we support but I will put it on my list to do a short "primer" for each language to give you the ins/outs of using the various elements.

     

     

    As for the arrays, that question gets asked alot. It started back when we developed the iControl interfaces for BIG-IP version 4.x. In there, we had methods that only took single scalar values. But, iControl is used by a lot of people in a lot of different ways. Imaging this method (just made up to illustrate the point)

     

     

    LocalLBPool.set_some_value(string pool_name, string value);

     

     

    This works great if you are trying to change the value for one pool. But what happens if you need to change that value for 1000 pools? What about 5000 pools? Let's say the latency in a single call is 200 ms to bring up/tear down the SSL connection. To execute 1000 calls, that would introduce a 200 s. (3.5 mins) overhead just to make those calls. For 5000 calls, that would be 16.5 minutes.

     

     

    So, we decided to make all of our methods "bulk" enabled so that users could combine multiple calls in a single one. This ends up being a little more difficult for the users that want to make a single change, but it eliminates the latency issue for large volume method calls.

     

     

    In the current release we have over 5000+ methods calls in iControl and for us to have 2 versions: one bulk, and one for scalars was deemed too much for us to support.

     

     

    Hope this explains it a bit.

     

     

    -Joe

     

  • Posted By Richard Milner-Watts on 08/15/2012 06:16 AM

     

    Anyone have any thoughts on why the following isn't working? No errors are thrown, yet it doesn't change the value for insert_xforwarded_for_header_mode.

     

     

      $ProfileMode = New-Object -TypeName iControl.LocalLBProfileProfileMode;
      $ProfileMode.value = "PROFILE_MODE_ENABLED";
      $ProfileMode.default_flag = "False";
      $ProfileModes = (, $ProfileMode);
    
    (Get-F5.iControl).LocalLBProfileHttp.set_insert_xforwarded_for_header_mode( "test_http_profile", $ProfileModes )
    (Get-F5.iControl).LocalLBProfileHttp.get_insert_xforwarded_for_header_mode( "test_http_profile" ) 

     

     

     

     

     

     

    EDIT: I fixed it myself, spend two hours playing with this and then find a solution 2 minutes after I post... typical.

     

     

     

    If I don't set default_flag to anything (true or false) then the code works. It's not obvious from the documentation but I'm guessing this is a system flag that I'm not meant to set myself, i.e. I can use it too tell whether the value is inherited but not to control inheritence??

     

     

     

    << A little confused

     

     

    Try setting the value of default_flag to the native true/false values in Powershell ($True, or $False). Or you could set it to 1 for true, or 0 for false. default_flag is of type "boolean" so I'm actually surprised it let you assign it a string.

     

     

     

  • Thanks for the responses, it's really nice to see active forum support for these things. Here's my Pool creation script in case it helps anyone out:

     

     

     

    -------------------------------------------------------------------------

     

    function Create-Pool()

     

     

    Check whether a Pool exists, create it if required.

     

    The following arguments are expected to be arrays: $MemberIPList $MemberPortList $HealthMonitorList

     

     

    -------------------------------------------------------------------------

     

    {

     

    Param([string] $poolName, [string] $LBMethod, [String[]] $MemberIPList, [String[]] $MemberPortList, [String[]] $HealthMonitorList )

     

    $PoolArray = @()

     

    $PoolArray = (Get-F5.iControl).LocalLBPool.get_list()

     

    If ($PoolArray -contains $poolName) {

     

    Write-Host "Pool: $poolName already exists" -ForegroundColor Cyan

     

    } Else {

     

    try {

     

    $IPPortDefList = New-Object -TypeName iControl.CommonIPPortDefinition[] $MemberIPList.Count;

     

    for($i=0; $i -lt $MemberIPList.Count; $i++) {

     

    $IPPortDefList[$i] = New-Object -TypeName iControl.CommonIPPortDefinition;

     

    $IPPortDefList[$i].address = $MemberIPList[$i];

     

    $IPPortDefList[$i].port = $MemberPortList[$i];

     

    }

     

    (Get-F5.iControl).LocalLBPool.create( (,$poolName), (,$LBMethod), (,$IPPortDefList) );

     

    Write-Host "Created Pool: $poolName" -ForegroundColor Green

     

     

    $monitor_association = New-Object -TypeName iControl.LocalLBPoolMonitorAssociation;

     

    $monitor_association.pool_name = $poolName;

     

    $monitor_association.monitor_rule = New-Object -TypeName iControl.LocalLBMonitorRule;

     

    $monitor_association.monitor_rule.type = "MONITOR_RULE_TYPE_AND_LIST";

     

    $monitor_association.monitor_rule.quorum = 1;

     

    $monitor_association.monitor_rule.monitor_templates = $HealthMonitorList;

     

    $monitor_associations = (, $monitor_association);

     

    (Get-F5.iControl).LocalLBPool.set_monitor_association( $monitor_associations );

     

    Write-Host "Assigned monitors to Pool `"$PoolName`"..." -ForegroundColor Green

     

    } Catch {

     

    Write-Host "There was an exception thrown creating Pool: $profileName" -ForegroundColor Red

     

    $Error[0]

     

    }

     

    }

     

    }