88
99namespace LKDev \HetznerCloud \Models \Images ;
1010
11- class Image
11+ use LKDev \HetznerCloud \HetznerAPIClient ;
12+ use LKDev \HetznerCloud \Models \Model ;
13+ use LKDev \HetznerCloud \Models \Servers \Server ;
14+
15+ /**
16+ *
17+ */
18+ class Image extends Model
1219{
20+ /**
21+ * @var int
22+ */
23+ public $ id ;
24+
25+ /**
26+ * @var string
27+ */
28+ public $ type ;
29+
30+ /**
31+ * @var string
32+ */
33+ public $ status ;
34+
35+ /**
36+ * @var string
37+ */
38+ public $ name ;
39+
40+ /**
41+ * @var string
42+ */
43+ public $ description ;
44+
45+ /**
46+ * @var float
47+ */
48+ public $ imageSize ;
49+
50+ /**
51+ * @var integer
52+ */
53+ public $ diskSize ;
54+
55+ /**
56+ * @var string
57+ */
58+ public $ created ;
59+
60+ /**
61+ * @var \LKDev\HetznerCloud\Models\Servers\Server
62+ */
63+ public $ createdFrom ;
64+
65+ /**
66+ * @var int
67+ */
68+ public $ boundTo ;
69+
70+ /**
71+ * @var string
72+ */
73+ public $ osFlavor ;
74+
75+ /**
76+ * @var string
77+ */
78+ public $ osVersion ;
79+
80+ /**
81+ * @var bool
82+ */
83+ public $ rapidDeploy ;
84+
85+ /**
86+ * Image constructor.
87+ *
88+ * @param int $id
89+ * @param string $type
90+ * @param string $status
91+ * @param string $name
92+ * @param string $description
93+ * @param float $imageSize
94+ * @param int $diskSize
95+ * @param string $created
96+ * @param \LKDev\HetznerCloud\Models\Servers\Server $createdFrom
97+ * @param int $boundTo
98+ * @param string $osFlavor
99+ * @param string $osVersion
100+ * @param bool $rapidDeploy
101+ */
102+ public function __construct (
103+ int $ id ,
104+ string $ type ,
105+ string $ status ,
106+ string $ name ,
107+ string $ description ,
108+ float $ imageSize ,
109+ int $ diskSize ,
110+ string $ created ,
111+ Server $ createdFrom ,
112+ int $ boundTo ,
113+ string $ osFlavor ,
114+ string $ osVersion ,
115+ bool $ rapidDeploy
116+ ) {
117+ $ this ->id = $ id ;
118+ $ this ->type = $ type ;
119+ $ this ->status = $ status ;
120+ $ this ->name = $ name ;
121+ $ this ->description = $ description ;
122+ $ this ->imageSize = $ imageSize ;
123+ $ this ->diskSize = $ diskSize ;
124+ $ this ->created = $ created ;
125+ $ this ->createdFrom = $ createdFrom ;
126+ $ this ->boundTo = $ boundTo ;
127+ $ this ->osFlavor = $ osFlavor ;
128+ $ this ->osVersion = $ osVersion ;
129+ $ this ->rapidDeploy = $ rapidDeploy ;
130+ parent ::__construct ();
131+ }
132+
133+ /**
134+ * Updates the Image. You may change the description or convert a Backup image to a Snapshot Image. Only images of type snapshot and backup can be updated.
135+ *
136+ * @see https://docs.hetzner.cloud/#resources-images-put
137+ * @param string $description
138+ * @param string $type
139+ * @return \LKDev\HetznerCloud\Models\Images\Image
140+ * @throws \LKDev\HetznerCloud\APIException
141+ */
142+ public function update (string $ description , string $ type ): Image
143+ {
144+ $ response = $ this ->httpClient ->put ('images/ ' .$ this ->id , [
145+ 'json ' => [
146+ 'description ' => $ description ,
147+ 'type ' => $ type ,
148+ ],
149+ ]);
150+ if (! HetznerAPIClient::hasError ($ response )) {
151+ return self ::parse (json_decode ((string ) $ response ->getBody ())->image );
152+ }
153+ }
154+
155+ /**
156+ * Deletes an Image. Only images of type snapshot and backup can be deleted.
157+ *
158+ * @see https://docs.hetzner.cloud/#resources-images-delete
159+ * @return bool
160+ * @throws \LKDev\HetznerCloud\APIException
161+ */
162+ public function delete (): bool
163+ {
164+ $ response = $ this ->httpClient ->delete ('images/ ' .$ this ->id );
165+ if (! HetznerAPIClient::hasError ($ response )) {
166+ return true ;
167+ }
168+ }
169+
170+ /**
171+ * @param object $input
172+ * @return \LKDev\HetznerCloud\Models\Images\Image|static
173+ */
174+ public static function parse (object $ input )
175+ {
176+ return new self ($ input ->id , $ input ->type , $ input ->status , $ input ->name , $ input ->description , $ input ->image_size , $ input ->disk_size , $ input ->created , Server::parse ($ input ->created_from ), $ input ->bound_to , $ input ->os_flavor , $ input ->os_version , $ input ->rapid_deploy );
177+ }
13178}
0 commit comments