-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathAction.php
More file actions
153 lines (134 loc) · 3.28 KB
/
Action.php
File metadata and controls
153 lines (134 loc) · 3.28 KB
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
147
148
149
150
151
152
153
<?php
namespace LKDev\HetznerCloud\Models\Actions;
use LKDev\HetznerCloud\HetznerAPIClient;
use LKDev\HetznerCloud\Models\Contracts\Resource;
use LKDev\HetznerCloud\Models\Model;
class Action extends Model implements Resource
{
/**
* @var int
*/
public $id;
/**
* @var string
*/
public $command;
/**
* @var string
*/
public $status;
/**
* @var int
*/
public $progress;
/**
* @var string|null
*/
public $started;
/**
* @var string|null
*/
public $finished;
/**
* @var array
*/
public $resources;
/**
* @var |null
*/
public $error;
/**
* Action constructor.
*
* @param int $id
* @param string $command
* @param int $progress
* @param string $status
* @param string $started
* @param string $finished
* @param array $resources
* @param null| $error
* @param string|null $root_password
* @param string|null $wss_url
*/
public function __construct(
int $id,
string $command,
int $progress,
string $status,
?string $started = null,
?string $finished = null,
$resources = null,
$error = null
) {
$this->id = $id;
$this->command = $command;
$this->progress = $progress;
$this->status = $status;
$this->started = $started;
$this->finished = $finished;
$this->resources = $resources;
$this->error = $error;
parent::__construct();
}
/**
* @param $actionId
* @return Action|null
*
* @throws \LKDev\HetznerCloud\APIException
*
* @deprecated use Actions::getById instead
*/
public function getById($actionId): ?self
{
$response = $this->httpClient->get('actions/'.$actionId);
if (! HetznerAPIClient::hasError($response)) {
return self::parse(json_decode((string) $response->getBody())->action);
}
return null;
}
/**
* @return Action
*
* @throws \LKDev\HetznerCloud\APIException
*/
public function refresh(): self
{
return $this->reload();
}
/**
* Wait for an action to complete.
*
* @param float $pollingInterval seconds
* @return bool
*
* @throws \LKDev\HetznerCloud\APIException
*/
public function waitUntilCompleted($pollingInterval = 0.5)
{
return Actions::waitActionCompleted($this, $pollingInterval);
}
public function reload()
{
return HetznerAPIClient::$instance->actions()->getById($this->id);
}
public function delete()
{
throw new \BadMethodCallException('delete on action is not possible');
}
public function update(array $data)
{
throw new \BadMethodCallException('update on action is not possible');
}
/**
* @param $input
* @return \LKDev\HetznerCloud\Models\Actions\Action|static
*/
public static function parse($input)
{
if ($input == null) {
return;
}
return new self($input->id, $input->command, $input->progress, $input->status, $input->started ?? null, $input->finished ?? null, $input->resources, $input->error ?? null);
}
}