简单的icontrol测试

根据OKnet icontrol 入门资料和基础代码来进行测试

参考:http://www.adntech.org/bbs/viewthread.php?tid=2213&extra=page%3D1

测试一:获取F5的版本

1)构造XML:SOAP请求,保存为soapreq_get_version.txt

view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?> 
<SOAP-ENV:Envelope 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/envelope/"> 
  <SOAP-ENV:Body> 
    <m:get_version xmlns:m="urn:iControl:System/SystemInfo"> 
    </m:get_version> 
  </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Body>
    <m:get_version xmlns:m="urn:iControl:System/SystemInfo">
    </m:get_version>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

2)使用curl 工具发送查询请求

curl --data-binary @soapreq_get_version.txt https://admin:[email protected]/iControl/iControlPortal.cgi --insecure

3)返回的结果如下:

<E:Envelope
        xmlns:E="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:A="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:s="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:y="http://www.w3.org/2001/XMLSchema"
        xmlns:iControl="urn:iControl"
        E:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<E:Body>
<m:get_versionResponse
        xmlns:m="urn:iControl:System/SystemInfo">
<return
        s:type="y:string">BIG-IP_v9.4.7</return>
</m:get_versionResponse>
</E:Body>
</E:Envelope>

测试二:通过PHP,使用cURL函数接口,通过HTTP POST XML:SOAP方式,实现调用。

1)在php.ini中打开extension=php_curl.dll选项

2)构造HTTP POST XML:SOAP的PHP页面内容,这里的重点是生成的http header 必要要以SOAP ACTION方式才能满足。

view plaincopy to clipboardprint?
<?php  
 
$postdata =   
'<?xml version="1.0" encoding="utf-8"?>  
<SOAP-ENV:Envelope  
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/envelope/">  
  <SOAP-ENV:Body>  
    <m:get_version xmlns:m="urn:iControl:System/SystemInfo">  
    </m:get_version>  
  </SOAP-ENV:Body>  
</SOAP-ENV:Envelope>';  
 
$soap_action = 'https://192.168.1.245/iControl/iControlPortal.cgi';  
$header [] = 'SOAPAction: "' . $soap_action . '"';  
 
$your_username="admin";  //change this to your login username  
$your_password="admin";  // change this to your  login password  
 
$ch = curl_init();  
curl_setopt($ch,CURLOPT_URL,"https://192.168.1.245/iControl/iControlPortal.cgi");  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);  
curl_setopt($ch, CURLOPT_HEADER, 0);  
curl_setopt($ch, CURLOPT_USERPWD, $your_username.':'.$your_password);  
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);   
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);   
 
$data = curl_exec($ch);  
 
$data = curl_exec($ch);  
 
if (curl_errno($ch)) {  
 print curl_error($ch);  
} else {  
 curl_close($ch);  
}  
 
echo $data;  
?> 
<?php

$postdata =
'<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Body>
    <m:get_version xmlns:m="urn:iControl:System/SystemInfo">
    </m:get_version>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>';

$soap_action = 'https://192.168.1.245/iControl/iControlPortal.cgi';
$header [] = 'SOAPAction: "' . $soap_action . '"';

$your_username="admin";  //change this to your login username
$your_password="admin";  // change this to your  login password

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"https://192.168.1.245/iControl/iControlPortal.cgi");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERPWD, $your_username.':'.$your_password);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

$data = curl_exec($ch);

$data = curl_exec($ch);

if (curl_errno($ch)) {
 print curl_error($ch);
} else {
 curl_close($ch);
}

echo $data;
?>
 

 3)这样访问该PHP页面就能得到F5的版本 BIG-IP_v9.4.7

测试三:获取F5的系统信息

1)查找icontrol的SDK,API Reference-WSDL-System-SystemInfo,得到F5的系统信息的参数是"get_system_information"

<operation name="get_system_information">

 <documentation>Gets the system-identifying attributes of the operating system.</documentation>

  <soap:operation soapAction="urn:iControl:System/SystemInfo" />

2)可以查到systeminformation返回的内容包含system_name,host_name 等等

<xsd:complexType name="System.SystemInformation">

- <xsd:sequence>
  <xsd:element name="system_name" type="xsd:string" />
  <xsd:element name="host_name" type="xsd:string" />
  <xsd:element name="os_release" type="xsd:string" />
  <xsd:element name="os_machine" type="xsd:string" />
  <xsd:element name="os_version" type="xsd:string" />
  <xsd:element name="platform" type="xsd:string" />
  <xsd:element name="product_category" type="xsd:string" />
  <xsd:element name="chassis_serial" type="xsd:string" />
  <xsd:element name="switch_board_serial" type="xsd:string" />
  <xsd:element name="switch_board_part_revision" type="xsd:string" />
  <xsd:element name="host_board_serial" type="xsd:string" />
  <xsd:element name="host_board_part_revision" type="xsd:string" />
  <xsd:element name="annunciator_board_serial" type="xsd:string" />
  <xsd:element name="annunciator_board_part_revision" type="xsd:string" />
  </xsd:sequence>
  </xsd:complexType>
3)构造包含有XML的PHP代码,如果要单独显示每一个元素的内容,需要查看返回的XML:SOAP的内容,了解元素名称和名称空间,才能对代码进行相应修改,这里的重点是使用simplexml_load_string调用XML:SOAP的结构时需要对调用的XML元素,定义名称空间,具体见代码,只有这样PHP才能正确解析XML:SOAP的内容。
view plaincopy to clipboardprint?
<?php  
$postdata =  
'<?xml version="1.0" encoding="utf-8"?>  
<SOAP-ENV:Envelope  
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/envelope/">  
  <SOAP-ENV:Body>  
    <m:get_system_information xmlns:m="urn:iControl:System/SystemInfo">  
    </m:get_system_information>  
  </SOAP-ENV:Body>  
</SOAP-ENV:Envelope>';  
 
$soap_action = 'https://192.168.1.245/iControl/iControlPortal.cgi';  
$header [] = 'SOAPAction: "' . $soap_action . '"';  
 
$your_username="admin";  //change this to your login username  
$your_password="admin";  // change this to your login password  
 
$ch = curl_init();  
curl_setopt($ch,CURLOPT_URL,"https://192.168.1.245/iControl/iControlPortal.cgi");  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);  
curl_setopt($ch, CURLOPT_HEADER, 0);  
curl_setopt($ch, CURLOPT_USERPWD, $your_username.':'.$your_password);  
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);  
 
$data = curl_exec($ch);  
 
if (curl_errno($ch)) {  
 print curl_error($ch);  
} else {  
 curl_close($ch);  
}  
$xml = simplexml_load_string($data,null,null,'http://schemas.xmlsoap.org/soap/envelope/');  
define("XMLNS_SOAPENV", "http://schemas.xmlsoap.org/soap/envelope/");  
define("XMLNS_SOAPM", "urn:iControl:System/SystemInfo");  
echo "Hostname :";  
echo "<br>";  
echo $xml 
    ->children(XMLNS_SOAPENV)->Body // change to soapenv namespace  
    ->children(XMLNS_SOAPM)->get_system_informationResponse // change to soapm namespace  
    ->children("")->return // change to default namespace  
    ->host_name // still in default namespace  
//    ->attributes(XMLNS_XSI) // attributes in the xsi namespace  
//    ->type  
;  
?> 
<?php
$postdata =
'<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Body>
    <m:get_system_information xmlns:m="urn:iControl:System/SystemInfo">
    </m:get_system_information>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>';

$soap_action = 'https://192.168.1.245/iControl/iControlPortal.cgi';
$header [] = 'SOAPAction: "' . $soap_action . '"';

$your_username="admin";  //change this to your login username
$your_password="admin";  // change this to your login password

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"https://192.168.1.245/iControl/iControlPortal.cgi");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERPWD, $your_username.':'.$your_password);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

$data = curl_exec($ch);

if (curl_errno($ch)) {
 print curl_error($ch);
} else {
 curl_close($ch);
}
$xml = simplexml_load_string($data,null,null,'http://schemas.xmlsoap.org/soap/envelope/');
define("XMLNS_SOAPENV", "http://schemas.xmlsoap.org/soap/envelope/");
define("XMLNS_SOAPM", "urn:iControl:System/SystemInfo");
echo "Hostname :";
echo "<br>";
echo $xml
    ->children(XMLNS_SOAPENV)->Body // change to soapenv namespace
    ->children(XMLNS_SOAPM)->get_system_informationResponse // change to soapm namespace
    ->children("")->return // change to default namespace
    ->host_name // still in default namespace
//    ->attributes(XMLNS_XSI) // attributes in the xsi namespace
//    ->type
;
?>
3)显示的内容为F5的主机名:
Hostname :
BIGIP3600.F5.COM

 

你可能感兴趣的:(F5,职场,休闲,iControl)