1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
<?php
use GuzzleHttp\Client;
use OpenStack\Common\Transport\HandlerStack;
use OpenStack\Common\Transport\Middleware;
use OpenStack\Identity\v3\Service;
use OpenStack\Common\Auth\Token;
use OpenStack\Common\Transport\Utils;
class genTokenOptions
{
private $optionsGlobal;
private $stack;
private $backup = [];
public function __construct($options){
echo "test";
$this->stack = HandlerStack::create();
$httpClient = new Client([
'base_uri' => Utils::normalizeUrl($options['authUrl']),
'handler' => $this->stack,
]);
$options['identityService'] = Service::factory($httpClient);
$options['authHandler'] = function () use ($options) {
return $options['identityService']->generateToken($options);
};
$this->optionsGlobal['Common'] = $options;
}
/**
* @codeCoverageIgnore
*/
private function addDebugMiddleware(array $options, HandlerStack &$stack)
{
if (!empty($options['debugLog'])
&& !empty($options['logger'])
&& !empty($options['messageFormatter'])
) {
$stack->push(GuzzleMiddleware::log($options['logger'], $options['messageFormatter']));
}
}
public function genComputeToken(){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'nova';
$options['catalogType'] = 'compute';
$options['region'] = 'RegionOne';
list($token, $baseUrl) = $options['identityService']->authenticate($options);
//var_dump($token);
//$stack = HandlerStack::create();
$this->stack->push(Middleware::authHandler($options['authHandler'], $token));
$this->addDebugMiddleware($options, $this->stack);
$options['httpClient'] = new Client([
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $this->stack,
]);
$this->backup['Compute'] = array('token' => json_encode($token), 'baseUrl' => $baseUrl );
serialize($token->methods);
foreach($token->roles as $role){
serialize($role->name);
serialize($role->links);
serialize($role->id);
}
serialize($token->expires);
serialize($token->project->domainId);
serialize($token->project->parentId);
serialize($token->project->enabled);
serialize($token->project->description);
serialize($token->project->id);
serialize($token->project->links);
serialize($token->project->name);
foreach($token->catalog->services as $service){
serialize($service->id);
serialize($service->name);
serialize($service->description);
serialize($service->type);
foreach($service->endpoints as $end){
serialize($end->id);
serialize($end->interface);
serialize($end->name);
serialize($end->serviceId);
serialize($end->region);
serialize($end->links);
serialize($end->url);
}
serialize($service->links);
}
serialize($token->extras);
serialize($token->user->domainId);
serialize($token->user->defaultProjectId);
serialize($token->user->id);
serialize($token->user->email);
serialize($token->user->enabled);
serialize($token->user->description);
serialize($token->user->links);
serialize($token->user->name);
serialize($token->issued);
serialize($token->id);
var_dump($token->id);
$this->optionsGlobal['Compute'] = $options;
}
public function loadComputeBackup($opt){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'nova';
$options['catalogType'] = 'compute';
$options['region'] = 'RegionOne';
//list($token, $baseUrl) = $options['identityService']->authenticate($options);
$this->backup['Compute'] = json_decode($opt, true);
var_dump($this->backup['Compute']);
$token = json_decode($this->backup['Compute']['token'], true);
$baseUrl = $this->backup['Compute']['baseUrl'];
//$stack = HandlerStack::create();
$this->stack->push(Middleware::authHandler($options['authHandler'], $token));
$this->addDebugMiddleware($options, $this->stack);
$options['httpClient'] = new Client([
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $this->stack,
]);
$this->backup['Compute'] = array('token' => json_encode($token), 'baseUrl' => $baseUrl );
$this->optionsGlobal['Compute'] = $options;
}
public function getBackup($service){
return json_encode($this->backup[$service]);
}
public function getOptionsCompute(){
return $this->optionsGlobal['Compute'];
}
}
|