Closed Vladdy88 closed 6 years ago
I modified the Servers::create method to
public static function create($config)
{
if(!is_a($config, Configs\Server::class))
throw new InvalidInput('config must be a ' . Configs\Server::class);
$config->verify();
$response = self::request('POST', '', $config->toArray());
$serialized_response = $response->jsonSerialize();
$status = $serialized_response->action->status;
$progress = $serialized_response->action->progress;
$action_id = $serialized_response->action->id;
while ($progress != 100 && $status != 'success') {
$actionResponse = \Exploriment\HetznerCloud\Actions::find($action_id);
$progress = $actionResponse->progress;
$status = $actionResponse->status;
sleep(1);
}
return new ServerCreation($serialized_response);
}
and in this way I can get at the end of the creation API the desired details. But maybe there is a better way.
Pushed out an update, response should no longer be empty. Sorry about that! The action doesn't have to be completed for you to get your server information.
Let me know if it still doesn't work for you.
Yes, now it is ok. Thanks a lot. Great work!
I have tested the script and I found I little problem with it. When I use the
$creation = HetznerCloud\Servers::create($config);
it returns an object with null members like in the example bellow :I saw that the response is returned after the command is given, and the action is still in progress. It should be modified to wait until the action is finished and send the response only after that. Otherwise I have to use after the creation the command to get the server details, but it`s not the best way in my opinion.