Suite Test Token Management

This commit is contained in:
root 2016-01-31 03:24:02 +01:00
parent de1f302047
commit 7276d3f033
3 changed files with 38 additions and 37 deletions

View file

@ -10,47 +10,26 @@ use OpenStack\Common\Transport\Utils;
class genTokenOptions
{
private $optionsGlobal;
private $stack;
public function __construct($options, $token){
public function __construct($options){
echo "test";
$stack = HandlerStack::create();
//IdentityService?
// $options['IdentityService'] pas oblige?...
// creer HttpClient authurl HandlerStack::create()
// $option['identityService'] = factory httpClient
//$httpClient = new Client([
// 'base_uri' => Utils::normalizeUrl($options['authUrl']),
// 'handler' => HandlerStack::create(),
//]);
$this->stack = HandlerStack::create();
$httpClient = new Client([
$httpClient['Common'] = new Client([
'base_uri' => Utils::normalizeUrl($options['authUrl']),
'handler' => $stack,
]);
$options['identityService'] = Service::factory($httpClient);
//AuthHadler?
//
$options['authHandler'] = function () use ($options) {
return $options['identityService']->generateToken($options);
};
//StockClient?
// creer $options['httpClient'] instance de ClientInterface
// token, baseUrl = identity->authenticate
// stack = getStack authhandler token
// addDebug??
// $options['httpClient'] = httpCLient baseurl stack
$baseUrl = $options['authUrl'];
//$stack = HandlerStack::create();
$stack->push(Middleware::authHandler($options['authHandler'], $token));
$this->addDebugMiddleware($options, $stack);
$options['httpClient'] = $httpClient;
$this->optionsGlobal = $options;
$this->optionsGlobal['Common'] = $options;
}
/**
@ -66,7 +45,28 @@ class genTokenOptions
}
}
public function getOptions(){
return $this->optionsGlobal;
public genComputeToken(){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'nova';
$options['catalogType'] = 'compute';
$options['region'] = 'RegionOne';
list($token, $baseUrl) = $options['identityService']->authenticate($options);
//$stack = HandlerStack::create();
$this->stack->push(Middleware::authHandler($options['authHandler'], $token));
$this->addDebugMiddleware($options, $this->stack);
$options['httpClient'] = new Client([
'base_uri' => Utils::normalizeUrl($options['authUrl']),
'handler' => $stack,
]);
$this->optionsGlobal['Compute'] = $options;
}
public function getOptionsCompute(){
return $this->optionsGlobal['Compute'];
}
}

View file

@ -10,7 +10,7 @@
//$id = new identity($openstack_api, $pluginApi);
// var_dump($id->genToken());
$compute = $openstack_api->computeV2(['region'=> 'RegionOne']);
$compute = $openstack_api->computeV2($array);
$servers = $compute->listServers(true);
var_dump($servers);

View file

@ -58,13 +58,14 @@
$pluginApi = plugin_api::getInstance();
$openstack_api = new OpenStack\OpenStack($Args);
$id = new identity($openstack_api, $pluginApi);
//$openstack_api = new OpenStack\OpenStack($Args);
//$id = new identity($openstack_api, $pluginApi);
$token = $id->genToken();
//$token = $id->genToken();
$tmp = new genTokenOptions($Args, $token);
$array = $tmp->getOptions();
$openstack_api = new OpenStack\OpenStack($array);
$tmp = new genTokenOptions($Args);
$tmp->genComputeToken();
$array = $tmp->getOptionsCompute();
$openstack_api = new OpenStack\OpenStack(new array());
?>