-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathServer.php
More file actions
768 lines (683 loc) · 25.1 KB
/
Server.php
File metadata and controls
768 lines (683 loc) · 25.1 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
<?php
/**
* Created by PhpStorm.
* User: lukaskammerling
* Date: 28.01.18
* Time: 20:58.
*/
namespace LKDev\HetznerCloud\Models\Servers;
use GuzzleHttp\Client;
use LKDev\HetznerCloud\APIResponse;
use LKDev\HetznerCloud\HetznerAPIClient;
use LKDev\HetznerCloud\Models\Actions\Action;
use LKDev\HetznerCloud\Models\Contracts\Resource;
use LKDev\HetznerCloud\Models\Datacenters\Datacenter;
use LKDev\HetznerCloud\Models\Images\Image;
use LKDev\HetznerCloud\Models\ISOs\ISO;
use LKDev\HetznerCloud\Models\Model;
use LKDev\HetznerCloud\Models\Networks\Network;
use LKDev\HetznerCloud\Models\Protection;
use LKDev\HetznerCloud\Models\Servers\Types\ServerType;
class Server extends Model implements Resource
{
/**
* @var int
*/
public $id;
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $status;
/**
* @var string
*/
public $created;
/**
* @var ServerPublicNet
*/
public $publicNet;
/**
* @var ServerPrivateNet[]
*/
public $privateNet;
/**
* @var ServerType
*/
public $serverType;
/**
* @var \LKDev\HetznerCloud\Models\Datacenters\Datacenter
*/
public $datacenter;
/**
* @var Image
*/
public $image;
/**
* @var ISO
*/
public $iso;
/**
* @var bool
*/
public $rescueEnabled;
/**
* @var bool
*/
public $locked;
/**
* @var string
*/
public $backupWindow;
/**
* @var int
*/
public $outgoingTraffic;
/**
* @var int
*/
public $ingoingTraffic;
/**
* @var int
*/
public $includedTraffic;
/**
* @var \LKDev\HetznerCloud\Models\Protection
*/
public $protection;
/**
* @var array
*/
public $labels;
/**
* @var array
*/
public $volumes;
/**
* @var int
*/
public $primaryDiskSize;
/**
* @param int $serverId
* @param Client|null $httpClient
*/
public function __construct(int $serverId, Client $httpClient = null)
{
$this->id = $serverId;
parent::__construct($httpClient);
}
/**
* @param $data
* @return \LKDev\HetznerCloud\Models\Servers\Server
*/
public function setAdditionalData($data)
{
$this->name = $data->name;
$this->status = $data->status ?: null;
$this->publicNet = property_exists($data, 'public_net') ? ServerPublicNet::parse($data->public_net) : null;
$this->privateNet = property_exists($data, 'private_net') ? $this->parsePrivateNet($data->private_net) : [];
$this->serverType = property_exists($data, 'server_type') ? ServerType::parse($data->server_type) : null;
$this->datacenter = property_exists($data, 'datacenter') ? Datacenter::parse($data->datacenter) : null;
$this->created = $data->created;
$this->image = property_exists($data, 'image') ? Image::parse($data->image) : null;
$this->iso = property_exists($data, 'iso') ? ISO::parse($data->iso) : null;
$this->rescueEnabled = $data->rescue_enabled ?: null;
$this->locked = $data->locked ?: null;
$this->backupWindow = $data->backup_window ?: null;
$this->outgoingTraffic = $data->outgoing_traffic ?: null;
$this->ingoingTraffic = $data->ingoing_traffic ?: null;
$this->includedTraffic = $data->included_traffic ?: null;
$this->volumes = property_exists($data, 'volumes') ? $data->volumes : [];
$this->labels = get_object_vars($data->labels);
$this->primaryDiskSize = $data->primary_disk_size ?: null;
return $this;
}
/**
* @param \stdClass[] $privateNets
* @return ServerPrivateNet[]
*/
protected function parsePrivateNet(array $privateNets)
{
$parsed = [];
foreach ($privateNets as $privateNet) {
$parsed[] = new ServerPrivateNet($privateNet->network, $privateNet->ip, $privateNet->alias_ips, $privateNet->mac_address);
}
return $parsed;
}
/**
* Reload the data of the server.
*
* @return Server
* @throws \LKDev\HetznerCloud\APIException
* @deprecated 2.0.0-alpha1 use reload() instead
*/
public function get()
{
return $this->reload();
}
/**
* Reload the data of the server.
*
* @return Server
* @throws \LKDev\HetznerCloud\APIException
*/
public function reload()
{
return HetznerAPIClient::$instance->servers()->get($this->id);
}
/**
* Starts a server by turning its power on.
*
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function powerOn(): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/poweron'));
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* Reboots a server gracefully by sending an ACPI request. The server operating system must support ACPI and react to the request, otherwise the server will not reboot.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-1
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function softReboot(): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/reboot'));
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* Cuts power to a server and starts it again. This forcefully stops it without giving the server operating system time to gracefully stop. This may lead to data loss, it’s equivalent to pulling the power cord and plugging it in again. Reset should only be used when reboot does not work.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-2
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function reset(): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/reset'));
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* Shuts down a server gracefully by sending an ACPI shutdown request. The server operating system must support ACPI and react to the request, otherwise the server will not shut down.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-3
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function shutdown(): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/shutdown'));
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* Cuts power to the server. This forcefully stops it without giving the server operating system time to gracefully stop. May lead to data loss, equivalent to pulling the power cord. Power off should only be used when shutdown does not work.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-4
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function powerOff(): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/poweroff'));
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* Resets the root password. Only works for Linux systems that are running the qemu guest agent. Server must be powered on (state on) in order for this operation to succeed.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-5
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function resetRootPassword(): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/reset_password'));
if (! HetznerAPIClient::hasError($response)) {
$payload = json_decode((string) $response->getBody());
return APIResponse::create([
'action' => Action::parse($payload->action),
'root_password' => $payload->root_password,
], $response->getHeaders());
}
return null;
}
/**
* Enable the Hetzner Rescue System for this server. The next time a Server with enabled rescue mode boots it will start a special minimal Linux distribution designed for repair and reinstall.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-6
* @param string $type
* @param array $ssh_keys
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function enableRescue($type = 'linux64', $ssh_keys = []): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/enable_rescue'), [
'json' => [
'type' => $type,
'ssh_keys' => $ssh_keys,
],
]);
if (! HetznerAPIClient::hasError($response)) {
$payload = json_decode((string) $response->getBody());
return APIResponse::create([
'action' => Action::parse($payload->action),
'root_password' => $payload->root_password,
], $response->getHeaders());
}
return null;
}
/**
* Disables the Hetzner Rescue System for a server. This makes a server start from its disks on next reboot.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-7
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function disableRescue(): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/disable_rescue'));
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* Creates an image (snapshot) from a server by copying the contents of its disks. This creates a snapshot of the current state of the disk and copies it into an image. If the server is currently running you must make sure that its disk content is consistent. Otherwise, the created image may not be readable.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-8
* @param string $description
* @param string $type
* @param array $labels
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function createImage(string $description = '', string $type = 'snapshot', array $labels = []): ?APIResponse
{
$payload = [
'description' => $description,
'type' => $type,
];
if (! empty($labels)) {
$payload['labels'] = $labels;
}
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/create_image'), [
'json' => $payload,
]);
if (! HetznerAPIClient::hasError($response)) {
$payload = json_decode((string) $response->getBody());
return APIResponse::create([
'action' => Action::parse($payload->action),
'image' => Image::parse($payload->image),
], $response->getHeaders());
}
return null;
}
/**
* Rebuilds a server overwriting its disk with the content of an image, thereby destroying all data on the target server.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-9
* @param \LKDev\HetznerCloud\Models\Images\Image $image
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function rebuildFromImage(Image $image): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/rebuild'), [
'json' => [
'image' => $image->id ?: $image->name,
],
]);
if (! HetznerAPIClient::hasError($response)) {
$payload = json_decode((string) $response->getBody());
return APIResponse::create(array_merge([
'action' => Action::parse($payload->action),
], (property_exists($payload, 'root_password')) ? ['root_password' => $payload->root_password] : []), $response->getHeaders());
}
return null;
}
/**
* Changes the type (Cores, RAM and disk sizes) of a server.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-10
* @param \LKDev\HetznerCloud\Models\Servers\Types\ServerType $serverType
* @param bool $upgradeDisk
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function changeType(ServerType $serverType, bool $upgradeDisk = false): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/change_type'), [
'json' => [
'server_type' => $serverType->name,
'upgrade_disk' => $upgradeDisk,
],
]);
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* Enables and configures the automatic daily backup option for the server. Enabling automatic backups will increase the price of the server by 20%.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-11
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function enableBackups(string $backupWindow = null): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/enable_backup'));
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* Disables the automatic backup option and deletes all existing Backups for a Server.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-12
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function disableBackups(): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/disable_backup'));
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* Attaches an ISO to a server. The Server will immediately see it as a new disk. An already attached ISO will automatically be detached before the new ISO is attached.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-13
* @param \LKDev\HetznerCloud\Models\ISOs\ISO $iso
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function attachISO(ISO $iso): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/attach_iso'), [
'json' => [
'iso' => $iso->name ?: $iso->id,
],
]);
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* Detaches an ISO from a server. In case no ISO image is attached to the server, the status of the returned action is immediately set to success.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-14
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function detachISO(): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/detach_iso'));
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* Changes the hostname that will appear when getting the hostname belonging to the primary IPs (ipv4 and ipv6) of this server.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-15
* @param string $ip
* @param string $dnsPtr
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function changeReverseDNS(string $ip, string $dnsPtr): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/change_dns_ptr'), [
'json' => [
'ip' => $ip,
'dns_ptr' => $dnsPtr,
],
]);
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* Get Metrics for specified server.
*
* @see https://docs.hetzner.cloud/#servers-get-metrics-for-a-server
* @param string $type
* @param string $start
* @param string $end
* @param int|null $step
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function metrics(string $type, string $start, string $end, int $step = null)
{
$response = $this->httpClient->get($this->replaceServerIdInUri('servers/{id}/metrics?').http_build_query(compact('type', 'start', 'end', 'step')));
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'metrics' => json_decode((string) $response->getBody())->metrics,
], $response->getHeaders());
}
return null;
}
/**
* Deletes a server. This immediately removes the server from your account, and it is no longer accessible.
*
* @see https://docs.hetzner.cloud/#resources-servers-delete
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function delete(): ?APIResponse
{
$response = $this->httpClient->delete($this->replaceServerIdInUri('servers/{id}'));
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* Update a server with new meta data.
*
* @see https://docs.hetzner.cloud/#resources-servers-put
* @param array $data
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function update(array $data)
{
$response = $this->httpClient->put($this->replaceServerIdInUri('servers/{id}'), [
'json' => $data,
]);
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'server' => self::parse(json_decode((string) $response->getBody())->server),
], $response->getHeaders());
}
return null;
}
/**
* Requests credentials for remote access via vnc over websocket to keyboard, monitor, and mouse for a server.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-16
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function requestConsole(): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/request_console'));
if (! HetznerAPIClient::hasError($response)) {
$payload = json_decode((string) $response->getBody());
return APIResponse::create([
'action' => Action::parse($payload->action),
'wss_url' => $payload->wss_url,
'password' => $payload->password,
], $response->getHeaders());
}
return null;
}
/**
* Changes the protection configuration of the server.
*
* @see https://docs.hetzner.cloud/#resources-server-actions-post-16
* @param bool $delete
* @param bool $rebuild
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function changeProtection(bool $delete = true, bool $rebuild = true): ?APIResponse
{
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/change_protection'), [
'json' => [
'delete' => $delete,
'rebuild' => $rebuild,
],
]);
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* @param Network $network
* @param string|null $ip
* @param array $aliasIps
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function attachToNetwork(Network $network, string $ip = null, array $aliasIps = [])
{
$payload = [
'network' => $network->id,
];
if ($ip != null) {
$payload['ip'] = $ip;
}
if ($ip != null) {
$payload['alias_ips'] = $aliasIps;
}
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/attach_to_network'), [
'json' => $payload,
]);
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* @param Network $network
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function detachFromNetwork(Network $network)
{
$payload = [
'network' => $network->id,
];
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/detach_from_network'), [
'json' => $payload,
]);
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* @param Network $network
* @param array $aliasIps
* @return APIResponse|null
* @throws \LKDev\HetznerCloud\APIException
*/
public function changeAliasIPs(Network $network, array $aliasIps)
{
$payload = [
'network' => $network->id,
'alias_ips' => $aliasIps,
];
$response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/change_alias_ips'), [
'json' => $payload,
]);
if (! HetznerAPIClient::hasError($response)) {
return APIResponse::create([
'action' => Action::parse(json_decode((string) $response->getBody())->action),
], $response->getHeaders());
}
return null;
}
/**
* @param string $uri
* @return string
*/
protected function replaceServerIdInUri(string $uri): string
{
return str_replace('{id}', $this->id, $uri);
}
/**
* @param $input
* @return \LKDev\HetznerCloud\Models\Servers\Server|static |null
*/
public static function parse($input)
{
if ($input == null) {
return null;
}
return (new self($input->id))->setAdditionalData($input);
}
}