istic-openstack/server/Test/AppTestClass.php

126 lines
3.2 KiB
PHP
Raw Permalink Normal View History

<?php
include_once("../core/LibOverride/genTokenOptions.php");
2016-03-09 16:16:22 +01:00
include_once("../core/ErrorManagement.php");
use OpenCloud\Common\Error\BadResponseError;
use OpenCloud\Common\Error\BaseError;
use OpenCloud\Common\Error\NotImplementedError;
use OpenCloud\Common\Error\UserInputError;
class AppTest{
protected $openstack;
2016-02-24 23:06:02 +01:00
protected $postParams;
protected $tokenClass;
protected $tokenPost;
protected $output;
2016-02-17 17:56:11 +01:00
protected $errorClass;
public function __construct($args){
$this->tokenPost = NULL;
$this->tokenClass = new genTokenOptions($args);
2016-03-23 15:44:06 +01:00
$this->openstack = new OpenStack\OpenStack(['authUrl' => $args["authUrl"]]);
2016-02-24 23:06:02 +01:00
$this->errorClass = new errorManagement($this);
$this->output = array();
2016-02-29 15:25:30 +01:00
2016-02-17 17:56:11 +01:00
$this->errorClass = new errorManagement($this);
2016-02-29 15:25:30 +01:00
2016-02-28 19:26:53 +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;
case "Compute":
if($this->tokenPost == NULL) $this->tokenClass->genComputeToken();
$opt = $this->tokenClass->getOptions($service);
return $this->openstack->computeV2($opt);
break;
2016-02-24 23:06:02 +01:00
case "Network":
if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken();
$opt = $this->tokenClass->getOptions($service);
return $this->openstack->networkingV2($opt);
break;
case "NetworkLayer3":
2016-04-19 18:00:37 +02:00
if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken();
2016-04-19 18:27:27 +02:00
$opt = $this->tokenClass->getOptions('Network');
2016-04-19 18:00:37 +02:00
return $this->openstack->networkingV2ExtLayer3($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-24 23:06:02 +01:00
}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){
if(isset($this->postParams[$name])){
return $this->postParams[$name];
}else{
$this->setOutput("Error", "Missing parameter ".$name);
}
}
public function setPostParam($name, $value){
$this->postParams[$name] = $value;
}
public function setOutput($key, $out){
$this->output[$key] = $out;
}
public function show(){
2016-02-28 19:26:53 +01:00
return json_encode($this->output);
}
2016-02-29 15:25:30 +01:00
2016-02-17 17:56:11 +01:00
public function getErrorInstance(){
return $this->errorClass;
}
2016-02-28 19:26:53 +01:00
}
2016-02-29 15:25:30 +01:00