istic-openstack/server/core/App.php

73 lines
1.5 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");
class App{
protected $openstack;
protected $pluginsApi;
protected $tokenClass;
protected $tokenPost;
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->output = array();
}
public function setToken($token){
$this->tokenPost = $token;
$this->tokenClass->loadBackup($his->tokenPost);
}
public function getLibClass($service){
switch($service){
case "Identity":
if($tokenPost == NULL) $tokenClass->genIdentityToken();
$opt = $tokenClass->getOptions($service);
return $this->openstack->identityV3($opt);
break;
case "Image":
if($tokenPost == NULL) $tokenClass->genImageToken();
$opt = $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(Exception $e){
echo $e;
exit();
}
}
public function setOutput($key, $out){
$this->output[$key] = $out;
}
public function show(){
echo json_encode($this->output);
}
}