2016-02-05 00:07:31 +01:00
|
|
|
<?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");
|
|
|
|
|
|
|
|
use OpenStack\Common\Error\BadResponseError;
|
|
|
|
use OpenStack\Common\Error\BaseError;
|
|
|
|
use OpenStack\Common\Error\NotImplementedError;
|
|
|
|
use OpenStack\Common\Error\UserInputError;
|
2016-02-05 00:07:31 +01:00
|
|
|
|
|
|
|
class App{
|
|
|
|
|
|
|
|
protected $openstack;
|
|
|
|
protected $pluginsApi;
|
2016-02-12 12:45:00 +01:00
|
|
|
protected $postParams;
|
2016-02-05 00:07:31 +01:00
|
|
|
protected $tokenClass;
|
|
|
|
protected $tokenPost;
|
2016-02-12 12:45:00 +01:00
|
|
|
protected $errorClass;
|
2016-02-05 00:07:31 +01:00
|
|
|
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);
|
2016-02-05 00:07:31 +01:00
|
|
|
$this->output = array();
|
2016-02-12 12:45:00 +01:00
|
|
|
$this->postParams = $_POST;
|
2016-02-05 00:07:31 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setToken($token){
|
|
|
|
|
|
|
|
$this->tokenPost = $token;
|
|
|
|
$this->tokenClass->loadBackup($his->tokenPost);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLibClass($service){
|
|
|
|
|
|
|
|
switch($service){
|
|
|
|
case "Identity":
|
2016-02-12 12:11:11 +01:00
|
|
|
if($this->tokenPost == NULL) $this->tokenClass->genIdentityToken();
|
|
|
|
$opt = $this->tokenClass->getOptions($service);
|
2016-02-05 00:07:31 +01:00
|
|
|
return $this->openstack->identityV3($opt);
|
|
|
|
break;
|
2016-02-10 18:09:44 +01:00
|
|
|
case "Image":
|
2016-02-12 12:11:11 +01:00
|
|
|
if($this->tokenPost == NULL) $this->tokenClass->genImageToken();
|
|
|
|
$opt = $this->tokenClass->getOptions($service);
|
|
|
|
return $this->openstack->imagesV2($opt);
|
2016-02-10 18:09:44 +01:00
|
|
|
break;
|
2016-02-05 00:07:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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){
|
|
|
|
var_dump($e);
|
|
|
|
}catch(UserInputError $e){
|
|
|
|
var_dump($e);
|
|
|
|
}catch(BaseError $e){
|
|
|
|
var_dump($e);
|
2016-02-05 00:07:31 +01:00
|
|
|
exit();
|
2016-02-12 12:45:00 +01:00
|
|
|
}catch(NotImplementedError $e){
|
|
|
|
var_dump($e);
|
2016-02-05 00:07:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-12 12:45:00 +01:00
|
|
|
public function getPostParam($name){
|
|
|
|
|
|
|
|
return $this->postParams[$name];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-05 00:07:31 +01:00
|
|
|
public function setOutput($key, $out){
|
|
|
|
|
|
|
|
$this->output[$key] = $out;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-12 12:45:00 +01:00
|
|
|
public function getErrorInstance(){
|
|
|
|
|
|
|
|
return $this->errorClass;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-05 00:07:31 +01:00
|
|
|
public function show(){
|
|
|
|
echo json_encode($this->output);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|