diff --git a/server/core/LibOverride/Test.php b/server/core/LibOverride/Test.php index 4e8e540..5babc35 100755 --- a/server/core/LibOverride/Test.php +++ b/server/core/LibOverride/Test.php @@ -12,15 +12,16 @@ class genTokenOptions private $optionsGlobal; private $stack; + private $backup = []; public function __construct($options){ echo "test"; $this->stack = HandlerStack::create(); - $httpClient['Common'] = new Client([ + $httpClient = new Client([ 'base_uri' => Utils::normalizeUrl($options['authUrl']), - 'handler' => $stack, + 'handler' => $this->stack, ]); $options['identityService'] = Service::factory($httpClient); @@ -45,27 +46,57 @@ class genTokenOptions } } - public genComputeToken(){ + 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($options['authUrl']), - 'handler' => $stack, + 'base_uri' => Utils::normalizeUrl($baseUrl), + 'handler' => $this->stack, ]); - + $this->backup['Compute'] = array('token' => serialize($token), 'baseUrl' => $baseUrl ); $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'] = unserialize($opt); + $token = unserialize($this->backup['Compute'] ['token']); + $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' => serialize($token), 'baseUrl' => $baseUrl ); + $this->optionsGlobal['Compute'] = $options; + } + + public function getBackup($service){ + return serialize($this->backup[$service]); + } + public function getOptionsCompute(){ return $this->optionsGlobal['Compute']; } diff --git a/server/index.php b/server/index.php index 23c99a1..b5424da 100755 --- a/server/index.php +++ b/server/index.php @@ -13,5 +13,18 @@ $compute = $openstack_api->computeV2($array); $servers = $compute->listServers(true); var_dump($servers); + foreach($servers as $server){ + echo $server->id." !!!!!!!!! "; + } + $tmp = new genTokenOptions($Args); + $tmp->loadComputeBackup($computBack); + $array = $tmp->getOptionsCompute(); + + $openstackTest = new OpenStack\OpenStack([]); + $computeTest = $openstackTest->computeV2($array); + $serversTest = $computeTest->listServers(true); + foreach($serversTest as $server){ + echo $server->id." %%%%%% "; + } // var_dump($openstack_api->getBuilderOptions()); diff --git a/server/init.php b/server/init.php index a7989ce..3c5f848 100755 --- a/server/init.php +++ b/server/init.php @@ -66,6 +66,9 @@ $tmp = new genTokenOptions($Args); $tmp->genComputeToken(); $array = $tmp->getOptionsCompute(); - $openstack_api = new OpenStack\OpenStack(new array()); - + $openstack_api = new OpenStack\OpenStack([]); + + $computBack = $tmp->getBackup("Compute"); + //file_put_contents("token", serialize($tmp)); + ?>