benclerc / aruba-switchapi
用于与Aruba SwitchAPI (ArubaOS)交互的库。
1.9
2021-08-02 08:30 UTC
Requires
- php: >=7.4.0
README
Aruba SwitchAPI 是一个PHP库,用于请求Aruba交换机(ArubaOS)。此库可以检索、创建、更新和删除交换机上的配置。它可以用来
- 从由PHP设计的Web界面配置交换机。
- 使用PHP脚本备份交换机配置。
- 更多功能,取决于您!
警告:此库不完整,主要面向POE、VLAN、端口和LED定位器。欢迎贡献力量!
您可以在 Aruba的网站上找到所有支持的方法,选择您的设备并下载API文档。
目录
入门
- 获取 Composer。
- 使用composer安装库
composer require benclerc/aruba-switchapi
。 - 将以下内容添加到您的应用程序的主PHP文件中
require 'vendor/autoload.php';
。 - 使用交换机的主机名、用户名和密码实例化Config类
$configSwitch = new \Aruba\Config('123.123.123.123', 'admin', 'password');
。 - 使用先前创建的Config对象来实例化SwitchAPI对象
$switch = new \Aruba\SwitchAPI($configSwitch);
。 - 开始使用库
$runningConf = $switch->getRunningConfig();
。
文档
您可以在 这里找到完整的文档。
Config类
此Config类用于准备实例化和使用SwitchAPI类的必要配置信息。在构造函数中,您必须传递
- 交换机的主机名(FQDN)或IP地址
- 有效的用户名
- 有效的密码
可选参数
- 超时:5000ms。使用
setTimeout()
更改。 - SSL验证对方选项:TRUE。使用
setSSLVerifyPeer()
更改。 - SSL验证主机选项:2。使用
setSSLVerifyHost()
更改。 - API版本:'v7'。使用
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()); }
SwitchAPI类
用法
此类使用异常来处理错误,对于正常执行,您应该在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()); }
可用方法
您可以在 这里浏览所有可用方法。