istic-openstack/server/core/App.php

134 lines
3.4 KiB
PHP
Raw Normal View History

<?php
2016-02-12 11:57:18 +01:00
include_once("core/Plugin_Api.php");
include_once("core/LibOverride/genTokenOptions.php");
2016-02-12 12:45:00 +01:00
include_once("core/ErrorManagement.php");
2016-03-09 15:21:46 +01:00
use OpenCloud\Common\Error\BadResponseError;
use OpenCloud\Common\Error\BaseError;
use OpenCloud\Common\Error\NotImplementedError;
use OpenCloud\Common\Error\UserInputError;
class App{
protected $openstack;
protected $pluginsApi;
2016-02-12 12:45:00 +01:00
protected $postParams;
protected $tokenClass;
protected $tokenPost;
2016-02-12 12:45:00 +01:00
protected $errorClass;
protected $output;
public function __construct($args){
$this->tokenPost = NULL;
$this->tokenClass = new genTokenOptions($args);
$this->openstack = new OpenStack\OpenStack([]);
$this->pluginsApi = plugin_api::getInstance();
2016-02-12 12:45:00 +01:00
$this->errorClass = new errorManagement($this);
$this->output = array();
2016-02-12 12:45:00 +01:00
$this->postParams = $_POST;
}
public function setToken($token){
$this->tokenPost = $token;
$this->tokenClass->loadBackup($this->tokenPost);
}
public function getLibClass($service){
switch($service){
case "Identity":
if($this->tokenPost == NULL) $this->tokenClass->genIdentityToken();
$opt = $this->tokenClass->getOptions($service);
return $this->openstack->identityV3($opt);
break;
case "Image":
if($this->tokenPost == NULL) $this->tokenClass->genImageToken();
$opt = $this->tokenClass->getOptions($service);
return $this->openstack->imagesV2($opt);
break;
2016-02-24 23:06:02 +01:00
case "Network":
if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken();
$opt = $this->tokenClass->getOptions($service);
return $this->openstack->networkingV2($opt);
break;
case "Compute":
2016-03-09 14:53:48 +01:00
if($this->tokenPost == NULL) $this->tokenClass->genComputeToken();
$opt = $this->tokenClass->getOptions($service);
return $this->openstack->computeV2($opt);
break;
}
}
public function authenticate(){
try{
$this->tokenClass->genIdentityToken();
$this->tokenClass->genComputeToken();
$this->tokenClass->genImageToken();
$this->tokenClass->genNetworkToken();
$this->setOutput("token", $this->tokenClass->getBackup());
2016-02-12 12:45:00 +01:00
}catch(BadResponseError $e){
$this->errorClass->BadResponseHandler($e);
}catch(UserInputError $e){
$this->errorClass->UserInputHandler($e);
}catch(BaseError $e){
$this->errorClass->BaseErrorHandler($e);
}catch(NotImplementedError $e){
$this->errorClass->NotImplementedHandler($e);
2016-03-09 14:53:48 +01:00
}
}
public function deauthenticate(){
try{
$this->tokenClass->revokeComputeToken();
$this->tokenClass->revokeImageToken();
$this->tokenClass->revokeNetworkToken();
$this->tokenClass->revokeIdentityToken();
$this->setOutput("deauthenticate", "Ok");
}catch(BadResponseError $e){
$this->errorClass->BadResponseHandler($e);
}catch(UserInputError $e){
$this->errorClass->UserInputHandler($e);
}catch(BaseError $e){
$this->errorClass->BaseErrorHandler($e);
}catch(NotImplementedError $e){
$this->errorClass->NotImplementedHandler($e);
}
}
2016-02-12 12:45:00 +01:00
public function getPostParam($name){
return $this->postParams[$name];
}
public function setOutput($key, $out){
$this->output[$key] = $out;
}
2016-02-12 12:45:00 +01:00
public function getErrorInstance(){
return $this->errorClass;
}
public function show(){
echo json_encode($this->output);
2016-02-28 22:54:51 +01:00
//error_log(var_dump(json_encode($this->output), true), 0);
}
}