1: <?php
2:
3: namespace Saklient\Cloud\Models;
4:
5: require_once __DIR__ . "/../../../Saklient/Cloud/Client.php";
6: use \Saklient\Cloud\Client;
7: require_once __DIR__ . "/../../../Saklient/Cloud/Models/Model.php";
8: use \Saklient\Cloud\Models\Model;
9: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Resource.php";
10: use \Saklient\Cloud\Resources\Resource;
11: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Server.php";
12: use \Saklient\Cloud\Resources\Server;
13: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/ServerPlan.php";
14: use \Saklient\Cloud\Resources\ServerPlan;
15: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/IsoImage.php";
16: use \Saklient\Cloud\Resources\IsoImage;
17: require_once __DIR__ . "/../../../Saklient/Cloud/Enums/EServerInstanceStatus.php";
18: use \Saklient\Cloud\Enums\EServerInstanceStatus;
19: require_once __DIR__ . "/../../../Saklient/Util.php";
20: use \Saklient\Util;
21: require_once __DIR__ . "/../../../Saklient/Errors/SaklientException.php";
22: use \Saklient\Errors\SaklientException;
23:
24:
25: class Model_Server extends Model {
26:
27: 28: 29: 30: 31: 32:
33: protected function _apiPath()
34: {
35: return "/server";
36: }
37:
38: 39: 40: 41: 42: 43:
44: protected function _rootKey()
45: {
46: return "Server";
47: }
48:
49: 50: 51: 52: 53: 54:
55: protected function _rootKeyM()
56: {
57: return "Servers";
58: }
59:
60: 61: 62: 63: 64: 65:
66: protected function _className()
67: {
68: return "Server";
69: }
70:
71: 72: 73: 74: 75: 76: 77: 78:
79: protected function _createResourceImpl($obj, $wrapped=false)
80: {
81: Util::validateArgCount(func_num_args(), 1);
82: Util::validateType($wrapped, "boolean");
83: return new Server($this->_client, $obj, $wrapped);
84: }
85:
86: 87: 88: 89: 90: 91: 92:
93: public function offset($offset)
94: {
95: Util::validateArgCount(func_num_args(), 1);
96: Util::validateType($offset, "int");
97: return $this->_offset($offset);
98: }
99:
100: 101: 102: 103: 104: 105: 106:
107: public function limit($count)
108: {
109: Util::validateArgCount(func_num_args(), 1);
110: Util::validateType($count, "int");
111: return $this->_limit($count);
112: }
113:
114: 115: 116: 117: 118: 119: 120: 121: 122:
123: public function filterBy($key, $value, $multiple=false)
124: {
125: Util::validateArgCount(func_num_args(), 2);
126: Util::validateType($key, "string");
127: Util::validateType($multiple, "boolean");
128: return $this->_filterBy($key, $value, $multiple);
129: }
130:
131: 132: 133: 134: 135: 136:
137: public function reset()
138: {
139: return $this->_reset();
140: }
141:
142: 143: 144: 145: 146: 147: 148: 149:
150: public function create()
151: {
152: return $this->_create();
153: }
154:
155: 156: 157: 158: 159: 160: 161:
162: public function getById($id)
163: {
164: Util::validateArgCount(func_num_args(), 1);
165: Util::validateType($id, "string");
166: return $this->_getById($id);
167: }
168:
169: 170: 171: 172: 173: 174:
175: public function find()
176: {
177: return $this->_find();
178: }
179:
180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190:
191: public function withNameLike($name)
192: {
193: Util::validateArgCount(func_num_args(), 1);
194: Util::validateType($name, "string");
195: return $this->_withNameLike($name);
196: }
197:
198: 199: 200: 201: 202: 203: 204: 205: 206: 207:
208: public function withTag($tag)
209: {
210: Util::validateArgCount(func_num_args(), 1);
211: Util::validateType($tag, "string");
212: return $this->_withTag($tag);
213: }
214:
215: 216: 217: 218: 219: 220: 221: 222:
223: public function withTags($tags)
224: {
225: Util::validateArgCount(func_num_args(), 1);
226: Util::validateType($tags, "\\ArrayObject");
227: return $this->_withTags($tags);
228: }
229:
230: 231: 232: 233: 234: 235: 236: 237:
238: public function withTagDnf($dnf)
239: {
240: Util::validateArgCount(func_num_args(), 1);
241: Util::validateType($dnf, "\\ArrayObject");
242: return $this->_withTagDnf($dnf);
243: }
244:
245: 246: 247: 248: 249: 250: 251: 252:
253: public function sortByName($reverse=false)
254: {
255: Util::validateType($reverse, "boolean");
256: return $this->_sortByName($reverse);
257: }
258:
259: 260: 261: 262: 263:
264: public function __construct(\Saklient\Cloud\Client $client)
265: {
266: parent::__construct($client);
267: Util::validateArgCount(func_num_args(), 1);
268: Util::validateType($client, "\\Saklient\\Cloud\\Client");
269: }
270:
271: 272: 273: 274: 275: 276: 277:
278: public function withPlan(\Saklient\Cloud\Resources\ServerPlan $plan)
279: {
280: Util::validateArgCount(func_num_args(), 1);
281: Util::validateType($plan, "\\Saklient\\Cloud\\Resources\\ServerPlan");
282: $this->_filterBy("ServerPlan.ID", new \ArrayObject([$plan->_id()]));
283: return $this;
284: }
285:
286: 287: 288: 289: 290: 291: 292:
293: public function withStatus($status)
294: {
295: Util::validateArgCount(func_num_args(), 1);
296: Util::validateType($status, "string");
297: $this->_filterBy("Instance.Status", new \ArrayObject([$status]));
298: return $this;
299: }
300:
301: 302: 303: 304: 305: 306:
307: public function withStatusUp()
308: {
309: return $this->withStatus(EServerInstanceStatus::up);
310: }
311:
312: 313: 314: 315: 316: 317:
318: public function withStatusDown()
319: {
320: return $this->withStatus(EServerInstanceStatus::down);
321: }
322:
323: 324: 325: 326: 327: 328: 329:
330: public function withIsoImage(\Saklient\Cloud\Resources\IsoImage $iso)
331: {
332: Util::validateArgCount(func_num_args(), 1);
333: Util::validateType($iso, "\\Saklient\\Cloud\\Resources\\IsoImage");
334: $this->_filterBy("Instance.CDROM.ID", new \ArrayObject([$iso->_id()]));
335: return $this;
336: }
337:
338: 339: 340: 341: 342: 343: 344:
345: public function sortByCpu($reverse=false)
346: {
347: Util::validateType($reverse, "boolean");
348: $this->_sort("ServerPlan.CPU", $reverse);
349: return $this;
350: }
351:
352: 353: 354: 355: 356: 357: 358:
359: public function sortByMemory($reverse=false)
360: {
361: Util::validateType($reverse, "boolean");
362: $this->_sort("ServerPlan.MemoryMB", $reverse);
363: return $this;
364: }
365:
366:
367:
368: }
369:
370: