1: <?php
2:
3: namespace Saklient\Cloud\Resources;
4:
5: require_once __DIR__ . "/../../../Saklient/Util.php";
6: use \Saklient\Util;
7: require_once __DIR__ . "/../../../Saklient/Cloud/Client.php";
8: use \Saklient\Cloud\Client;
9: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Script.php";
10: use \Saklient\Cloud\Resources\Script;
11: require_once __DIR__ . "/../../../Saklient/Errors/SaklientException.php";
12: use \Saklient\Errors\SaklientException;
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26: class DiskConfig {
27:
28: 29: 30: 31: 32: 33:
34: protected $_client;
35:
36: 37: 38: 39: 40:
41: protected function get_client()
42: {
43: return $this->_client;
44: }
45:
46:
47:
48: 49: 50: 51: 52: 53:
54: protected $_diskId;
55:
56: 57: 58: 59: 60:
61: protected function get_diskId()
62: {
63: return $this->_diskId;
64: }
65:
66:
67:
68: 69: 70: 71: 72: 73:
74: protected $_hostName;
75:
76: 77: 78: 79: 80:
81: protected function get_hostName()
82: {
83: return $this->_hostName;
84: }
85:
86: 87: 88: 89: 90: 91:
92: protected function set_hostName($v)
93: {
94: Util::validateArgCount(func_num_args(), 1);
95: Util::validateType($v, "string");
96: $this->_hostName = $v;
97: return $v;
98: }
99:
100:
101:
102: 103: 104: 105: 106: 107:
108: protected $_password;
109:
110: 111: 112: 113: 114:
115: protected function get_password()
116: {
117: return $this->_password;
118: }
119:
120: 121: 122: 123: 124: 125:
126: protected function set_password($v)
127: {
128: Util::validateArgCount(func_num_args(), 1);
129: Util::validateType($v, "string");
130: $this->_password = $v;
131: return $v;
132: }
133:
134:
135:
136: 137: 138: 139: 140: 141:
142: protected $_sshKeys;
143:
144: 145: 146: 147: 148:
149: protected function get_sshKeys()
150: {
151: return $this->_sshKeys;
152: }
153:
154: 155: 156: 157: 158:
159: protected function get_sshKey()
160: {
161: if ($this->_sshKeys->count() < 1) {
162: return null;
163: }
164: return $this->_sshKeys[0];
165: }
166:
167: 168: 169: 170: 171: 172:
173: protected function set_sshKey($v)
174: {
175: Util::validateArgCount(func_num_args(), 1);
176: Util::validateType($v, "string");
177: if ($this->_sshKeys->count() < 1) {
178: $this->_sshKeys->append($v);
179: }
180: else {
181: $this->_sshKeys[0] = $v;
182: }
183: return $v;
184: }
185:
186:
187:
188:
189:
190: 191: 192: 193: 194: 195:
196: protected $_ipAddress;
197:
198: 199: 200: 201: 202:
203: protected function get_ipAddress()
204: {
205: return $this->_ipAddress;
206: }
207:
208: 209: 210: 211: 212: 213:
214: protected function set_ipAddress($v)
215: {
216: Util::validateArgCount(func_num_args(), 1);
217: Util::validateType($v, "string");
218: $this->_ipAddress = $v;
219: return $v;
220: }
221:
222:
223:
224: 225: 226: 227: 228: 229:
230: protected $_defaultRoute;
231:
232: 233: 234: 235: 236:
237: protected function get_defaultRoute()
238: {
239: return $this->_defaultRoute;
240: }
241:
242: 243: 244: 245: 246: 247:
248: protected function set_defaultRoute($v)
249: {
250: Util::validateArgCount(func_num_args(), 1);
251: Util::validateType($v, "string");
252: $this->_defaultRoute = $v;
253: return $v;
254: }
255:
256:
257:
258: 259: 260: 261: 262: 263:
264: protected $_networkMaskLen;
265:
266: 267: 268: 269: 270:
271: protected function get_networkMaskLen()
272: {
273: return $this->_networkMaskLen;
274: }
275:
276: 277: 278: 279: 280: 281:
282: protected function set_networkMaskLen($v)
283: {
284: Util::validateArgCount(func_num_args(), 1);
285: Util::validateType($v, "int");
286: $this->_networkMaskLen = $v;
287: return $v;
288: }
289:
290:
291:
292: 293: 294: 295: 296: 297:
298: protected $_scripts;
299:
300: 301: 302: 303: 304:
305: protected function get_scripts()
306: {
307: return $this->_scripts;
308: }
309:
310:
311:
312: 313: 314: 315: 316: 317:
318: public function __construct(\Saklient\Cloud\Client $client, $diskId)
319: {
320: Util::validateArgCount(func_num_args(), 2);
321: Util::validateType($client, "\\Saklient\\Cloud\\Client");
322: Util::validateType($diskId, "string");
323: $this->_client = $client;
324: $this->_diskId = $diskId;
325: $this->_hostName = null;
326: $this->_password = null;
327: $this->_sshKeys = new \ArrayObject([]);
328: $this->_ipAddress = null;
329: $this->_defaultRoute = null;
330: $this->_networkMaskLen = null;
331: $this->_scripts = new \ArrayObject([]);
332: }
333:
334: 335: 336: 337: 338: 339: 340: 341: 342:
343: public function addScript(\Saklient\Cloud\Resources\Script $script)
344: {
345: Util::validateArgCount(func_num_args(), 1);
346: Util::validateType($script, "\\Saklient\\Cloud\\Resources\\Script");
347: $this->_scripts->append($script);
348: return $this;
349: }
350:
351: 352: 353: 354: 355: 356:
357: public function write()
358: {
359: $q = (object)[];
360: if ($this->_hostName != null) {
361: Util::setByPath($q, "HostName", $this->_hostName);
362: }
363: if ($this->_password != null) {
364: Util::setByPath($q, "Password", $this->_password);
365: }
366: if ($this->_sshKeys->count() > 0) {
367: Util::setByPath($q, "SSHKey.PublicKey", implode("\n", (array)($this->_sshKeys)));
368: }
369: if ($this->_ipAddress != null) {
370: Util::setByPath($q, "UserIPAddress", $this->_ipAddress);
371: }
372: if ($this->_defaultRoute != null) {
373: Util::setByPath($q, "UserSubnet.DefaultRoute", $this->_defaultRoute);
374: }
375: if ($this->_networkMaskLen != null) {
376: Util::setByPath($q, "UserSubnet.NetworkMaskLen", $this->_networkMaskLen);
377: }
378: if (0 < $this->_scripts->count()) {
379: $notes = new \ArrayObject([]);
380: foreach ($this->_scripts as $script) {
381: $notes->append((object)['ID' => $script->_id()]);
382: }
383: Util::setByPath($q, "Notes", $notes);
384: }
385: $path = "/disk/" . $this->_diskId . "/config";
386: $this->_client->request("PUT", $path, $q);
387: return $this;
388: }
389:
390: 391: 392:
393: public function __get($key) {
394: switch ($key) {
395: case "client": return $this->get_client();
396: case "diskId": return $this->get_diskId();
397: case "hostName": return $this->get_hostName();
398: case "password": return $this->get_password();
399: case "sshKey": return $this->get_sshKey();
400: case "sshKeys": return $this->get_sshKeys();
401: case "ipAddress": return $this->get_ipAddress();
402: case "defaultRoute": return $this->get_defaultRoute();
403: case "networkMaskLen": return $this->get_networkMaskLen();
404: case "scripts": return $this->get_scripts();
405: default: return null;
406: }
407: }
408:
409: 410: 411:
412: public function __set($key, $v) {
413: switch ($key) {
414: case "hostName": return $this->set_hostName($v);
415: case "password": return $this->set_password($v);
416: case "sshKey": return $this->set_sshKey($v);
417: case "ipAddress": return $this->set_ipAddress($v);
418: case "defaultRoute": return $this->set_defaultRoute($v);
419: case "networkMaskLen": return $this->set_networkMaskLen($v);
420: default: throw new SaklientException('non_writable_field', 'Non-writable field: Saklient\\Cloud\\Resources\\DiskConfig#'.$key);
421: }
422: }
423:
424: }
425:
426: