summaryrefslogtreecommitdiff
path: root/server/core/App.php
diff options
context:
space:
mode:
authorroot <root@kabir-PC>2016-02-23 20:34:59 +0100
committerroot <root@kabir-PC>2016-02-23 20:34:59 +0100
commitd2f5ae5c83ef5bc41cf430ace79769459b4acbf8 (patch)
treeb48882db52687bdd64a398c7d1844d05dbc01343 /server/core/App.php
parent1eff9ee90bf26127463cae0ae2cb2e1951527591 (diff)
parentff1832adcfe10fadb6cbf738c874611f77f6dd43 (diff)
Merge branch 'develop' of https://github.com/manzerbredes/istic-openstack into othmane
Diffstat (limited to 'server/core/App.php')
-rw-r--r--server/core/App.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/server/core/App.php b/server/core/App.php
new file mode 100644
index 0000000..babb3d9
--- /dev/null
+++ b/server/core/App.php
@@ -0,0 +1,100 @@
+<?php
+include_once("core/Plugin_Api.php");
+include_once("core/LibOverride/genTokenOptions.php");
+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;
+ protected $postParams;
+ protected $tokenClass;
+ protected $tokenPost;
+ 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();
+ $this->errorClass = new errorManagement($this);
+ $this->output = array();
+ $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());
+ }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);
+ }
+
+ }
+
+ public function getPostParam($name){
+
+ return $this->postParams[$name];
+
+ }
+
+ public function setOutput($key, $out){
+
+ $this->output[$key] = $out;
+
+ }
+
+ public function getErrorInstance(){
+
+ return $this->errorClass;
+
+ }
+
+ public function show(){
+ echo json_encode($this->output);
+ }
+
+} \ No newline at end of file