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 ());
}
您可以在此處瀏覽所有可用的方法。