|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ChrisArmitage\ScalewayApi\Endpoint; |
|
4
|
|
|
|
|
5
|
|
|
use ChrisArmitage\ScalewayApi\Client; |
|
6
|
|
|
use ChrisArmitage\ScalewayApi\Domain\Server; |
|
7
|
|
|
use ChrisArmitage\ScalewayApi\Domain\Task; |
|
8
|
|
|
use ChrisArmitage\ScalewayApi\WebService\Servers\WebServiceGateway; |
|
9
|
|
|
|
|
10
|
|
|
class Servers |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var Client |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $client; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var WebServiceGateway |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $gateway; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param WebServiceGateway $gateway |
|
24
|
|
|
*/ |
|
25
|
5 |
|
public function __construct(WebServiceGateway $gateway) { |
|
26
|
5 |
|
$this->gateway = $gateway; |
|
27
|
5 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @return Server[] |
|
31
|
|
|
* @throws \Exception |
|
32
|
|
|
*/ |
|
33
|
1 |
|
public function getAllServers() { |
|
34
|
1 |
|
$response = $this->gateway->getServers(); |
|
35
|
|
|
|
|
36
|
1 |
|
$collection = []; |
|
37
|
|
|
|
|
38
|
1 |
|
foreach ($response->servers as $server) { |
|
39
|
1 |
|
$collection[] = Server::makeFromServerJson($server); |
|
40
|
1 |
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
return $collection; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param $serverId |
|
47
|
|
|
* @return Server |
|
48
|
|
|
* @throws \Exception |
|
49
|
|
|
*/ |
|
50
|
1 |
|
public function getServer($serverId) { |
|
51
|
1 |
|
$response = $this->gateway->getServer($serverId); |
|
52
|
|
|
|
|
53
|
1 |
|
return Server::makeFromServerJson($response->server); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param $name |
|
58
|
|
|
* @param $organizationId |
|
59
|
|
|
* @param $imageId |
|
60
|
|
|
* @param $commercialType |
|
61
|
|
|
* @return Server |
|
62
|
|
|
* @throws \Exception |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public function createServer($name, $organizationId, $imageId, $commercialType) { |
|
65
|
1 |
|
$response = $this->gateway->createServer($name, $organizationId, $imageId, $commercialType); |
|
66
|
|
|
|
|
67
|
1 |
|
return Server::makeFromServerJson($response->server); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param $serverId |
|
72
|
|
|
* @return mixed |
|
73
|
|
|
* @throws \Exception |
|
74
|
|
|
*/ |
|
75
|
|
|
public function deleteServer($serverId) { |
|
76
|
|
|
$response = $this->gateway->deleteServer($serverId); |
|
77
|
|
|
|
|
78
|
|
|
return $response; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param $serverId |
|
83
|
|
|
* @param $action |
|
84
|
|
|
* @return Task |
|
85
|
|
|
* @throws \Exception |
|
86
|
|
|
*/ |
|
87
|
1 |
|
public function setAction($serverId, $action) { |
|
88
|
1 |
|
$response = $this->gateway->setAction($serverId, $action); |
|
89
|
|
|
|
|
90
|
1 |
|
return Task::makeFromTaskJson($response->task); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param $serverId |
|
95
|
|
|
* @param $key |
|
96
|
|
|
* @return string |
|
97
|
|
|
* @throws \ChrisArmitage\ScalewayApi\WebService\Servers\GeneralException |
|
98
|
|
|
*/ |
|
99
|
1 |
|
public function getUserData($serverId, $key) { |
|
100
|
1 |
|
$response = $this->gateway->getUserData($serverId, $key); |
|
101
|
|
|
|
|
102
|
1 |
|
return $response; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|