istic-openstack/server/core/App.php

101 lines
2.2 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");
use OpenStack\Common\Error\BadResponseError;
use OpenStack\Common\Error\BaseError;
use OpenStack\Common\Error\NotImplementedError;
use OpenStack\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($his->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;
}
}
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);
exit();
2016-02-12 12:45:00 +01:00
}catch(NotImplementedError $e){
var_dump($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);
}
}