1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace FNDEV\vShpare\Api\VM; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use FNDEV\vShpare\Api\VM\ConsoleTickets\ConsoleTickets; |
8
|
|
|
use FNDEV\vShpare\Api\VM\GuestPower\GuestPower; |
9
|
|
|
use FNDEV\vShpare\Api\VM\Hardware\Hardware; |
10
|
|
|
use FNDEV\vShpare\Api\VM\Power\Power; |
11
|
|
|
use FNDEV\vShpare\Api\VM\Tools\Tools; |
12
|
|
|
use FNDEV\vShpare\ApiResponse; |
13
|
|
|
use GuzzleHttp\Client; |
14
|
|
|
use GuzzleHttp\Psr7\Response; |
15
|
|
|
|
16
|
|
|
class VmSource |
17
|
|
|
{ |
18
|
|
|
public Client $HttpClient; |
19
|
|
|
public $properties; |
20
|
|
|
public $moid; |
21
|
|
|
const POWERED_ON="POWERED_ON"; |
22
|
|
|
const POWERED_OFF="POWERED_OFF"; |
23
|
|
|
const SUSPENDED="SUSPENDED"; |
24
|
|
|
public function __construct(Client $HttpClient,$properties,$moid) |
25
|
|
|
{ |
26
|
|
|
$this->HttpClient=$HttpClient; |
27
|
|
|
$this->properties=isset($properties->value) ? $properties->value : $properties; |
28
|
|
|
$this->moid=$moid; |
29
|
|
|
} |
30
|
|
|
public function __get($name) |
31
|
|
|
{ |
32
|
|
|
return $this->properties->{$name}; |
33
|
|
|
} |
34
|
|
|
public function reloadProperties(){ |
35
|
|
|
$this->properties=ApiResponse::BodyResponse($this->HttpClient->get("vm/{$this->moid}"))->value; |
36
|
|
|
return $this; |
37
|
|
|
} |
38
|
|
|
public function power(){ |
39
|
|
|
return new Power($this->HttpClient,$this); |
40
|
|
|
} |
41
|
|
|
public function guestPower(){ |
42
|
|
|
return new GuestPower($this->HttpClient,$this); |
43
|
|
|
} |
44
|
|
|
public function tools(){ |
45
|
|
|
return new Tools($this->HttpClient,$this); |
46
|
|
|
} |
47
|
|
|
public function consoleTicket(){ |
48
|
|
|
return new ConsoleTickets($this->HttpClient,$this); |
49
|
|
|
} |
50
|
|
|
public function hardware(){ |
51
|
|
|
return new Hardware($this->HttpClient,$this); |
52
|
|
|
} |
53
|
|
|
public function resources(){ |
54
|
|
|
return new Resources\Resources($this->HttpClient,$this); |
55
|
|
|
} |
56
|
|
|
public function isPoweredOn(){ |
57
|
|
|
return $this->properties->power_state==self::POWERED_ON; |
58
|
|
|
} |
59
|
|
|
public function isPoweredOff(){ |
60
|
|
|
return $this->properties->power_state==self::POWERED_OFF; |
61
|
|
|
} |
62
|
|
|
public function isSuspended(){ |
63
|
|
|
return $this->properties->power_state==self::SUSPENDED; |
64
|
|
|
} |
65
|
|
|
} |