istic-openstack/server/core/NetworkLayer3.php

532 lines
13 KiB
PHP
Raw Normal View History

2016-04-18 17:20:27 +02:00
<?php
/**
2016-04-27 14:22:59 +02:00
* File containing the networkLayer3 Class.
2016-04-18 17:20:27 +02:00
*
* @version 1.0 Initialisation of this file
* @since 1.0 Core application's file
*
* @author Evan Pisani 'yogg at epsina . com'
*
*/
2016-04-27 14:22:59 +02:00
2016-04-18 17:20:27 +02:00
use OpenCloud\Common\Error\BadResponseError;
use OpenCloud\Common\Error\BaseError;
use OpenCloud\Common\Error\NotImplementedError;
use OpenCloud\Common\Error\UserInputError;
2016-05-05 19:16:10 +02:00
require_once("CoreInterface.php");
2016-04-18 17:20:27 +02:00
/**
2016-04-27 14:22:59 +02:00
* networkLayer3 Class of the back-end application
2016-04-18 17:20:27 +02:00
*
2016-04-27 14:22:59 +02:00
* Management of networkLayer3
2016-04-18 17:20:27 +02:00
*
*/
2016-04-27 14:22:59 +02:00
class networkLayer3 implements Core{
2016-04-18 17:20:27 +02:00
/** @var App $app protected, contains the main app object */
protected $app;
2016-04-27 14:22:59 +02:00
/** @var OpenStack\NetworkLayer3 $libClass protected, contains the library NetworkLayer3 object */
2016-04-18 17:20:27 +02:00
protected $libClass;
/**
2016-04-27 14:22:59 +02:00
* networkLayer3 constructor
2016-04-18 17:20:27 +02:00
*
* @param App $app the main app object
*
2016-04-27 14:22:59 +02:00
* @return networkLayer3 Object
2016-04-18 17:20:27 +02:00
*/
public function __construct($app){
if(!isset($app)){
$this->app->setOutput("Error", "Incorrect parameter app");
}
$this->app = $app;
$this->libClass = $app->getLibClass("NetworkLayer3");
2016-04-18 17:20:27 +02:00
}
/**
* Execute an action
*
* @param String $action name of another function of this class
*
2016-04-27 14:22:59 +02:00
* @return void
2016-04-18 17:20:27 +02:00
*/
public function action($action){
2016-04-26 20:42:31 +02:00
$this->{$action.""}();
2016-04-18 17:20:27 +02:00
}
2016-04-19 18:00:37 +02:00
/**
* List floatingip
*
2016-04-27 14:22:59 +02:00
* @return void
2016-04-19 18:00:37 +02:00
*/
private function listFloatingIp(){
try{
$result = array();
2016-04-19 19:44:09 +02:00
$l = $this->libClass->listFloatingIps();
error_log(var_export($l, true), 0);
2016-04-19 18:00:37 +02:00
foreach ($l as $tmp) {
2016-04-19 18:33:21 +02:00
$result[] = $tmp;
2016-04-19 18:00:37 +02:00
}
2016-04-19 18:33:21 +02:00
$this->app->setOutput("NetworkLayer3", $result);
2016-04-19 18:00:37 +02:00
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
2016-04-26 20:42:31 +02:00
}catch(UserInputError $e){
2016-04-19 18:00:37 +02:00
$this->app->getErrorInstance()->UserInputHandler($e);
2016-04-26 20:42:31 +02:00
}catch(BaseError $e){
2016-04-19 18:00:37 +02:00
$this->app->getErrorInstance()->BaseErrorHandler($e);
2016-04-26 20:42:31 +02:00
}catch(NotImplementedError $e){
2016-04-19 18:00:37 +02:00
$this->app->getErrorInstance()->NotImplementedHandler($e);
2016-04-26 20:42:31 +02:00
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
2016-04-19 18:00:37 +02:00
}
2016-04-18 17:20:27 +02:00
/**
* Create a new floating IP adress
*
2016-04-21 22:52:00 +02:00
* @param array $opt Options for the floating ip creation (floatingNetworkId is required)
2016-04-18 17:20:27 +02:00
*
2016-04-27 14:22:59 +02:00
* @return void
2016-04-18 17:20:27 +02:00
*/
private function createFloatingIp(){
$opt = $this->app->getPostParam("opt");
if(!isset($opt)){
$this->app->setOutput("Error", "Incorrect parameter opt");
}
try{
2016-04-19 23:57:03 +02:00
$floatingip = $this->libClass->createFloatingIp($opt);
2016-04-21 21:31:25 +02:00
2016-04-19 18:00:37 +02:00
if(!isset($floatingip)){
2016-04-18 17:20:27 +02:00
$this->app->setOutput("Error", "Unknowing error during floating ip creation");
2016-04-21 21:31:25 +02:00
}else{
$this->app->setOutput("NetworkLayer3", $floatingip);
2016-04-18 17:20:27 +02:00
}
2016-04-19 23:57:03 +02:00
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
2016-04-26 20:42:31 +02:00
}catch(UserInputError $e){
2016-04-19 23:57:03 +02:00
$this->app->getErrorInstance()->UserInputHandler($e);
2016-04-26 20:42:31 +02:00
}catch(BaseError $e){
2016-04-19 23:57:03 +02:00
$this->app->getErrorInstance()->BaseErrorHandler($e);
2016-04-26 20:42:31 +02:00
}catch(NotImplementedError $e){
2016-04-19 23:57:03 +02:00
$this->app->getErrorInstance()->NotImplementedHandler($e);
2016-04-26 20:42:31 +02:00
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
2016-04-19 23:57:03 +02:00
}
/**
* Show floatingip details
*
* @param String id the id of the floatingip
*
2016-04-27 14:22:59 +02:00
* @return void
2016-04-19 23:57:03 +02:00
*/
private function getFloatingIp(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter opt");
}
try{
2016-04-21 21:31:25 +02:00
// List of floating IPs
$res = array();
$l = $this->libClass->listFloatingIps();
foreach ($l as $tmp) {
$res[] = $tmp;
}
// Verification if id exists
$result = null;
foreach ($res as $f) {
2016-04-21 22:52:00 +02:00
if(strcmp($f->id, $id)){
2016-04-21 21:31:25 +02:00
$result = $f;
2016-04-26 20:42:31 +02:00
2016-04-19 23:57:03 +02:00
}
}
2016-04-21 21:31:25 +02:00
if(!isset($result)){ // If id doesn't exists
2016-04-19 23:57:03 +02:00
$this->app->setOutput("Error", "Unknow id");
2016-04-21 21:31:25 +02:00
}else{ // If id exists
2016-04-19 23:57:03 +02:00
$res = $this->libClass->getFloatingIp($id);
$this->app->setOutput("NetworkLayer3", $res);
2016-04-21 21:31:25 +02:00
}
2016-04-18 17:20:27 +02:00
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
2016-04-26 20:42:31 +02:00
}catch(UserInputError $e){
2016-04-18 17:20:27 +02:00
$this->app->getErrorInstance()->UserInputHandler($e);
2016-04-26 20:42:31 +02:00
}catch(BaseError $e){
2016-04-18 17:20:27 +02:00
$this->app->getErrorInstance()->BaseErrorHandler($e);
2016-04-26 20:42:31 +02:00
}catch(NotImplementedError $e){
2016-04-18 17:20:27 +02:00
$this->app->getErrorInstance()->NotImplementedHandler($e);
2016-04-26 20:42:31 +02:00
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
2016-04-18 17:20:27 +02:00
}
/**
* Update floating ip
*
* @param id the id of the floatingip to update
*
2016-04-27 14:22:59 +02:00
* @return void
2016-04-18 17:20:27 +02:00
*/
private function updateFloatingIp(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter opt");
}
try{
2016-04-21 21:31:25 +02:00
// List of floating IPs
$res = array();
$l = $this->libClass->listFloatingIps();
foreach ($l as $tmp) {
$res[] = $tmp;
}
// Verification if id exists
$result = null;
foreach ($res as $f) {
2016-04-21 22:52:00 +02:00
if(strcmp($f->id, $id)){
2016-04-21 21:31:25 +02:00
$result = $f;
2016-04-26 20:42:31 +02:00
}
}
2016-04-21 21:31:25 +02:00
if(!isset($result)){ // If id doesn't exists
$this->app->setOutput("Error", "Unknowing floatingip id");
2016-04-21 21:31:25 +02:00
}else{
$result->update();
}
2016-04-18 17:20:27 +02:00
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
2016-04-26 20:42:31 +02:00
}catch(UserInputError $e){
2016-04-18 17:20:27 +02:00
$this->app->getErrorInstance()->UserInputHandler($e);
2016-04-26 20:42:31 +02:00
}catch(BaseError $e){
2016-04-18 17:20:27 +02:00
$this->app->getErrorInstance()->BaseErrorHandler($e);
2016-04-26 20:42:31 +02:00
}catch(NotImplementedError $e){
2016-04-18 17:20:27 +02:00
$this->app->getErrorInstance()->NotImplementedHandler($e);
2016-04-26 20:42:31 +02:00
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
2016-04-18 17:20:27 +02:00
}
/**
* Delete a floating ip
*
* @param string floatingip_id the floating-ip id to delete
*
2016-04-27 14:22:59 +02:00
* @return void
2016-04-18 17:20:27 +02:00
*/
private function deleteFloatingIp(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter opt");
}
try{
2016-04-21 21:31:25 +02:00
// List of floating IPs
$res = array();
$l = $this->libClass->listFloatingIps();
foreach ($l as $tmp) {
$res[] = $tmp;
}
// Verification if id exists
$result = null;
foreach ($res as $f) {
2016-04-21 22:52:00 +02:00
if(strcmp($f->id, $id)){
2016-04-21 21:31:25 +02:00
$result = $f;
2016-04-26 20:42:31 +02:00
}
}
2016-04-21 21:31:25 +02:00
if(!isset($result)){ // If id doesn't exists
$this->app->setOutput("Error", "Unknowing floatingip id");
2016-04-21 21:31:25 +02:00
}else{
$result->delete();
}
2016-04-18 17:20:27 +02:00
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
2016-04-26 20:42:31 +02:00
}catch(UserInputError $e){
2016-04-18 17:20:27 +02:00
$this->app->getErrorInstance()->UserInputHandler($e);
2016-04-26 20:42:31 +02:00
}catch(BaseError $e){
2016-04-18 17:20:27 +02:00
$this->app->getErrorInstance()->BaseErrorHandler($e);
2016-04-26 20:42:31 +02:00
}catch(NotImplementedError $e){
2016-04-18 17:20:27 +02:00
$this->app->getErrorInstance()->NotImplementedHandler($e);
2016-04-26 20:42:31 +02:00
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
2016-04-18 17:20:27 +02:00
}
2016-04-21 21:31:25 +02:00
2016-04-18 17:20:27 +02:00
/**
* Retrieve a floating ip
*
* @param string floatingip_id the floating-ip id to retrieve
*
2016-04-27 14:22:59 +02:00
* @return void
2016-04-18 17:20:27 +02:00
*/
private function retrieveFloatingIp(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter opt");
}
try{
2016-04-21 21:31:25 +02:00
// List of floating IPs
$res = array();
$l = $this->libClass->listFloatingIps();
foreach ($l as $tmp) {
$res[] = $tmp;
}
// Verification if id exists
$result = null;
foreach ($res as $f) {
2016-04-21 22:52:00 +02:00
if(strcmp($f->id, $id)){
2016-04-21 21:31:25 +02:00
$result = $f;
2016-04-26 20:42:31 +02:00
}
}
2016-04-21 21:31:25 +02:00
if(!isset($result)){ // If id doesn't exists
$this->app->setOutput("Error", "Unknowing floatingip id");
2016-04-21 21:31:25 +02:00
}else{
$result->retrieve();
}
2016-04-18 17:20:27 +02:00
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
2016-04-26 20:42:31 +02:00
}catch(UserInputError $e){
2016-04-18 17:20:27 +02:00
$this->app->getErrorInstance()->UserInputHandler($e);
2016-04-26 20:42:31 +02:00
}catch(BaseError $e){
2016-04-18 17:20:27 +02:00
$this->app->getErrorInstance()->BaseErrorHandler($e);
2016-04-26 20:42:31 +02:00
}catch(NotImplementedError $e){
2016-04-18 17:20:27 +02:00
$this->app->getErrorInstance()->NotImplementedHandler($e);
2016-04-26 20:42:31 +02:00
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
2016-04-18 17:20:27 +02:00
}
2016-04-21 22:52:00 +02:00
/**
* Create a new router
*
* @param array $opt Options for the new router
* externalGatewayInfo[] required (only the param networkId in the tab)
* adminStateUp (optionnal)
* name (optionnal)
*
2016-04-27 14:22:59 +02:00
* @return void
2016-04-21 22:52:00 +02:00
*/
private function createRouter(){
$opt = $this->app->getPostParam("opt");
if(!isset($opt)){
$this->app->setOutput("Error", "Incorrect parameter opt");
}
try{
$router = $this->libClass->createRouter($opt);
if(!isset($router)){
$this->app->setOutput("Error", "Unknowing error during floating ip creation");
}else{
$this->app->setOutput("NetworkLayer3", $router);
}
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
2016-04-26 20:42:31 +02:00
}catch(UserInputError $e){
2016-04-21 22:52:00 +02:00
$this->app->getErrorInstance()->UserInputHandler($e);
2016-04-26 20:42:31 +02:00
}catch(BaseError $e){
2016-04-21 22:52:00 +02:00
$this->app->getErrorInstance()->BaseErrorHandler($e);
2016-04-26 20:42:31 +02:00
}catch(NotImplementedError $e){
2016-04-21 22:52:00 +02:00
$this->app->getErrorInstance()->NotImplementedHandler($e);
2016-04-26 20:42:31 +02:00
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
2016-04-21 22:52:00 +02:00
}
/**
* List routers
*
2016-04-27 14:22:59 +02:00
* @return void
2016-04-21 22:52:00 +02:00
*/
private function listRouters(){
try{
$result = array();
$l = $this->libClass->listRouters();
foreach ($l as $tmp) {
$result[] = $tmp;
}
$this->app->setOutput("NetworkLayer3", $result);
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
2016-04-26 20:42:31 +02:00
}catch(UserInputError $e){
2016-04-21 22:52:00 +02:00
$this->app->getErrorInstance()->UserInputHandler($e);
2016-04-26 20:42:31 +02:00
}catch(BaseError $e){
2016-04-21 22:52:00 +02:00
$this->app->getErrorInstance()->BaseErrorHandler($e);
2016-04-26 20:42:31 +02:00
}catch(NotImplementedError $e){
2016-04-21 22:52:00 +02:00
$this->app->getErrorInstance()->NotImplementedHandler($e);
2016-04-26 20:42:31 +02:00
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
2016-04-21 22:52:00 +02:00
}
/**
* Show router details
*
* @param String id the id of the router
*
2016-04-27 14:22:59 +02:00
* @return void
2016-04-21 22:52:00 +02:00
*/
private function getRouter(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter opt");
}
try{
// List of routers
$res = array();
$l = $this->libClass->listRouters();
foreach ($l as $tmp) {
$res[] = $tmp;
}
// Verification if id exists
$result = null;
foreach ($res as $f) {
if(strcmp($f->id, $id)){
$result = $f;
}
}
if(!isset($result)){ // If id doesn't exists
$this->app->setOutput("Error", "Unknow id");
}else{ // If id exists
$res = $this->libClass->getRouter($id);
$this->app->setOutput("NetworkLayer3", $res);
}
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
2016-04-26 20:42:31 +02:00
}catch(UserInputError $e){
2016-04-21 22:52:00 +02:00
$this->app->getErrorInstance()->UserInputHandler($e);
2016-04-26 20:42:31 +02:00
}catch(BaseError $e){
2016-04-21 22:52:00 +02:00
$this->app->getErrorInstance()->BaseErrorHandler($e);
2016-04-26 20:42:31 +02:00
}catch(NotImplementedError $e){
2016-04-21 22:52:00 +02:00
$this->app->getErrorInstance()->NotImplementedHandler($e);
2016-04-26 20:42:31 +02:00
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
2016-04-21 22:52:00 +02:00
}
/**
* Delete a router
*
* @param string router the router to delete
*
2016-04-27 14:22:59 +02:00
* @return void
2016-04-21 22:52:00 +02:00
*/
private function deleteRouter(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter opt");
}
try{
// List of routers
$res = array();
$l = $this->libClass->listRouters();
foreach ($l as $tmp) {
$res[] = $tmp;
}
// Verification if id exists
$result = null;
foreach ($res as $f) {
if(strcmp($f->id, $id)){
$result = $f;
}
}
if(!isset($result)){ // If id doesn't exists
$this->app->setOutput("Error", "Unknowing router id");
}else{
$result->delete();
}
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
2016-04-26 20:42:31 +02:00
}catch(UserInputError $e){
2016-04-21 22:52:00 +02:00
$this->app->getErrorInstance()->UserInputHandler($e);
2016-04-26 20:42:31 +02:00
}catch(BaseError $e){
2016-04-21 22:52:00 +02:00
$this->app->getErrorInstance()->BaseErrorHandler($e);
2016-04-26 20:42:31 +02:00
}catch(NotImplementedError $e){
2016-04-21 22:52:00 +02:00
$this->app->getErrorInstance()->NotImplementedHandler($e);
2016-04-26 20:42:31 +02:00
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
2016-04-21 22:52:00 +02:00
}
/**
* Update router
*
* @param id the id of the floatingip to update
*
2016-04-27 14:22:59 +02:00
* @return void
2016-04-21 22:52:00 +02:00
*/
private function updateRouter(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter opt");
}
try{
// List of floating IPs
$res = array();
$l = $this->libClass->listRouters();
foreach ($l as $tmp) {
$res[] = $tmp;
}
// Verification if id exists
$result = null;
foreach ($res as $f) {
if(strcmp($f->id, $id)){
$result = $f;
2016-04-26 20:42:31 +02:00
2016-04-21 22:52:00 +02:00
}
}
if(!isset($result)){ // If id doesn't exists
$this->app->setOutput("Error", "Unknowing floatingip id");
}else{
$result->update();
}
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
2016-04-26 20:42:31 +02:00
}catch(UserInputError $e){
2016-04-21 22:52:00 +02:00
$this->app->getErrorInstance()->UserInputHandler($e);
2016-04-26 20:42:31 +02:00
}catch(BaseError $e){
2016-04-21 22:52:00 +02:00
$this->app->getErrorInstance()->BaseErrorHandler($e);
2016-04-26 20:42:31 +02:00
}catch(NotImplementedError $e){
2016-04-21 22:52:00 +02:00
$this->app->getErrorInstance()->NotImplementedHandler($e);
2016-04-26 20:42:31 +02:00
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
2016-04-21 22:52:00 +02:00
}
2016-04-18 17:20:27 +02:00
}