Add Init and AppClass to do tests, Error Correction in App.php
This commit is contained in:
parent
ad33435ce0
commit
af451ad442
3 changed files with 106 additions and 5 deletions
73
server/Test/AppTestClass.php
Executable file
73
server/Test/AppTestClass.php
Executable file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
include_once("../core/Plugin_Api.php");
|
||||
include_once("../core/LibOverride/genTokenOptions.php");
|
||||
|
||||
class AppTest{
|
||||
|
||||
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($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(Exception $e){
|
||||
echo $e;
|
||||
exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function setOutput($key, $out){
|
||||
|
||||
$this->output[$key] = $out;
|
||||
|
||||
}
|
||||
|
||||
public function show(){
|
||||
echo json_encode($this->output);
|
||||
}
|
||||
|
||||
}
|
28
server/Test/InitTest.php
Executable file
28
server/Test/InitTest.php
Executable file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
include_once("../config.inc.php");
|
||||
include_once("AppTestClass.php");
|
||||
|
||||
$user = "demo";
|
||||
$password = "demopass";
|
||||
$project = "demo";
|
||||
|
||||
$Args = Array(
|
||||
"user" => Array(
|
||||
"name" => $user,
|
||||
"password" => $password,
|
||||
"domain" => Array(
|
||||
"name" => "Default")
|
||||
),
|
||||
"scope" => Array(
|
||||
"project" => Array(
|
||||
"name" => $project,
|
||||
"domain" => Array(
|
||||
"name" => "Default")
|
||||
)
|
||||
),
|
||||
"authUrl" => $config["urlAuth"]
|
||||
);
|
||||
|
||||
$App = new AppTest($Args);
|
||||
|
||||
?>
|
|
@ -31,14 +31,14 @@ class App{
|
|||
|
||||
switch($service){
|
||||
case "Identity":
|
||||
if($tokenPost == NULL) $tokenClass->genIdentityToken();
|
||||
$opt = $tokenClass->getOptions($service);
|
||||
if($this->tokenPost == NULL) $this->tokenClass->genIdentityToken();
|
||||
$opt = $this->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);
|
||||
if($this->tokenPost == NULL) $this->tokenClass->genImageToken();
|
||||
$opt = $this->tokenClass->getOptions($service);
|
||||
return $this->openstack->imagesV2($opt);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue