此脚本用于控制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. golang 随机数/域名校验

    //随机数生成要用到的 const letterBytes = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ...

  2. Ajax 传递json字符串到客户端时报 Internal server error

    架构:struts2+JQuery 需求:就是前台请求后台,后台查询数据库,将数据转换成json格式,使用struts2框架赋值给action内的变量jsonStr,前台通过 response.jso ...

  3. 关于17个Cr的430采购的注意事项 430F

    430F不锈钢是在430钢上加上易切削性能的钢种.用于自动车床.螺栓和螺母等.430LX在430钢中添加Ti或Nb.降低C含量,改善了加工性能的和焊接性能.用于热水罐.供热水系统.卫生器具.家庭用耐用 ...

  4. (转载)实例详解Android快速开发工具类总结

    实例详解Android快速开发工具类总结 作者:LiJinlun 字体:[增加 减小] 类型:转载 时间:2016-01-24我要评论 这篇文章主要介绍了实例详解Android快速开发工具类总结的相关 ...

  5. 总结:Ruby里是值传递还是引用传递

    在ruby中一切都是对象,而你向方法中传递的实质上是对象的引用( object-reference).ruby中变量都是对象的引用. 先来看 def pref2(agr) agr.downcase e ...

  6. github添加公钥出现 github ssh key Key is invalid. Ensure you've copied the file correctly的解决办法

    因为在公钥查看的时候可能是利用了vim明明查看,所以会有换行,导致这个错误,解决方法是用cat命令查看文件,或者其他方式查看,总之公钥不能有换行.

  7. Shiny学习实践01

    Shiny是什么东东? 官方描述: Shiny is an R package that makes it easy to build interactive web apps straight fr ...

  8. IIS日志分析:SC-Status语义

    在网站属性-网站-日志(属性) 中进行设定该站点IIS日志常规属性和扩展属性,扩展属性设置IIS日志包含字段显示. HTTP协议状态(sc-status)码的含义  IIS中 100 Continue ...

  9. Uoj #274. 【清华集训2016】温暖会指引我们前行 LCT维护边权_动态最小生成树

    Code: 行#include<bits/stdc++.h> #define ll long long #define maxn 1000000 #define inf 100000000 ...

  10. freemarker使用map替换字符串中的值

    package demo01; import java.io.IOException;import java.io.OutputStreamWriter;import java.io.StringRe ...