Aruba SwitchAPI
1.0.0
Aruba SwitchAPI是一个用于请求 Aruba 交换机 (ArubaOS) 的 PHP 库。该库可以检索、创建、更新和删除交换机上的配置。它可以用于:
警告:该库不完整,主要面向 POE、VLAN、端口和 LED 定位器。欢迎贡献!
您可以在 Aruba 网站上找到所有支持的方法,选择您的设备并下载 API 文档。
composer require benclerc/aruba-switchapi
安装库。require 'vendor/autoload.php';
。$configSwitch = new ArubaConfig('123.123.123.123', 'admin', 'password');
。$switch = new ArubaSwitchAPI($configSwitch);
。$runningConf = $switch->getRunningConfig();
。 您可以在此处找到完整的文档。
该 Config 类用于准备实例化和使用 SwitchAPI 类所需的强制配置信息。在构造函数中,您必须传递:
可选参数:
setTimeout()
来改变。setSSLVerifyPeer()
进行更改。setSSLVerifyHost()
进行更改。setAPIVersion()
进行更改(仅支持 >= v7)。例子 :
// Basic configuration
$ configSwitch = new Aruba Config ( ' 123.123.123.123 ' , ' admin ' , ' password ' );
// Configuration for very slow switchs/long requests
$ configSwitch = new Aruba Config ( ' 123.123.123.123 ' , ' admin ' , ' password ' );
$ configSwitch -> setTimeout ( 20000 );
// Unsecure configuration
$ configSwitch = new Aruba Config ( ' 123.123.123.123 ' , ' admin ' , ' password ' );
$ configSwitch -> setSSLVerifyPeer ( FALSE )-> setSSLVerifyHost ( FALSE );
// Special API version
$ configSwitch = new Aruba Config ( ' 123.123.123.123 ' , ' admin ' , ' password ' );
$ configSwitch -> setAPIVersion ( ' v8 ' );
// The class logins to the switch when being instanciated hence the try/catch statement.
try {
$ switch = new Aruba SwitchAPI ( $ configSwitch );
} catch ( Exception $ e ) {
echo ( ' Handle error : ' . $ e -> getMessage ());
}
此类使用 Exception 来处理错误,对于名义执行,您应该在 try/catch 语句内实例化和请求方法。
例子:
// Blink for 1 min LED locator
try {
$ res = $ switch -> blinkLedLocator ( 2 , 1 );
if ( $ res ) {
echo ( ' Blink succeeded ' );
} else {
echo ( ' Blink failed ' );
}
} catch ( Exception $ e ) {
echo ( ' Handle error : ' . $ e -> getMessage ());
}
// Create a VLAN
try {
$ res = $ switch -> createVlan ( 666 , ' HELL ' );
if ( $ res ) {
echo ( ' The VLAN has been created. ' );
} else {
echo ( ' Error : the VLAN was not created. ' );
}
} catch ( Exception $ e ) {
echo ( ' Handle error : ' . $ e -> getMessage ());
}
// Get status of all ports
try {
$ res = $ switch -> getPortsStatus ();
if ( $ res != FALSE ) {
foreach ( $ res as $ key => $ value ) {
$ status = ( $ value -> is_port_enabled ) ? ' up ' : ' down ' ;
echo ( ' Port ' . $ value -> id . ' is ' . $ status . ' <br> ' );
}
} else {
echo ( ' Error : status could not be retrieved. ' );
}
} catch ( Exception $ e ) {
echo ( ' Handle error : ' . $ e -> getMessage ());
}
// Set untagged VLAN 666 on port 42
try {
$ res = $ switch -> setUVlanPort ( 666 , ' 42 ' );
if ( $ res ) {
echo ( ' The VLAN 666 has been affected to the port 42. ' );
} else {
echo ( ' Error : the VLAN was not affected. ' );
}
} catch ( Exception $ e ) {
echo ( ' Handle error : ' . $ e -> getMessage ());
}
您可以在此处浏览所有可用的方法。