cancel
Showing results for 
Search instead for 
Did you mean: 

Problem this snippet solves:

This is a Powershell iControl Sample illustrating how to use the module resource provisioning methods to manage the partitioning of memory, disk, and cpu across the modules licensed to run on the BIG-IP system.

This script will query the resource provision, set the values of LTM and GTM to custom with custom ratios, and reset them back to their default "nominal" values.

Code :

#----------------------------------------------------------------------------
# The contents of this file are subject to the "END USER LICENSE AGREEMENT FOR F5
# Software Development Kit for iControl"; you may not use this file except in
# compliance with the License. The License is included in the iControl
# Software Development Kit.
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is iControl Code and related documentation
# distributed by F5.
#
# The Initial Developer of the Original Code is F5 Networks,
# Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2010 F5 Networks,
# Inc. All Rights Reserved.  iControl (TM) is a registered trademark of F5 Networks, Inc.
#
# Alternatively, the contents of this file may be used under the terms
# of the GNU General Public License (the "GPL"), in which case the
# provisions of GPL are applicable instead of those above.  If you wish
# to allow use of your version of this file only under the terms of the
# GPL and not to allow others to use your version of this file under the
# License, indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by the GPL.
# If you do not delete the provisions above, a recipient may use your
# version of this file under either the License or the GPL.
#----------------------------------------------------------------------------
param (
  $bigip = $null,
  $uid = $null,
  $pwd = $null,
  $cmd = "list"
)

Set-PSDebug -strict;

#-------------------------------------------------------------------------
# function usage
#-------------------------------------------------------------------------
function usage()
{
  Write-Host "Usage: ManagementProvisioning.ps1 host uid pwd [list|custom|nominal]";
  exit;
}

#----------------------------------------------------------------------------
function Write-Entry()
#----------------------------------------------------------------------------
{
  param($col1, $col2, $col3, $col4, $col5);

  if ( $col1 -ne $null )
  {
    "{0,16} {1,9} {2,12} {3,12} {4,12}" -f $col1, $col2, $col3, $col4, $col5;
  }
  else
  {
    "---------------- --------- ------------ ------------ ------------";
  }
}

#----------------------------------------------------------------------------
function Get-Provisioning()
#----------------------------------------------------------------------------
{
  Write-Host "Retrieving the Provisioning List...";

  $module_list = (Get-F5.iControl).ManagementProvision.get_list();
  $levels = (Get-F5.iControl).ManagementProvision.get_level($module_list);
  $cpu_ratios = (Get-F5.iControl).ManagementProvision.get_custom_cpu_ratio($module_list);
  $disk_ratios = (Get-F5.iControl).ManagementProvision.get_custom_disk_ratio($module_list);
  $memory_ratios = (Get-F5.iControl).ManagementProvision.get_custom_memory_ratio($module_list);
  
  Write-Entry "Module Name" "Level" "CPU Ratio" "Disk Ratio" "Memory Ratio"
  Write-Entry
  for($i=0; $i -lt $module_list.Length; $i++)
  {
    $level = $levels[$i].ToString().Replace("PROVISION_LEVEL_", "");
    Write-Entry $module_list[$i] $level $cpu_ratios[$i] $disk_ratios[$i] $memory_ratios[$i]
  }
}

#----------------------------------------------------------------------------
function Set-Custom()
#----------------------------------------------------------------------------
{
  Write-Host "Setting Custom Provisioning levels";

  $modules = ("TMOS_MODULE_LTM", "TMOS_MODULE_GTM");
  $levels = ("PROVISION_LEVEL_CUSTOM", "PROVISION_LEVEL_CUSTOM");
  (Get-F5.iControl).ManagementProvision.set_level($modules, $levels);
  (Get-F5.iControl).ManagementProvision.set_custom_cpu_ratio($modules, (200, 50));
  (Get-F5.iControl).ManagementProvision.set_custom_disk_ratio($modules, (125, 125));
  (Get-F5.iControl).ManagementProvision.set_custom_cpu_ratio($modules, (175, 75));
}

#----------------------------------------------------------------------------
function Set-Nominal()
#----------------------------------------------------------------------------
{
  Write-Host "Resetting Provisioning Levels to NOMINAL...";
  
  $modules = ("TMOS_MODULE_LTM", "TMOS_MODULE_GTM");
  $levels = ("PROVISION_LEVEL_NOMINAL", "PROVISION_LEVEL_NOMINAL");
  $ratios = (0, 0);
  (Get-F5.iControl).ManagementProvision.set_level($modules, $levels);
  (Get-F5.iControl).ManagementProvision.set_custom_cpu_ratio($modules, $ratios);
  (Get-F5.iControl).ManagementProvision.set_custom_disk_ratio($modules, $ratios);
  (Get-F5.iControl).ManagementProvision.set_custom_cpu_ratio($modules, $ratios);
}


function Do-Initialize()
{
  if ( (Get-PSSnapin | Where-Object { $_.Name -eq "iControlSnapIn"}) -eq $null )
  {
    Add-PSSnapIn iControlSnapIn
  }
  $success = Initialize-F5.iControl -HostName $bigip -Username $uid -Password $pwd;
  
  return $success;
}

#-------------------------------------------------------------------------
# Main Application Logic
#-------------------------------------------------------------------------
if ( ($bigip -eq $null) -or ($uid -eq $null) -or ($pwd -eq $null) )
{
  usage;
}

if ( Do-Initialize )
{
  switch ($cmd) {
    "custom" {
      Set-Custom;
    }
    "nominal" {
      Set-Nominal
    }
    "list" {
      Get-Provisioning;
    }
    default {
      Get-Provisioning;
    }
  }
}
else
{
  Write-Error "ERROR: iControl subsystem not initialized"
}
Version history
Last update:
‎09-Mar-2015 11:34
Updated by:
Contributors