此脚本用于控制F5设备,可对pool成员进行操作及成员状态,该脚本及源自于f5官网

使用格式:

1.查看pool成员状态

/usr/bin/perl /scripts/togglepoolmember.pl  F5设备IP 443(port) 用户 password pool名称

2.pool成员对内对外操作

/usr/bin/perl /scripts/togglepoolmember.pl  F5设备IP 443(port) 用户 password pool名称 pool成员IP:port

#!/usr/bin/perl
#----------------------------------------------------------------------------
# The contents of this file are subject to the iControl Public License
# Version 9.2 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.f5.com/.
#
# 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-2005
# 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.
#---------------------------------------------------------------------------- #use SOAP::Lite + trace => qw(method debug);
use SOAP::Lite; #----------------------------------------------------------------------------
# Validate Arguments
#----------------------------------------------------------------------------
my $sHost = $ARGV[0];
my $sPort = $ARGV[1];
my $sUID = $ARGV[2];
my $sPWD = $ARGV[3];
my $sPool = $ARGV[4];
my $sNodeAddr = $ARGV[5];
my $sProtocol = "https"; sub usage()
{
die ("Usage: togglePoolMember.pl host port uid pwd [pool [addr:port]]\n");
} if ( ($sHost eq "") or ($sPort eq "") or ($sUID eq "") or ($sPWD eq "") )
{
usage();
} if ( ("80" eq $sPort) or ("8080" eq $sPort) )
{
$sProtocol = "http";
} #----------------------------------------------------------------------------
# Transport Information
#----------------------------------------------------------------------------
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
return "$sUID" => "$sPWD";
} $Pool = SOAP::Lite
-> uri('urn:iControl:LocalLB/Pool')
-> readable(1)
-> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
$PoolMember = SOAP::Lite
-> uri('urn:iControl:LocalLB/PoolMember')
-> readable(1)
-> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi"); #----------------------------------------------------------------------------
# Attempt to add auth headers to avoid dual-round trip
#----------------------------------------------------------------------------
eval { $Pool->transport->http_request->header
(
'Authorization' =>
'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
); };
eval { $Pool->transport->http_request->header
(
'Authorization' =>
'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
); }; #----------------------------------------------------------------------------
# support for custom enum types
#----------------------------------------------------------------------------
sub SOAP::Deserializer::typecast
{
my ($self, $value, $name, $attrs, $children, $type) = @_;
my $retval = undef;
if ( "{urn:iControl}Common.EnabledState" == $type )
{
$retval = $value;
}
return $retval;
} #----------------------------------------------------------------------------
# Main logic
#----------------------------------------------------------------------------
if ( "" eq $sPool )
{
#------------------------------------------------------------------------
# No pool supplied. Query pool list and display members for given pool
#------------------------------------------------------------------------
$soapResponse = $Pool->get_list();
&checkResponse($soapResponse);
@pool_list = @{$soapResponse->result}; &showPoolMembers(@pool_list);
}
elsif ( "" eq $sNodeAddr )
{
#------------------------------------------------------------------------
# Pool supplied, but now member so display given pools members
#------------------------------------------------------------------------
&showPoolMembers($sPool);
}
else
{
#------------------------------------------------------------------------
# both pool and member supplied so toggle the specified member.
#------------------------------------------------------------------------
&togglePoolMember($sPool, $sNodeAddr);
} #----------------------------------------------------------------------------
# Show list of pools and members
#----------------------------------------------------------------------------
sub showPoolMembers()
{
my (@pool_list) = @_;
my @member_state_lists = &getPoolMemberStates(@pool_list); print "Available pool members\n";
print "======================\n";
$i = 0;
foreach $pool (@pool_list)
{
print "pool $pool\n{\n";
@member_state_list = @{@member_state_lists[$i]};
foreach $member_state (@member_state_list)
{
$member = $member_state->{"member"};
$addr = $member->{"address"};
$port = $member->{"port"}; $session_state = $member_state->{"session_state"}; print " $addr:$port ($session_state)\n";
}
print "}\n";
$i++;
}
} #----------------------------------------------------------------------------
# Toggle a specified pool member
#----------------------------------------------------------------------------
sub togglePoolMember()
{
my ($pool_name, $member_def) = (@_); #------------------------------------------------------------------------
# Split apart node:port
#------------------------------------------------------------------------
($sNodeIP, $sNodePort) = split(/:/, $member_def, 2);
if ( "" eq $sNodePort )
{
$sNodePort = "0";
}
$member = { address => $sNodeIP, port => $sNodePort }; #--------------------------------------------------------------------
# Query enabled state for given Node:port
#--------------------------------------------------------------------
$pool_member_state = &getPoolMemberState($pool_name, $member); #----------------------------------------------------------------
# Set the state to be toggled to.
#----------------------------------------------------------------
my $toggleState = "STATE_DISABLED";
if ( "STATE_DISABLED" eq $pool_member_state )
{
$toggleState = "STATE_ENABLED";
}
elsif ( "STATE_ENABLED" eq $pool_member_state )
{
$toggleState = "STATE_DISABLED";
}
else
{
die("Couldn't find member $member_def in pool $pool_name\n");
} $MemberSessionState =
{
member => $member,
session_state => $toggleState
};
push @MemberSessionStateList, $MemberSessionState;
push @MemberSessionStateLists, [@MemberSessionStateList]; #----------------------------------------------------------------
# Toggle the state.
#----------------------------------------------------------------
$soapResponse =
$PoolMember->set_session_enabled_state
(
SOAP::Data->name ( pool_names => ( [$pool_name] ) ),
SOAP::Data->name ( session_states => [@MemberSessionStateLists] )
);
&checkResponse($soapResponse);
$MemberMonitorState =
{
member => $member,
monitor_state => $toggleState
};
push @MemberMonitorStateList, $MemberMonitorState;
push @MemberMonitorStateLists, [@MemberMonitorStateList];
#-------------------------------------------------------------
# Toggle the Monitor State
#-------------------------------------------------------------
$soapResponse = $PoolMember->set_monitor_state
(SOAP::Data->name ( pool_names => ( [$pool_name] ) ),
SOAP::Data->name ( monitor_states => [@MemberMonitorStateLists] ));
&checkResponse($soapResponse);
print "Pool Member $pool_name {$sNodeIP:$sNodePort} state set from '$pool_member_state' to '$toggleState'\n";
} #----------------------------------------------------------------------------
# returns the status structures for the members of the specified pools
#----------------------------------------------------------------------------
sub getPoolMemberStates()
{
my (@pool_list) = @_; $soapResponse = $PoolMember->get_session_enabled_state
(
SOAP::Data->name(pool_names => [@pool_list])
);
&checkResponse($soapResponse);
@member_state_lists = @{$soapResponse->result}; return @member_state_lists;
} #----------------------------------------------------------------------------
# Get the actual state of a given pool member
#----------------------------------------------------------------------------
sub getPoolMemberState()
{
my ($pool_name, $member_def) = (@_);
my $state = "";
@member_state_lists = &getPoolMemberStates($pool_name);
@member_state_list = @{@member_state_lists[0]};
foreach $member_state (@member_state_list)
{
my $member = $member_state->{"member"};
if ( ($member->{"address"} eq $member_def->{"address"}) and
($member->{"port"} eq $member_def->{"port"}) )
{
$state = $member_state->{"session_state"}
}
}
return $state;
} #----------------------------------------------------------------------------
# checkResponse
#----------------------------------------------------------------------------
sub checkResponse()
{
my ($soapResponse) = (@_);
if ( $soapResponse->fault )
{
print $soapResponse->faultcode, " ", $soapResponse->faultstring, "\n";
exit();
}
}

F5设备控制脚本的更多相关文章

  1. loadrunner 脚本开发-基本知识

    脚本开发-基本知识 1)编码工具设置 自动补全输入Tools->General Options->Environment->Auto complete word 显示功能语法Tool ...

  2. loadrunner-录制脚本,设置代理,参数化,校验点,关联

    详细记录一个脚本制作过程相关知识点 制作脚本 因为要做网页所以选择web协议,根据实际需要选择 选择浏览器地址,打开的网页网址,脚本存储地址以及初始化脚本,初始化脚本的目的是执行用例后不再执行此脚本中 ...

  3. loadrunder之脚本篇——脚本基础知识和常用操作

    1)编码工具设置 自动补全输入Tools->General Options->Environment->Auto complete word 显示功能语法Tools->Genr ...

  4. ;~ 并发运行的AutoHotkey脚本真机实际测试模板参考20191010.ahk

    ;~ 并发运行的AutoHotkey脚本真机实际测试模板参考20191010.ahk;~ 2019年10月10日;~ 徐晓亮(aahk6188);~ 操作系统测试环境: Windows 7 专业版 3 ...

  5. ;~ 小部分AutoHotkey脚本源代码测试模板样板.ahk

    ; ;~ 小部分AutoHotkey脚本源代码测试模板样板.ahk ;~ 请把一行或几行少量代码放到此文件中实际测试一下,;~ 看看测试结果如何,等到能够实现代码功能时再复制到自己的脚本代码文件中;~ ...

  6. [很郁闷]python2.7连接mysql5.5配置

    前言:今天在公司电脑上python版本跟自己家里电脑上的一样,不一样的是mysql公司版本5.6,结果花了两天的时间都没配置好python和mysql 简单说就是python连接mysql一直报200 ...

  7. WHY数学图形可视化工具(开源)

    WHY数学图形可视化工具 软件下载地址:http://files.cnblogs.com/WhyEngine/WhyMathGraph.zip 源码下载地址: http://pan.baidu.com ...

  8. QTP自传之录制

    录制,是一件吃力不讨好的活.很多人以为录制就是我的主要甚至全部的功能,这是大错特错的.不过,录制功能却是不熟悉我的人了解我的有效途径,是大家学习的有力武器.今天就先从录制功能说起吧. 说到录制,就不得 ...

  9. 从0开始的Python学习001快速上手手册

    假设大家已经安装好python的环境了. Windows检查是否可以运行python脚本 Ctrl+R 输入 cmd 在命令行中输入python 如果出现下面结果,我们就可以开始python的学习了. ...

随机推荐

  1. selenium3+python-多窗口、句柄(handle)

    一.获取当前窗口句柄 1.元素有属性,浏览器的窗口其实也有属性的,只是你看不到,浏览器窗口的属性用句柄(handle)来识别. 2.人为操作的话,可以通过眼睛看,识别不同的窗口点击切换.但是脚本没长眼 ...

  2. 我和CSDN的那些事

    作者:朱金灿 来源:http://blog.csdn.net/clever101 前些日子收到这样一个邀请: CSDN的工作人员还来电给我确认是否能参加.开始我有点犹豫,毕竟是在工作日的晚上,毕竟离我 ...

  3. [2月1号] 努比亚全机型ROM贴 最全最新NubiaUI5.0 ROOT 极速体验

    前言 感谢在开发过程中mandfx和dgtl198312予以的帮助!本帖将整理所有Nubia手机的最新刷机包,还有少数机型未制作刷机包,需要的机油可以联系我制作recovery以及刷机包加群23722 ...

  4. 关于MVC4.0版本以上的RegisterBundles用法

    public class BundleConfig { //新建了一个项目文件,打开App_Start下的BundleConfig看看, public static void RegisterBund ...

  5. Embedded之Stack之三

    Stack Overflow While stacks are generally large, they don't occupy all of memory. It is possible to ...

  6. WPF度量系統

    和Winform不同,WPF的度量單位不是像素,而是設備無關單位DIU,其大小總是1/96吋 那麽,WPF中一個寬度爲96的按鈕,到底是多少個像素呢? 答:取決於系統DPI. 計算公式爲:實際像素 = ...

  7. windows server 2012 r2 安装无法找到install.wim 错误代码0x80070026,以及制作U启动盘决解ISO文件超过5G大小限制的解决方案(转)

    戴尔服务器r530 windows server 2012 r2 安装无法找到install.wim 错误代码0x80070026,以及制作U启动盘决解ISO文件超过5G大小限制的解决方案 关于在服务 ...

  8. webapi部署到IIS 404错误

    环境:win2008r2+IIS 解决方案: 添加一个映射 可执行文件地址(根据系统决定64位可32位): C:\Windows\Microsoft.NET\Framework64\v4.0.3031 ...

  9. 在 Laravel 应用中使用 pjax 进行页面加速

    说明# PHPHub 使用 pjax 来加速网页的加载, 这篇文章是在开发完此功能后做的笔记. 什么是 Pjax# .--. / \ ## a a ( '._) |'-- | _.\___/_ ___ ...

  10. 一个休假申请页对input标签各种属性的用法案例(手机端)

    <%@ page language="java" import="java.util.*" contentType="text/html; ch ...