1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tylercd100\Rebooter\Api; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
6
|
|
|
use Tylercd100\Rebooter\ApiRebooter; |
7
|
|
|
|
8
|
|
|
class LinodeRebooter extends ApiRebooter { |
9
|
|
|
|
10
|
|
|
protected $token; |
11
|
|
|
protected $linodeId; |
12
|
|
|
protected $host; |
13
|
|
|
protected $client; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @param string $token API Token from Linode.com |
17
|
|
|
* @param [type] $linodeId The ID of the linode you want to control |
|
|
|
|
18
|
|
|
* @param string $host The api host |
19
|
|
|
* @param Client $client The guzzle client to use |
20
|
|
|
*/ |
21
|
3 |
|
public function __construct($token, $linodeId, $host = "api.linode.com", Client $client = null){ |
22
|
|
|
|
23
|
3 |
|
if(!$client instanceof Client){ |
24
|
3 |
|
$client = new Client(); |
25
|
3 |
|
} |
26
|
|
|
|
27
|
3 |
|
$this->client = $client; |
28
|
3 |
|
$this->token = $token; |
29
|
3 |
|
$this->linodeId = $linodeId; |
30
|
3 |
|
$this->host = $host; |
31
|
3 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Executes a Boot command |
35
|
|
|
* @return GuzzleHttp\Psr7\Response |
36
|
|
|
*/ |
37
|
|
|
public function boot(){ |
38
|
|
|
return $this->exec("linode.boot"); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Executes a Reboot command |
43
|
|
|
* @return GuzzleHttp\Psr7\Response |
44
|
|
|
*/ |
45
|
|
|
public function reboot(){ |
46
|
|
|
return $this->exec("linode.reboot"); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Executes a Shutdown command |
51
|
|
|
* @return GuzzleHttp\Psr7\Response |
52
|
|
|
*/ |
53
|
|
|
public function shutdown(){ |
54
|
|
|
return $this->exec("linode.shutdown"); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Builds the request URL for the API call |
59
|
|
|
* @param string $action The Linode API action |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
protected function buildRequestUrl($action){ |
63
|
|
|
return "https://{$this->host}/?api_key={$this->token}&api_action={$action}&LinodeID={$this->linodeId}"; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Executes a command on the API |
68
|
|
|
* @return GuzzleHttp\Psr7\Response |
69
|
|
|
*/ |
70
|
|
|
protected function exec($action){ |
71
|
|
|
$url = $this->buildRequestUrl($action); |
72
|
|
|
return $res = $this->client->request('GET', $url); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
} |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.