├── .gitignore
├── README.md
├── composer.json
├── composer.lock
├── phpunit.xml
├── src
└── Sircamp
│ └── Xenapi
│ ├── Connection
│ ├── XenConnection.php
│ ├── XenResponse.php
│ └── license.txt
│ ├── Element
│ ├── XenElement.php
│ ├── XenHost.php
│ ├── XenNetwork.php
│ └── XenVirtualMachine.php
│ ├── Exception
│ └── XenConnectionException.php
│ └── Xen.php
└── tests
└── .gitkeep
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | composer.phar
3 | vendor
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Xenapi for PHP
2 |
3 | A Xen PHP API for managment of Hypervisor and Citrix Server and their Virtual Machines for PHP, it works on Laravel 4, Laravel 5, Codeigniter and other PHP framework.
4 | Before install this library make sure to have installed *xmlrpc php* module
5 |
6 | API in PHP to communicate with Xen Server .
7 | This packages is available on Composer's repositories .
8 | The package Allows to completely Manage an Hypervisvor Citrix .
9 | With this , you can clone , start , stop and reboot any VPS of your Hypervisor
10 | Also, this APi allow you toi have a realtime graph of your Hypervisor's VPS!
11 | I've create the Method that obtain XML realtime stats of Machine and convert it to RRD file, needed for the FlotJS library to draw the graph.
12 | This API is available for all the major PHP Frameworks, such as Laravel, Symfony or Codeigniter.
13 |
14 | ## Table Of Contents
15 |
16 | 1. [Installation](#installation)
17 | 2. [Documentation](#documentation)
18 | + [Namespace Import](#namespace-import)
19 | + [Connect With an Hypervisor](#connect-with-an-hypervisor)
20 | + [Get Virtual Machine](#get-virtual-machine)
21 | + [Virtual Machine Managment](#virtual-machine-managment)
22 | + [Get Host](#get-host)
23 | + [Host Management](#host-management)
24 | + [Response Management](#response-management)
25 | + [Exceptions](#exceptions)
26 |
27 | ## Installation :
28 |
29 | Package is available on [Packagist](https://packagist.org/packages/sircamp/xenapi),
30 | you can install it using [Composer](http://getcomposer.org).
31 |
32 | In the **require** key of **composer.json** file add the following:
33 |
34 | ```php
35 | "sircamp/xenapi": "2.1"
36 | ```
37 | Or type this command from your project folder
38 |
39 | ```bash
40 | composer require sircamp/xenapi
41 | ```
42 |
43 | ## Documentation:
44 |
45 | #### Namespace Import
46 | Sircamp\Xenapi is namespaced, but you can make your life easier by importing
47 | a single class into your context:
48 |
49 | ```php
50 | use Sircamp\Xenapi\Xen as Xen;
51 | ```
52 |
53 | #### Connect With an Hypervisor
54 |
55 | Make sure that you have IP, User and Password of your hypervisor:
56 |
57 | ```php
58 | $ip = "123.123.123.123";
59 | $user = "username";
60 | $password = "password";
61 | $xen = new Xen($ip,$user,$password); //OK now you have an open connection to Hypervisor
62 | ```
63 |
64 | #### Get Virtual Machine
65 |
66 | This serves to have a virtual machine (by the hostname) that is on selected hypervisor :
67 |
68 | ```php
69 | $vm = $xen->getVMByNameLabel("virtual.machine.hostaname");
70 | ```
71 |
72 |
73 | #### Virtual Machine Management
74 |
75 | Now you have the an XenVirtualMachine object that map your virtual machine, so we are ready to manage the VM
76 |
77 | ##### Start VM
78 |
79 | This method starts a stopped VM
80 |
81 | ```php
82 | $vm->start();
83 | ```
84 | You can, also, pass two parameters at this method:
85 | ```php
86 | $pause = true; // start VM in pause status , dafault is false
87 | $force = true; // force the boot of VM, default is true
88 | $vm->start($pause, $force);
89 | ```
90 |
91 | ##### StartOn VM
92 |
93 | This method starts the specified VM on a particular host. This function can only be called with the VM is in the Halted State.
94 | *This method needs an XenHost object as parameter, but if you want you can pass a UUID host string*
95 |
96 | ```php
97 | $host // this is a XenHost object istance or a string istance
98 | $hostRef = $host;
99 | $pause = true; // start VM in pause status , dafault is false
100 | $force = true; // force the boot of VM, default is true
101 | $vm->startOn($hostRef,$pause, $force);
102 | ```
103 |
104 | ##### Shutdown VM
105 |
106 | This method sends a shutdown command to the Virtual Machine
107 |
108 | ```php
109 | $vm->cleanShutdown();
110 | ```
111 |
112 | ##### Hard Shutdown VM
113 | This method immediatly a shutdown the Virtual Machine
114 |
115 | ```php
116 | $vm->hardShutdown();
117 | ```
118 |
119 | ##### Reboot VM
120 | This method sends a reboot command to the Virtual Machine
121 | ```php
122 | $vm->cleanShutdown();
123 | ```
124 |
125 | ##### Hard Reboot VM
126 |
127 | This method immediatly restarts the Virtual Machine
128 |
129 | ```php
130 | $vm->hardShutdown();
131 | ```
132 |
133 | ##### Suspend VM
134 |
135 | This method puts Virtual Machine in a suspend mode (read the Citrix manual)
136 |
137 | ```php
138 | $vm->suspend();
139 | ```
140 |
141 | ##### Resume VM
142 |
143 | This method resumes a Virtual Machine that is in a suspend mode (read the Citrix manual)
144 |
145 | ```php
146 | $vm->resume();
147 | ```
148 | ##### ResumeOn VM
149 |
150 | This method awaken the specified VM and resume it on a particular Host. This can only be called when the specified VM is in the Suspended state.
151 | *This method needs an XenHost object as parameter, but if you want you can pass a UUID host string*
152 |
153 | ```php
154 | $host // this is a XenHost object istance or a string istance
155 | $hostRef = $host;
156 | $vm->resumeOn($hostRef);
157 | ```
158 |
159 | ##### Pause VM
160 |
161 | This method puts a Virtual Machine in pause
162 |
163 | ```php
164 | $vm->pause();
165 | ```
166 |
167 | ##### Unpause VM
168 |
169 | This method restores a Virtual Machine that is in pause
170 |
171 | ```php
172 | $vm->unpause();
173 | ```
174 |
175 | ##### Clone VM
176 |
177 | This method clones the selected Virtual Machine into another ( please check if your hypervisor supports another machine).
178 |
179 | before this, you must stop the virtual machine that you want clone
180 |
181 | ```php
182 | $name = "new_cloned_vm"; // name of cloned vm
183 | $vm->cleanShudown(); // stop vm
184 | $vm->clonevm($name);
185 | ```
186 |
187 | ##### Power Status of VM
188 |
189 | This method gets the power status of the selected Virtual Machine
190 |
191 | ```php
192 | $vm->getPowerState();
193 | ```
194 |
195 | ##### Power State Reset of VM
196 |
197 | Reset the power-state of the VM to halted in the database only. (Used to recover from slave failures in pooling scenarios by resetting the power-states of VMs running on dead slaves to halted.) This is a potentially dangerous operation; use with care.
198 |
199 | ```php
200 | $vm->powerStateReset();
201 | ```
202 |
203 | ##### UUID of VM
204 |
205 | This method obtains the UUID of the selected Virtual Machine.
206 |
207 |
208 | ```php
209 | $vm->getUUID();
210 | ```
211 |
212 | ##### Consoles of VM
213 |
214 | This method returns the all console instances of selected Virtual Machine.
215 | The console istance allows you to have and manage a SSH or RDP session of Virtual Machine
216 |
217 |
218 | ```php
219 | $vm->getConsoles()
220 | ```
221 | ##### UUID of VM Console
222 |
223 | This method returns the UUID of selected Virtual Machine's console.
224 | The UUID is very usefull for console istance mangement.
225 |
226 | ```php
227 | $vm->getConsoleUUID($console)
228 | ```
229 |
230 | ##### Guest Metrics of VM
231 |
232 | This method returns the guest metrics of selected Virtual Machine.
233 | This metrics contains:
234 |
235 | + uuid
236 | + os_version (name, uname, distro, relase version)
237 | + memory
238 | + disks
239 | + networks
240 | + other
241 |
242 | *in the future, i will write an example*
243 |
244 | ```php
245 | $vm->getGuestMetrics()
246 | ```
247 |
248 |
249 | ##### Metrics of VM
250 |
251 | This method returns the metrics of selected Virtual Machine.
252 | This metrics contains:
253 |
254 | + uuid
255 | + memory_actual
256 | + VCPUs_number
257 | + VCPUs_utilisation
258 |
259 | *as for guest metrics, in the future, i will write an example*
260 |
261 | ```php
262 | $vm->getMetrics()
263 | ```
264 | ##### Statistics of VM
265 |
266 | This method returns the current stats of the running selected Virtual Machine.
267 | With this method, you can obtain the stats of CPUs, RAM and DISK I/O in ***realtime***!
268 |
269 | However, this method return an response object that contains a XML string in the ***value*** attribute.
270 | Inside this XML string you find the required statistics.
271 |
272 | *as for last two methods, in the future, i will write an example. Also, i would to show you how to obtain a realtime stats graph, stay tuned ;)*
273 |
274 | ```php
275 | $vm->getStats()
276 | ```
277 | ##### Disks Total Space of VM
278 |
279 | This method returns the total amount of Virtual Machine's Disks space.
280 | Actually this method return the total in bytes.
281 |
282 | ```php
283 | $vm->getDiskSpace()
284 | ```
285 | Also, you can pass an argument:
286 |
287 | ```php
288 | $format = "GB";
289 | $vm->getDiskSpace($format);
290 | ```
291 | This allow you to have the disk space in the format as you want.
292 | **NB: this feature is not yet implemented**
293 |
294 | ##### Name of VM
295 | This method returns the name of VM
296 |
297 | ```php
298 | $vm->getName()
299 | ```
300 |
301 | ##### GetAll VMs
302 | This method returns a list of all the VMs known to the system.
303 |
304 | ```php
305 | $vm->getAll()
306 | ```
307 |
308 | ##### PoolMigrate VM
309 | Migrate a VM to another Host. This can only be called when the specified VM is in the Running state.
310 | *This method needs an XenHost object as parameter, but if you want you can pass a UUID host string*
311 | The *optionsMap* parameter is a map that contains the options for pool migrating.
312 |
313 | ```php
314 | $optionsMap = array(
315 | 'option1' => "option first",
316 | 'option2' => "option second"
317 | )
318 | $host // this is a XenHost object istance or a string istance
319 | $hostRef = $host;
320 | $vm->poolMigrate($refHost, $optionsMap);
321 | ```
322 |
323 | ##### MigrateSend VM
324 | Assert whether a VM can be migrated to the specified destination.
325 | In this method the first parameter, *dest*, is the result of a **Host.migrate** receive call.
326 | The *vdiMap* parameter is the map of source VDI to destination SR.
327 | The *vifMap* parameter is the map of VIF to destination network.
328 | The *optionsMap* Extra configuration operations.
329 | The *live* parameter allows to migrate the VM in *live mode* or nothing, on default this paramter is set to *false*.
330 |
331 | ```php
332 | $dest // Host.migrate call result
333 | $vdiMap //map of source VDI
334 | $vifMap //map of source VFI
335 | $options = array(
336 | 'option1' => "option first",
337 | 'option2' => "option second"
338 | );
339 | $live = true;
340 | $vm->migrateSend($dest,$vdiMap,$vifMap,$options,$live)
341 | ```
342 | **NB: this method is still in testing mode**
343 |
344 | ##### AssertCanMigrate VM
345 | Assert whether a VM can be migrated to the specified destination.
346 | In this method the first parameter, *dest*, is the result of a **Host.migrate** receive call.
347 | The *vdiMap* parameter is the map of source VDI to destination SR.
348 | The *vifMap* parameter is the map of VIF to destination network.
349 | The *optionsMap* Extra configuration operations.
350 | The *live* parameter allows to migrate the VM in *live mode* or nothing, on default this paramter is set to *false*.
351 |
352 | ```php
353 | $dest // Host.migrate call result
354 | $vdiMap //map of source VDI
355 | $vifMap //map of source VFI
356 | $options = array(
357 | 'option1' => "option first",
358 | 'option2' => "option second"
359 | );
360 | $live = true;
361 | $vm->assertCanMigrate($dest,$vdiMap,$vifMap,$options,$live)
362 | ```
363 | **NB: this method is still in testing mode**
364 |
365 | ##### Snapshot of VM
366 | Snapshots the specified VM, making a new VM. Snapshot automatically exploits the capabilities of the underlying storage repository in which the VM’s disk images are stored
367 |
368 | ```php
369 | $name = "name of snapshot";
370 | $vm->snapshot($name)
371 | ```
372 |
373 | ##### Snapshot of VM
374 | Snapshots the specified VM with quiesce, making a new VM.
375 | Snapshot automatically exploits the capabilities of the underlying storage repository in which the VM’s disk images are stored
376 |
377 | ```php
378 | $name = "name of snapshot";
379 | $vm->snapshotWithQuiesce($name)
380 | ```
381 | ##### GetSnapshot of VM
382 | Get the snapshot info field of the given VM.
383 |
384 | ```php
385 | $vm->getSnapshotInfo()
386 | ```
387 |
388 | ##### Revert of VM
389 | Reverts the specified VM to a previous state
390 |
391 | ```php
392 | $snapshotID // the snaoshot id
393 | $vm->revert($snapshotID)
394 | ```
395 |
396 | ##### Copy VM
397 | Copied the specified VM, making a new VM. Unlike clone, copy does not exploits the capabilities of the underlying storage repository in which the VM’s disk images are stored. Instead, copy guarantees that the disk images of the newly created VM will be ’full disks’ - i.e. not part of a CoW chain. This function can only be called when the VM is in the Halted State
398 |
399 | ```php
400 | $name = "nameOfCopy";
401 | $vm->copy($name);
402 | ```
403 |
404 | ##### Destroy VM
405 | Destroy the specified VM. The VM is completely removed from the system. This function can only be called when the VM is in the Halted State.
406 |
407 | ```php
408 | $vm->destroy();
409 | ```
410 |
411 | ##### Checkpoints of VM
412 | Checkpoints the specified VM, making a new VM. Checkpoint automatically exploits the capabil-ities of the underlying storage repository in which the VM’s disk images are stored (e.g. Copy on Write) and saves the memory image as well
413 |
414 | ```php
415 | $name = "nameOfVM";
416 | $vm->checkpoint($name);
417 | ```
418 |
419 | ##### SetStartDelay of VM
420 | Set this VM’s start delay in seconds.
421 |
422 | ```php
423 | $seconds = 5;
424 | $vm->setStartDelay($seconds);
425 | ```
426 |
427 | ##### SetShutdownDelay of VM
428 | Set this VM’s start delay in seconds.
429 |
430 | ```php
431 | $seconds = 5;
432 | $vm->setShutdownDelay($seconds);
433 | ```
434 |
435 | ##### GetStartDelay of VM
436 | Get this VM’s start delay in seconds.
437 |
438 | ```php
439 | $vm->getStartDelay();
440 | ```
441 |
442 | ##### GetShutdownDelay of VM
443 | Get this VM’s start delay in seconds.
444 |
445 | ```php
446 | $vm->getShutdownDelay();
447 | ```
448 | ##### GetCurrentOperations of VM
449 | Get the current operations field of the given VM.
450 |
451 | ```php
452 | $vm->getCurrentOperations();
453 | ```
454 | ##### GetAllowedOperations of VM
455 | Get the allowed operations field of the given VM.
456 |
457 | ```php
458 | $vm->getAllowedOperations();
459 | ```
460 | ##### GetNameDescription of VM
461 | Get the name/description field of the given VM.
462 |
463 | ```php
464 | $vm->getNameDescription();
465 | ```
466 |
467 | ##### SetNameDescription of VM
468 | Set the name/description field of the given VM.
469 |
470 | ```php
471 | $description = "description";
472 | $vm->setNameDescription($description);
473 | ```
474 |
475 | ##### GetIsATemplate of VM
476 | Get the is a template field of the given VM.
477 |
478 | ```php
479 | $vm->getIsATemplate();
480 | ```
481 |
482 | ##### SetIsATemplate of VM
483 | Set the is a template field of the given VM.
484 |
485 | ```php
486 | $template = false;
487 | $vm->setIsATemplate($template);
488 | ```
489 |
490 | ##### GetResidentOn of VM
491 | Get the resident on field of the given VM.
492 | In the response of this method you’ll find a XenHost object that you can use.
493 |
494 | ```php
495 | $vm->getResidentOn();
496 | ```
497 | ##### GetPlatform of VM
498 | Get the platform field of the given VM.
499 |
500 | ```php
501 | $vm->getPlatform();
502 | ```
503 |
504 | ##### SetPlatform of VM
505 | Set the platform field of the given VM.
506 |
507 | ```php
508 | $array = array(
509 | 'data'=>'value',
510 | 'data2'=>'value'
511 | );
512 | $vm->setPlatform($array);
513 | ```
514 |
515 | ##### GetOtherConfig of VM
516 | Get the other config field of the given VM.
517 |
518 | ```php
519 | $vm->getOtherConfig();
520 | ```
521 |
522 | ##### SetOtherConfig of VM
523 | Set the other config field of the given VM.
524 |
525 | ```php
526 | $array = array(
527 | 'config'=>'value',
528 | 'config2'=>'value'
529 | );
530 | $vm->setOtherConfig($array);
531 | ```
532 |
533 | ##### AddToOtherConfig of VM
534 | Set the other config field of the VM given key-value pair to the other config field of the given vm.
535 |
536 | ```php
537 | $key = "key";
538 | $value = "value"
539 |
540 | $vm->addToOtherConfig($key, value);
541 | ```
542 |
543 | ##### RemoveFromOtherConfig of VM
544 | Remove the given key and its corresponding value from the other config field of the given vm. If the key is not in that Map, then do nothing.
545 |
546 | ```php
547 | $key = "key";
548 | $value = "value"
549 |
550 | $vm->removeFromOtherConfig($key);
551 | ```
552 |
553 | ##### GetNameLabel of VM
554 | Get name label VM.
555 |
556 | ```php
557 | $vm->getNameLabel();
558 | ```
559 |
560 | #### Get Host
561 |
562 | This serves to obtain the target host (by the hostname) :
563 |
564 | ```php
565 | $host = $xen->getHOSTByNameLabel("host.machine.hostaname");
566 | ```
567 |
568 | #### Host Management
569 |
570 | Now you have the an XenHost object that map your hypervisor, so we are ready to manage the HOST
571 |
572 | ##### Disable HOST
573 | Puts the host into a state in which no new VMs can be started. Currently active VMs on the host continue to execute.
574 | ```php
575 | $host->disable()
576 | ```
577 | ##### Enable HOST
578 | Puts the host into a state in which new VMs can be started.
579 | ```php
580 | $host->enable()
581 | ```
582 | ##### Shutdown HOST
583 | Shutdown the host. (This function can only be called if there are no currently running VMs on the host and it is disabled.).
584 |
585 | ```php
586 | $host->shutdown()
587 | ```
588 | ##### Reboot HOST
589 | Reboot the host. (This function can only be called if there are no currently running VMs on the host and it is disabled.).
590 |
591 | ```php
592 | $host->reboot()
593 | ```
594 | ##### Dmesg of HOST
595 | Get the host xen dmesg.
596 |
597 | ```php
598 | $host->dmesg()
599 | ```
600 | ##### DmesgClear of HOST
601 | Get the host xen dmesg, and clear the buffer
602 |
603 | ```php
604 | $host->dmesgClear()
605 | ```
606 | ##### GetLog of HOST
607 | Get the host’s log file.
608 |
609 | ```php
610 | $host->getLog()
611 | ```
612 | ##### ListMethods of HOST
613 | List all supported methods.
614 |
615 | ```php
616 | $host->listMethods()
617 | ```
618 |
619 | ##### LicenseApply of HOST
620 | Apply a new license to a host.
621 | The default value of *$license* is an empty string
622 |
623 | ```php
624 | $file = file_get_contents("/path/license/file");
625 | $license = base64_encode($file);
626 | $host->licenseApply($license)
627 | ```
628 | **NB: $license must be an base64 encoded file**
629 |
630 |
631 | ##### AssertCanEvacuate HOST
632 | Check this host can be evacuated.
633 |
634 | ```php
635 | $host->assertCanEvacuate()
636 | ```
637 |
638 | ##### Evacuate HOST
639 | Migrate all VMs off of this host, where possible.
640 |
641 | ```php
642 | $host->evacuate()
643 | ```
644 |
645 | ##### GetServerTime of HOST
646 | This call queries the host’s clock for the current time.
647 |
648 | ```php
649 | $host->getServertime()
650 | ```
651 |
652 | ##### GetServerLocaltime of HOST
653 | This call queries the host's clock for the current time in the host’s local timezone.
654 |
655 | ```php
656 | $host->getServerLocaltime()
657 | ```
658 | ##### GetServerCertificate of HOST
659 | Get the installed server SSL certificate.
660 |
661 | ```php
662 | $host->getServerCertificate()
663 | ```
664 | **NB: This method returns the SSL certificate in .pem format**
665 |
666 | ##### ApplyEdition of HOST
667 | Change to another edition, or reactivate the current edition after a license has expired. This may be subject to the successful checkout of an appropriate license.
668 | Default *$force* param is *false*, this means which you want force an update edition.
669 |
670 | ```php
671 | $edition = "newedition";
672 | $force = true;
673 | $host->getServerCertificate()
674 | ```
675 | ##### RefreshPackInfo of HOST
676 | Refresh the list of installed Supplemental Packs.
677 |
678 | ```php
679 | $host->refreshPackInfo()
680 | ```
681 |
682 | ##### EnableLocalStorageCaching of HOST
683 | Enable the use of a local SR for caching purposes.
684 |
685 | ```php
686 | $srRef = "srReferID";
687 | $host->enableLocalStorageCaching($srRef);
688 | ```
689 |
690 | ##### DisableLocalStorageCaching of HOST
691 | Disable the use of a local SR for caching purposes.
692 |
693 | ```php
694 | $host->disableLocalStorageCaching();
695 | ```
696 |
697 | ##### MigrateReceive of HOST
698 | Prepare to receive a VM, returning a token which can be passed to *VM->migrate().*
699 | The *$features* is an associative array that cotains the configuration value that you need to run the migrating machine, it default value is an *empty* array.
700 |
701 | ```php
702 | $networkRef = "networkRef" // shorty you can pass the obeject that map network
703 | $features = array(
704 | 'options1'=>"youroption",
705 | 'options2'=>"youroption",
706 | );
707 | $host->migrateReceive($networkRef, $features);
708 | ```
709 | ##### GETUUID of HOST
710 | Get the uuid field of the given host.
711 |
712 | ```php
713 | $host->getUUID()
714 | ```
715 |
716 | ##### GetNameLabel of HOST
717 | Get the name/label field of the given host.
718 |
719 | ```php
720 | $host->getNameLabel()
721 | ```
722 | ##### SetNameLabel of HOST
723 | Set the name/label field of the given host.
724 |
725 | ```php
726 | $name = "server.yourname.com";
727 | $host->setNameLabel($name);
728 | ```
729 |
730 | ##### GetNameDescription of HOST
731 | Get the name/description field of the given HOST.
732 |
733 | ```php
734 | $host->getNameDescription()
735 | ```
736 | ##### SetNameDescription of HOST
737 | Set the name/description field of the given HOST.
738 |
739 | ```php
740 | $description = "long long text";
741 | $host->setNameDescription($description)
742 | ```
743 | ##### SetNameDescription of HOST
744 | Set the name/description field of the given HOST.
745 |
746 | ```php
747 | $description = "long long text";
748 | $host->setNameDescription($description)
749 | ```
750 | ##### GetAllowedOperations of HOST
751 | Get the allowed operations field of the given HOST.
752 |
753 | ```php
754 | $host->getAllowedOperations()
755 | ```
756 |
757 | ##### GetSoftwareVersion of HOST
758 | Get the software version field of the given host.
759 |
760 | ```php
761 | $host->getSoftwareVersion()
762 | ```
763 |
764 | ##### GetOtherConfig of HOST
765 | Get the other config field of the given HOST.
766 |
767 | ```php
768 | $host->getOtherConfig()
769 | ```
770 | ##### SetOtherConfig of HOST
771 | Set the other config field of the given HOST.
772 |
773 | ```php
774 | $config = array(
775 | 'config1' => "first config",
776 | 'config2' => "second config"
777 | );
778 | $host->setOtherConfig($config)
779 | ```
780 |
781 | ##### AddOtherConfig of HOST
782 | Add the given key-value pair to the other config field of the given host.
783 |
784 | ```php
785 | $key = "config1";
786 | $value = "first config";
787 | $host->addOtherConfig($key,$value)
788 | ```
789 | ##### RemoveOtherConfig of HOST
790 | Remove the given key and its corresponding value from the other config field of the given host. *If the key is not in that Map, then do nothing.*
791 |
792 | ```php
793 | $key = "config1";
794 | $host->removeOtherConfig($key)
795 | ```
796 |
797 | ##### GetSupportedBootloaders of HOST
798 | Get the supported bootloaders field of the given host.
799 |
800 | ```php
801 | $host->getSupportedBootloaders()
802 | ```
803 | ##### GetResidentVMs of HOST
804 | Get the resident VMs field of the given host.
805 | In the response of this method you'll find, if there exists at least a VM inside this Host, an array of VMs object that you can use.
806 |
807 | ```php
808 | $host->getResidentVMs()
809 | ```
810 | ##### GetPatches of HOST
811 | Get the patches field of the given host.
812 |
813 | ```php
814 | $host->getPatches()
815 | ```
816 |
817 | ##### GetHostCPUs of HOST
818 | Get the host CPUs field of the given host.
819 |
820 | ```php
821 | $host->getHostCPUs()
822 | ```
823 | ##### GetCPUInfo of HOST
824 | Get the cpu info field of the given host.
825 |
826 | ```php
827 | $host->getCPUInfo()
828 | ```
829 | ##### GetHostname of HOST
830 | Get the hostname of the given host.
831 |
832 | ```php
833 | $host->getHostname()
834 | ```
835 | ##### SetHostname of HOST
836 | Set the hostname of the given host.
837 |
838 | ```php
839 | $name = "new.hostname.com"
840 | $host->setHostname($name);
841 | ```
842 | ##### GetAddress of HOST
843 | Get the address field of the given host.
844 |
845 | ```php
846 | $host->getAddress()
847 | ```
848 |
849 | ##### SetAddress of HOST
850 | Set the address field of the given host.
851 |
852 | ```php
853 | $address = "123.123.123.123"
854 | $host->setAddress($address);
855 | ```
856 |
857 | ##### GetMetrics of HOST
858 | Get the metrics field of the given host.
859 |
860 | ```php
861 | $host->getMetrics()
862 | ```
863 |
864 | ##### GetLicenseParam of HOST
865 | Get the license params field of the given host.
866 |
867 | ```php
868 | $host->getLicenseParam()
869 | ```
870 | ##### GetEdition of HOST
871 | Get the edition field of the given host.
872 |
873 | ```php
874 | $host->getEdition()
875 | ```
876 |
877 | ##### GetLicenseServer of HOST
878 | Get the license server field of the given host.
879 |
880 | ```php
881 | $host->getLicenseServer()
882 | ```
883 | ##### SetLicenseServer of HOST
884 | Set the license server field of the given host.
885 |
886 | ```php
887 | $license = "newlicense"
888 | $host->setLicenseServer($license);
889 | ```
890 | ##### AddToLicenseServer of HOST
891 | Add the given key-value pair to the license server field of the given host.
892 |
893 | ```php
894 | $key = "licenseName";
895 | $value = "licenseValue";
896 | $host->addToLicenseServer($key,$value);
897 | ```
898 |
899 | ##### RemoveFromLicenseServer of HOST
900 | Remove the given key and its corresponding value from the license server field of the given host. *If the key is not in that Map, then do nothing.*
901 |
902 | ```php
903 | $key = "licenseName";
904 | $host->removeFromLicenseServer($key);
905 | ```
906 |
907 | ##### GetChipsetInfo of HOST
908 | Get the chipset info field of the given host.
909 |
910 | ```php
911 | $host->getChipsetInfo()
912 | ```
913 | #### Response Management
914 |
915 | Every method return an istance of *XenResponse* class.
916 | This object contains three attributes:
917 |
918 | + Value
919 | + Status
920 | + ErrorDescription
921 |
922 | ##### Value attribute
923 | This attribute contains the value of response, sach as message, XML string or something else.
924 |
925 | use this method to obtain it:
926 | ```php
927 | $response = $vm->hardReboot();
928 | $response->getValue();
929 | ```
930 | ##### Status attribute
931 | This attribute contains the status of response.
932 | If status is **Success** the request is OK.
933 | Otherwise is request is KO, use this for check the result of your operations
934 |
935 | use this method to obtain it:
936 | ```php
937 | $response = $vm->hardReboot();
938 | $response->getStatus();
939 | ```
940 | ##### ErrorDescription attribute
941 | This attribute contains message of KO response.
942 | Just take the value of this attribute and check why the response isn't OK.
943 |
944 | For example if your connection credentials are wrong:
945 | ```php
946 | $console = "wrong_console";
947 | $response = $vm->getConsolesUUID($console);
948 | $response->getStatus(); //return Failure
949 | $response->getErrorDescription(); // return an array with some error message
950 | ```
951 |
952 | #### Exceptions
953 |
954 | This is exaplained the custom excetions
955 |
956 | ##### XenConnectionException
957 |
958 | This exception is launched when you try to connect to a hypervisor with a wrong credentials.
959 |
960 | To catch this exception, remember to use the namespace of this class:
961 | ```php
962 | use Sircamp\Xenapi\Exception\XenConnectionException as XenConnectionException;
963 | ```
964 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sircamp/xenapi",
3 | "description": "A Xen PHP API for managment of Hypervisor and their Virtual Machine for php",
4 | "keywords": ["laravel","xen","phpxenapi","api","citrix","citrixapi","xmlrpc","vps","hypervisor"],
5 | "type": "library",
6 | "license": "MIT",
7 | "authors": [
8 | {
9 | "name": "Stefano Campese",
10 | "email": "sircampydevelop@gmail.com",
11 | "role": "Developer",
12 | "homepage": "http://www.stefanocampese.xyz"
13 | }
14 | ],
15 | "require": {
16 | "php": ">=5.4.0",
17 | "respect/validation": "^1.1",
18 | "guzzlehttp/guzzle": "~5.0"
19 | },
20 | "autoload": {
21 | "classmap": [
22 |
23 | ],
24 | "psr-0": {
25 | "Sircamp\\Xenapi\\": "src/"
26 | }
27 | },
28 | "suggest": {
29 | "nesbot/carbon": "A simple API extension for DateTime."
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5 | "This file is @generated automatically"
6 | ],
7 | "content-hash": "c4901b44b258374175f8186710870052",
8 | "packages": [
9 | {
10 | "name": "guzzlehttp/guzzle",
11 | "version": "5.3.1",
12 | "source": {
13 | "type": "git",
14 | "url": "https://github.com/guzzle/guzzle.git",
15 | "reference": "70f1fa53b71c4647bf2762c09068a95f77e12fb8"
16 | },
17 | "dist": {
18 | "type": "zip",
19 | "url": "https://api.github.com/repos/guzzle/guzzle/zipball/70f1fa53b71c4647bf2762c09068a95f77e12fb8",
20 | "reference": "70f1fa53b71c4647bf2762c09068a95f77e12fb8",
21 | "shasum": ""
22 | },
23 | "require": {
24 | "guzzlehttp/ringphp": "^1.1",
25 | "php": ">=5.4.0"
26 | },
27 | "require-dev": {
28 | "ext-curl": "*",
29 | "phpunit/phpunit": "^4.0"
30 | },
31 | "type": "library",
32 | "autoload": {
33 | "psr-4": {
34 | "GuzzleHttp\\": "src/"
35 | }
36 | },
37 | "notification-url": "https://packagist.org/downloads/",
38 | "license": [
39 | "MIT"
40 | ],
41 | "authors": [
42 | {
43 | "name": "Michael Dowling",
44 | "email": "mtdowling@gmail.com",
45 | "homepage": "https://github.com/mtdowling"
46 | }
47 | ],
48 | "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients",
49 | "homepage": "http://guzzlephp.org/",
50 | "keywords": [
51 | "client",
52 | "curl",
53 | "framework",
54 | "http",
55 | "http client",
56 | "rest",
57 | "web service"
58 | ],
59 | "time": "2016-07-15T19:28:39+00:00"
60 | },
61 | {
62 | "name": "guzzlehttp/ringphp",
63 | "version": "1.1.0",
64 | "source": {
65 | "type": "git",
66 | "url": "https://github.com/guzzle/RingPHP.git",
67 | "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b"
68 | },
69 | "dist": {
70 | "type": "zip",
71 | "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/dbbb91d7f6c191e5e405e900e3102ac7f261bc0b",
72 | "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b",
73 | "shasum": ""
74 | },
75 | "require": {
76 | "guzzlehttp/streams": "~3.0",
77 | "php": ">=5.4.0",
78 | "react/promise": "~2.0"
79 | },
80 | "require-dev": {
81 | "ext-curl": "*",
82 | "phpunit/phpunit": "~4.0"
83 | },
84 | "suggest": {
85 | "ext-curl": "Guzzle will use specific adapters if cURL is present"
86 | },
87 | "type": "library",
88 | "extra": {
89 | "branch-alias": {
90 | "dev-master": "1.1-dev"
91 | }
92 | },
93 | "autoload": {
94 | "psr-4": {
95 | "GuzzleHttp\\Ring\\": "src/"
96 | }
97 | },
98 | "notification-url": "https://packagist.org/downloads/",
99 | "license": [
100 | "MIT"
101 | ],
102 | "authors": [
103 | {
104 | "name": "Michael Dowling",
105 | "email": "mtdowling@gmail.com",
106 | "homepage": "https://github.com/mtdowling"
107 | }
108 | ],
109 | "description": "Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function.",
110 | "time": "2015-05-20T03:37:09+00:00"
111 | },
112 | {
113 | "name": "guzzlehttp/streams",
114 | "version": "3.0.0",
115 | "source": {
116 | "type": "git",
117 | "url": "https://github.com/guzzle/streams.git",
118 | "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5"
119 | },
120 | "dist": {
121 | "type": "zip",
122 | "url": "https://api.github.com/repos/guzzle/streams/zipball/47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5",
123 | "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5",
124 | "shasum": ""
125 | },
126 | "require": {
127 | "php": ">=5.4.0"
128 | },
129 | "require-dev": {
130 | "phpunit/phpunit": "~4.0"
131 | },
132 | "type": "library",
133 | "extra": {
134 | "branch-alias": {
135 | "dev-master": "3.0-dev"
136 | }
137 | },
138 | "autoload": {
139 | "psr-4": {
140 | "GuzzleHttp\\Stream\\": "src/"
141 | }
142 | },
143 | "notification-url": "https://packagist.org/downloads/",
144 | "license": [
145 | "MIT"
146 | ],
147 | "authors": [
148 | {
149 | "name": "Michael Dowling",
150 | "email": "mtdowling@gmail.com",
151 | "homepage": "https://github.com/mtdowling"
152 | }
153 | ],
154 | "description": "Provides a simple abstraction over streams of data",
155 | "homepage": "http://guzzlephp.org/",
156 | "keywords": [
157 | "Guzzle",
158 | "stream"
159 | ],
160 | "time": "2014-10-12T19:18:40+00:00"
161 | },
162 | {
163 | "name": "react/promise",
164 | "version": "v2.5.1",
165 | "source": {
166 | "type": "git",
167 | "url": "https://github.com/reactphp/promise.git",
168 | "reference": "62785ae604c8d69725d693eb370e1d67e94c4053"
169 | },
170 | "dist": {
171 | "type": "zip",
172 | "url": "https://api.github.com/repos/reactphp/promise/zipball/62785ae604c8d69725d693eb370e1d67e94c4053",
173 | "reference": "62785ae604c8d69725d693eb370e1d67e94c4053",
174 | "shasum": ""
175 | },
176 | "require": {
177 | "php": ">=5.4.0"
178 | },
179 | "require-dev": {
180 | "phpunit/phpunit": "~4.8"
181 | },
182 | "type": "library",
183 | "autoload": {
184 | "psr-4": {
185 | "React\\Promise\\": "src/"
186 | },
187 | "files": [
188 | "src/functions_include.php"
189 | ]
190 | },
191 | "notification-url": "https://packagist.org/downloads/",
192 | "license": [
193 | "MIT"
194 | ],
195 | "authors": [
196 | {
197 | "name": "Jan Sorgalla",
198 | "email": "jsorgalla@gmail.com"
199 | }
200 | ],
201 | "description": "A lightweight implementation of CommonJS Promises/A for PHP",
202 | "keywords": [
203 | "promise",
204 | "promises"
205 | ],
206 | "time": "2017-03-25T12:08:31+00:00"
207 | },
208 | {
209 | "name": "respect/validation",
210 | "version": "1.1.14",
211 | "source": {
212 | "type": "git",
213 | "url": "https://github.com/Respect/Validation.git",
214 | "reference": "22f1f14430155c21c1d6ba271a652f28c5057851"
215 | },
216 | "dist": {
217 | "type": "zip",
218 | "url": "https://api.github.com/repos/Respect/Validation/zipball/22f1f14430155c21c1d6ba271a652f28c5057851",
219 | "reference": "22f1f14430155c21c1d6ba271a652f28c5057851",
220 | "shasum": ""
221 | },
222 | "require": {
223 | "php": ">=5.4",
224 | "symfony/polyfill-mbstring": "^1.2"
225 | },
226 | "require-dev": {
227 | "egulias/email-validator": "~1.2",
228 | "malkusch/bav": "~1.0",
229 | "mikey179/vfsstream": "^1.5",
230 | "phpunit/phpunit": "~4.0",
231 | "symfony/validator": "~2.6.9",
232 | "zendframework/zend-validator": "~2.3"
233 | },
234 | "suggest": {
235 | "egulias/email-validator": "Strict (RFC compliant) email validation",
236 | "ext-bcmath": "Arbitrary Precision Mathematics",
237 | "ext-mbstring": "Multibyte String Functions",
238 | "fabpot/php-cs-fixer": "Fix PSR2 and other coding style issues",
239 | "malkusch/bav": "German bank account validation",
240 | "symfony/validator": "Use Symfony validator through Respect\\Validation",
241 | "zendframework/zend-validator": "Use Zend Framework validator through Respect\\Validation"
242 | },
243 | "type": "library",
244 | "extra": {
245 | "branch-alias": {
246 | "dev-master": "1.1-dev"
247 | }
248 | },
249 | "autoload": {
250 | "psr-4": {
251 | "Respect\\Validation\\": "library/"
252 | }
253 | },
254 | "notification-url": "https://packagist.org/downloads/",
255 | "license": [
256 | "BSD Style"
257 | ],
258 | "authors": [
259 | {
260 | "name": "Respect/Validation Contributors",
261 | "homepage": "https://github.com/Respect/Validation/graphs/contributors"
262 | }
263 | ],
264 | "description": "The most awesome validation engine ever created for PHP",
265 | "homepage": "http://respect.github.io/Validation/",
266 | "keywords": [
267 | "respect",
268 | "validation",
269 | "validator"
270 | ],
271 | "time": "2017-10-17T10:15:51+00:00"
272 | },
273 | {
274 | "name": "symfony/polyfill-mbstring",
275 | "version": "v1.6.0",
276 | "source": {
277 | "type": "git",
278 | "url": "https://github.com/symfony/polyfill-mbstring.git",
279 | "reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296"
280 | },
281 | "dist": {
282 | "type": "zip",
283 | "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296",
284 | "reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296",
285 | "shasum": ""
286 | },
287 | "require": {
288 | "php": ">=5.3.3"
289 | },
290 | "suggest": {
291 | "ext-mbstring": "For best performance"
292 | },
293 | "type": "library",
294 | "extra": {
295 | "branch-alias": {
296 | "dev-master": "1.6-dev"
297 | }
298 | },
299 | "autoload": {
300 | "psr-4": {
301 | "Symfony\\Polyfill\\Mbstring\\": ""
302 | },
303 | "files": [
304 | "bootstrap.php"
305 | ]
306 | },
307 | "notification-url": "https://packagist.org/downloads/",
308 | "license": [
309 | "MIT"
310 | ],
311 | "authors": [
312 | {
313 | "name": "Nicolas Grekas",
314 | "email": "p@tchwork.com"
315 | },
316 | {
317 | "name": "Symfony Community",
318 | "homepage": "https://symfony.com/contributors"
319 | }
320 | ],
321 | "description": "Symfony polyfill for the Mbstring extension",
322 | "homepage": "https://symfony.com",
323 | "keywords": [
324 | "compatibility",
325 | "mbstring",
326 | "polyfill",
327 | "portable",
328 | "shim"
329 | ],
330 | "time": "2017-10-11T12:05:26+00:00"
331 | }
332 | ],
333 | "packages-dev": [],
334 | "aliases": [],
335 | "minimum-stability": "stable",
336 | "stability-flags": [],
337 | "prefer-stable": false,
338 | "prefer-lowest": false,
339 | "platform": {
340 | "php": ">=5.4.0"
341 | },
342 | "platform-dev": []
343 | }
344 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 | ./tests/
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/Sircamp/Xenapi/Connection/XenConnection.php:
--------------------------------------------------------------------------------
1 | session_id = null;
20 | $this->url = null;
21 | $this->user = null;
22 | $this->password = null;
23 |
24 | }
25 |
26 | /**
27 | * Gets the value of url.
28 | *
29 | * @return mixed
30 | */
31 | public function getUrl()
32 | {
33 | return $this->url;
34 | }
35 |
36 | /**
37 | * Sets the value of url.
38 | *
39 | * @param mixed $url the url
40 | *
41 | * @return self
42 | */
43 | private function _setUrl($url)
44 | {
45 | $this->url = $url;
46 |
47 | return $this;
48 | }
49 |
50 | /**
51 | * Gets the value of session_id.
52 | *
53 | * @return mixed
54 | */
55 | public function getSessionId()
56 | {
57 | return $this->session_id;
58 | }
59 |
60 | /**
61 | * Sets the value of session_id.
62 | *
63 | * @param mixed $session_id the session id
64 | *
65 | * @return self
66 | */
67 | private function _setSessionId($session_id)
68 | {
69 | $this->session_id = $session_id;
70 |
71 | return $this;
72 | }
73 |
74 | /**
75 | * Gets the value of user.
76 | *
77 | * @return mixed
78 | */
79 | public function getUser()
80 | {
81 | return $this->user;
82 | }
83 |
84 | /**
85 | * Sets the value of user.
86 | *
87 | * @param mixed $user the user
88 | *
89 | * @return self
90 | */
91 | private function _setUser($user)
92 | {
93 | $this->user = $user;
94 |
95 | return $this;
96 | }
97 |
98 | /**
99 | * Gets the value of password.
100 | *
101 | * @return mixed
102 | */
103 | public function getPassword()
104 | {
105 | return $this->password;
106 | }
107 |
108 | /**
109 | * Sets the value of password.
110 | *
111 | * @param mixed $password the password
112 | *
113 | * @return self
114 | */
115 | private function _setPassword($password)
116 | {
117 | $this->password = $password;
118 |
119 | return $this;
120 | }
121 |
122 | /**
123 | * Sets all values of object.
124 | *
125 | * @param mixed $password the password, mixed $url the url,
126 | * mixed $session_id the session_id and mixed 4user the user
127 | *
128 | * @return self
129 | */
130 |
131 | function _setAll($url, $session_id, $user, $password)
132 | {
133 |
134 | $this->_setPassword($password);
135 | $this->_setSessionId($session_id);
136 | $this->_setUrl($url);
137 | $this->_setUser($user);
138 |
139 | return $this;
140 | }
141 |
142 | /**
143 | * Sets and initialize xen server connection
144 | *
145 | * @param mixed $url the ip, mixed $user the user and mixed $password the password,
146 | *
147 | *
148 | * @return XenResponse
149 | */
150 |
151 | function _setServer($url, $user, $password)
152 | {
153 |
154 | $response = $this->xenrpc_request($url, $this->xenrpc_method('session.login_with_password', array($user, $password, '1.3.1')));
155 |
156 | if (Validator::arrayType()->validate($response) && Validator::key('Status', Validator::equals('Success'))->validate($response))
157 | {
158 |
159 | $this->_setAll($url, $response['Value'], $user, $password);
160 |
161 | }
162 | else
163 | {
164 |
165 | throw new XenConnectionException("Error during contact Xen, check your credentials (user, password and ip)", 1);
166 |
167 | }
168 | }
169 |
170 | /**
171 | * This parse the xml response and return the response obj
172 | *
173 | * @param mixed $response ,
174 | *
175 | *
176 | * @return XenResponse
177 | */
178 |
179 | function xenrpc_parseresponse($response)
180 | {
181 |
182 |
183 | if (!Validator::arrayType()->validate($response) && !Validator::key('Status')->validate($response))
184 | {
185 |
186 | return new XenResponse($response);
187 | }
188 | else
189 | {
190 |
191 | if (Validator::key('Status', Validator::equals('Success'))->validate($response))
192 | {
193 | return new XenResponse($response);
194 | }
195 | else
196 | {
197 |
198 | if ($response['ErrorDescription'][0] == 'SESSION_INVALID')
199 | {
200 |
201 | $response = $this->xenrpc_request($this->url, $this->xenrpc_method('session.login_with_password',
202 | array($this->user, $this->password, '1.3.1')));
203 |
204 | if (Validator::arrayType()->validate($response) && Validator::key('Status', Validator::equals('Success'))->validate($response))
205 | {
206 | $this->_setSessionId($response['Value']);
207 | }
208 | else
209 | {
210 | return new XenResponse($response);
211 | }
212 | }
213 | else
214 | {
215 | return new XenResponse($response);
216 |
217 | }
218 | }
219 | }
220 |
221 |
222 | return new XenResponse($response);
223 | }
224 |
225 |
226 | /**
227 | * This encode the request into a xml_rpc
228 | *
229 | * @param mixed $name the method name and mixed $params the arguments,
230 | *
231 | *
232 | * @return mixed
233 | */
234 |
235 | function xenrpc_method($name, $params)
236 | {
237 |
238 | $encoded_request = xmlrpc_encode_request($name, $params);
239 |
240 | return $encoded_request;
241 | }
242 |
243 |
244 | /**
245 | * This make the curl request for comunicate to xen
246 | *
247 | * @param mixed $usr the url and mixed $req the request,
248 | *
249 | *
250 | * @return XenResponse
251 | */
252 |
253 | function xenrpc_request($url, $req)
254 | {
255 |
256 | $client = new Client();
257 |
258 | $response = $client->post($url,
259 | [
260 |
261 | 'headers' => [
262 | 'Content-type' => 'text/xml',
263 | 'Content-length' => strlen($req),
264 | ],
265 | 'body' => $req,
266 | 'timeout' => 60,
267 | 'verify' => false,
268 |
269 | ]);
270 |
271 | $body = $response->getBody();
272 | $xml = "";
273 | while (!$body->eof())
274 | {
275 | $xml .= $body->read(1024);
276 | }
277 |
278 |
279 | return xmlrpc_decode($xml);
280 | }
281 |
282 |
283 | /**
284 | * This halde every non-declared class method called on XenConnectionObj
285 | *
286 | * @param mixed $name the name of method and $args the argument of method,
287 | *
288 | *
289 | * @return XenResponse
290 | */
291 |
292 | function __call($name, $args)
293 | {
294 |
295 | if (!Validator::arrayType()->validate($args))
296 | {
297 | $args = array();
298 | }
299 |
300 | list($mod, $method) = explode('__', $name);
301 | $response = $this->xenrpc_parseresponse($this->xenrpc_request($this->getUrl(),
302 | $this->xenrpc_method($mod . '.' . $method, array_merge(array($this->getSessionId()), $args))));
303 |
304 | return $response;
305 | }
306 |
307 | }
308 |
309 | ?>
310 |
--------------------------------------------------------------------------------
/src/Sircamp/Xenapi/Connection/XenResponse.php:
--------------------------------------------------------------------------------
1 | $argument)
18 | {
19 | $class = new ReflectionClass('Sircamp\Xenapi\Connection\XenResponse');
20 | $property = $class->getProperty($key);
21 | $property->setAccessible(true);
22 | $property->setValue($this, $argument);
23 |
24 | }
25 |
26 | }
27 |
28 | /**
29 | * Gets the value of Value.
30 | *
31 | * @return mixed
32 | */
33 | public function getValue()
34 | {
35 | return $this->Value;
36 | }
37 |
38 | /**
39 | * Sets the value of Value.
40 | *
41 | * @param mixed $Value the value
42 | *
43 | * @return self
44 | */
45 | public function _setValue($Value)
46 | {
47 | $this->Value = $Value;
48 |
49 | return $this;
50 | }
51 |
52 | /**
53 | * Gets the value of Status.
54 | *
55 | * @return mixed
56 | */
57 | public function getStatus()
58 | {
59 | return $this->Status;
60 | }
61 |
62 | /**
63 | * Sets the value of Status.
64 | *
65 | * @param mixed $Status the status
66 | *
67 | * @return self
68 | */
69 | private function _setStatus($Status)
70 | {
71 | $this->Status = $Status;
72 |
73 | return $this;
74 | }
75 |
76 | /**
77 | * Gets the value of ErrorDescription.
78 | *
79 | * @return mixed
80 | */
81 | public function getErrorDescription()
82 | {
83 | return $this->ErrorDescription;
84 | }
85 |
86 | /**
87 | * Sets the value of ErrorDescription.
88 | *
89 | * @param mixed $ErrorDescription the error description
90 | *
91 | * @return self
92 | */
93 | private function _setErrorDescription($ErrorDescription)
94 | {
95 | $this->ErrorDescription = $ErrorDescription;
96 |
97 | return $this;
98 | }
99 | }
100 |
101 | ?>
--------------------------------------------------------------------------------
/src/Sircamp/Xenapi/Connection/license.txt:
--------------------------------------------------------------------------------
1 | /*
2 | * PHP XenAPI v1.0
3 | * a class for XenServer API calls
4 | *
5 | * Copyright (C) 2010 Andy Goodwin
6 | *
7 | * This class requires xml-rpc, PHP5, and curl.
8 | *
9 | * Permission is hereby granted, free of charge, to any person obtaining
10 | * a copy of this software and associated documentation files (the
11 | * "Software"), to deal in the Software without restriction, including
12 | * without limitation the rights to use, copy, modify, merge, publish,
13 | * distribute, sublicense, and/or sell copies of the Software, and to
14 | * permit persons to whom the Software is furnished to do so, subject to
15 | * the following conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be included
18 | * in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | *
28 | */
29 |
--------------------------------------------------------------------------------
/src/Sircamp/Xenapi/Element/XenElement.php:
--------------------------------------------------------------------------------
1 | xenconnection = $xenconnection;
17 | }
18 |
19 | /**
20 | * Gets the value of xenconnection.
21 | *
22 | * @return mixed
23 | */
24 | public function getXenconnection()
25 | {
26 | return $this->xenconnection;
27 | }
28 |
29 | /**
30 | * Sets the value of xenconnection.
31 | *
32 | * @param mixed $xenconnection the xenconnection
33 | *
34 | * @return self
35 | */
36 | private function _setXenconnection($xenconnection)
37 | {
38 | $this->xenconnection = $xenconnection;
39 |
40 | return $this;
41 | }
42 | }
43 |
44 | ?>
--------------------------------------------------------------------------------
/src/Sircamp/Xenapi/Element/XenHost.php:
--------------------------------------------------------------------------------
1 | name = $name;
16 | $this->hostId = $hostId;
17 | }
18 |
19 | /**
20 | * Gets the value of name.
21 | *
22 | * @return mixed
23 | */
24 | public function getName()
25 | {
26 | return $this->name;
27 | }
28 |
29 | /**
30 | * Sets the value of name.
31 | *
32 | * @param mixed $name the name
33 | *
34 | * @return self
35 | */
36 | public function _setName($name)
37 | {
38 | $this->name = $name;
39 |
40 | return $this;
41 | }
42 |
43 | /**
44 | * Gets the value of hostId.
45 | *
46 | * @return mixed
47 | */
48 | public function getHostId()
49 | {
50 | return $this->hostId;
51 | }
52 |
53 | /**
54 | * Sets the value of hostId.
55 | *
56 | * @param mixed $hostId the host id
57 | *
58 | * @return self
59 | */
60 | public function _setHostId($hostId)
61 | {
62 | $this->hostId = $hostId;
63 |
64 | return $this;
65 | }
66 |
67 | /**
68 | * Puts the host into a state in which no new VMs can be started. Currently active VMs on the host
69 | * continue to execute.
70 | *
71 | * @param
72 | *
73 | * @return mixed
74 | */
75 | public function disable()
76 | {
77 |
78 | return $this->getXenconnection()->host__disable($this->getHostId());
79 | }
80 |
81 | /**
82 | * Puts the host into a state in which new VMs can be started.
83 | *
84 | * @param
85 | *
86 | * @return mixed
87 | */
88 | public function enable()
89 | {
90 |
91 | return $this->getXenconnection()->host__enable($this->getHostId());
92 | }
93 |
94 |
95 | /**
96 | * Shutdown the host. (This function can only be called if there are no currently running VMs on
97 | * the host and it is disabled.).
98 | *
99 | * @param
100 | *
101 | * @return mixed
102 | */
103 | public function shutdown()
104 | {
105 |
106 | return $this->getXenconnection()->host__shutdown($this->getHostId());
107 | }
108 |
109 | /**
110 | * Reboot the host. (This function can only be called if there are no currently running VMs on
111 | * the host and it is disabled.).
112 | *
113 | * @param
114 | *
115 | * @return mixed
116 | */
117 | public function reboot()
118 | {
119 |
120 | return $this->getXenconnection()->host__reboot($this->getHostId());
121 | }
122 |
123 |
124 | /**
125 | * Get the host xen dmesg.
126 | *
127 | * @param
128 | *
129 | * @return mixed
130 | */
131 | public function dmesg()
132 | {
133 |
134 | return $this->getXenconnection()->host__dmesg($this->getHostId());
135 | }
136 |
137 | /**
138 | * Get the host xen dmesg, and clear the buffer
139 | *
140 | * @param
141 | *
142 | * @return mixed
143 | */
144 | public function dmesgClear()
145 | {
146 |
147 | return $this->getXenconnection()->host__dmesg_clear($this->getHostId());
148 | }
149 |
150 | /**
151 | * Get the host’s log file.
152 | *
153 | * @param
154 | *
155 | * @return mixed
156 | */
157 | public function getLog()
158 | {
159 |
160 | return $this->getXenconnection()->host__get_log($this->getHostId());
161 | }
162 |
163 | /**
164 | * List all supported methods.
165 | *
166 | * @param
167 | *
168 | * @return mixed
169 | */
170 | public function listMethods()
171 | {
172 |
173 | return $this->getXenconnection()->host__list_methods();
174 | }
175 |
176 |
177 | /**
178 | * Apply a new license to a host.
179 | *
180 | * @param $license The contents of the license file, base64 en-coded
181 | *
182 | * @return mixed
183 | */
184 | public function licenseApply($license = "")
185 | {
186 |
187 | return $this->getXenconnection()->host__license_apply($this->getHostId(), $license);
188 | }
189 |
190 |
191 | /**
192 | * Check this host can be evacuated.
193 | *
194 | * @param
195 | *
196 | * @return mixed
197 | */
198 | public function assertCanEvacuate()
199 | {
200 |
201 | return $this->getXenconnection()->host__assert_can_evacuate($this->getHostId());
202 | }
203 |
204 | /**
205 | * Migrate all VMs off of this host, where possible.
206 | *
207 | * @param
208 | *
209 | * @return mixed
210 | */
211 | public function evacuate()
212 | {
213 |
214 | return $this->getXenconnection()->host__evacuate($this->getHostId());
215 | }
216 |
217 |
218 | /**
219 | * This call queries the host’s clock for the current time.
220 | *
221 | * @param
222 | *
223 | * @return mixed
224 | */
225 | public function getServertime()
226 | {
227 |
228 | return $this->getXenconnection()->host__get_servertime($this->getHostId());
229 | }
230 |
231 | /**
232 | * This call queries the host's clock for the current time in the host’s local timezone.
233 | *
234 | * @param
235 | *
236 | * @return mixed
237 | */
238 | public function getServerLocaltime()
239 | {
240 |
241 | return $this->getXenconnection()->host__get_server_localtime($this->getHostId());
242 | }
243 |
244 | /**
245 | * Get the installed server SSL certificate. (pem file)
246 | *
247 | * @param
248 | *
249 | * @return mixed
250 | */
251 | public function getServerCertificate()
252 | {
253 |
254 | return $this->getXenconnection()->host__get_server_certificate($this->getHostId());
255 | }
256 |
257 |
258 | /**
259 | * Change to another edition, or reactivate the current edition after a license has expired. This may
260 | * be subject to the successful checkout of an appropriate license.
261 | *
262 | * @param $edition The requested edition, $force Update the license params even if the apply
263 | * call fails
264 | *
265 | * @return mixed
266 | */
267 | public function applyEdition($edition, $force = false)
268 | {
269 |
270 | return $this->getXenconnection()->host__apply_edition($this->getHostId(), $edition, $force);
271 | }
272 |
273 |
274 | /**
275 | * Refresh the list of installed Supplemental Packs.
276 | *
277 | * @param
278 | *
279 | * @return mixed
280 | */
281 | public function refreshPackInfo()
282 | {
283 |
284 | return $this->getXenconnection()->host__refresh_pack_info($this->getHostId());
285 | }
286 |
287 |
288 | /**
289 | * Enable the use of a local SR for caching purposes.
290 | *
291 | * @param string SR ref sr
292 | *
293 | * @return mixed
294 | */
295 | public function enableLocalStorageCaching($srRef)
296 | {
297 |
298 | return $this->getXenconnection()->host__enable_local_storage_caching($this->getHostId(), $srRef);
299 | }
300 |
301 |
302 | /**
303 | * Disable the use of a local SR for caching purposes.
304 | *
305 | * @param
306 | *
307 | * @return mixed
308 | */
309 | public function disableLocalStorageCaching()
310 | {
311 |
312 | return $this->getXenconnection()->host__disable_local_storage_caching($this->getHostId());
313 | }
314 |
315 | /**
316 | * Prepare to receive a VM, returning a token which can be passed to VM.migrate.
317 | *
318 | * @param string network ref network, array features
319 | *
320 | * @return mixed
321 | */
322 | public function migrateReceive($networkRef, $features = array())
323 | {
324 |
325 | return $this->getXenconnection()->host__migrate_receive($this->getHostId(), $networkRef, $features);
326 | }
327 |
328 | /**
329 | * Get the uuid field of the given host.
330 | *
331 | * @param
332 | *
333 | * @return mixed
334 | */
335 | public function getUUID()
336 | {
337 | return $this->getXenconnection()->host__get_uuid($this->getHostId());
338 | }
339 |
340 | /**
341 | * Get the name/label field of the given host.
342 | *
343 | * @param
344 | *
345 | * @return mixed
346 | */
347 | public function getNameLabel()
348 | {
349 | return $this->getXenconnection()->host__get_name_label($this->getHostId());
350 | }
351 |
352 | /**
353 | * Set the name/label field of the given host.
354 | *
355 | * @param string $name
356 | *
357 | * @return mixed
358 | */
359 | public function setNameLabel($name)
360 | {
361 | return $this->getXenconnection()->host__set_name_label($this->getHostId(), $name);
362 | }
363 |
364 | /**
365 | * Get the name/description field of the given HOST.
366 | *
367 | * @param
368 | *
369 | * @return XenResponse $response
370 | */
371 | public function getNameDescription()
372 | {
373 | return $this->getXenconnection()->host__get_name_description($this->getHostId());
374 | }
375 |
376 | /**
377 | * Set the name/description field of the given HOST.
378 | *
379 | * @param string name
380 | *
381 | * @return XenResponse $response
382 | */
383 | public function setNameDescription($name)
384 | {
385 | return $this->getXenconnection()->host__set_name_description($this->getHostId(), $name);
386 | }
387 |
388 | /**
389 | * Get the current operations field of the given HOST.
390 | *
391 | * @param
392 | *
393 | * @return XenResponse $response
394 | */
395 | public function getCurrentOperations()
396 | {
397 | return $this->getXenconnection()->host__get_current_operations($this->getHostId());
398 | }
399 |
400 | /**
401 | * Get the allowed operations field of the given HOST.
402 | *
403 | * @param
404 | *
405 | * @return XenResponse $response
406 | */
407 | public function getAllowedOperations()
408 | {
409 | return $this->getXenconnection()->host__get_allowed_operations($this->getHostId());
410 | }
411 |
412 | /**
413 | * Get the software version field of the given host.
414 | *
415 | * @param
416 | *
417 | * @return XenResponse $response
418 | */
419 | public function getSoftwareVersion()
420 | {
421 | return $this->getXenconnection()->host__get_software_version($this->getHostId());
422 | }
423 |
424 | /**
425 | * Get the other config field of the given HOST.
426 | *
427 | * @param
428 | *
429 | * @return XenResponse $response
430 | */
431 | public function getOtherConfig()
432 | {
433 | return $this->getXenconnection()->host__get_other_config($this->getHostId());
434 | }
435 |
436 | /**
437 | * Set the other config field of the given HOST.
438 | *
439 | * @param $value array
440 | *
441 | * @return XenResponse $response
442 | */
443 | public function setOtherConfig($array = array())
444 | {
445 | return $this->getXenconnection()->host__set_other_config($this->getHostId(), $array);
446 | }
447 |
448 | /**
449 | * Add the given key-value pair to the other config field of the given host.
450 | *
451 | * @param $key string
452 | *
453 | * @return XenResponse $response
454 | */
455 | public function addToOtherConfig($key, $value)
456 | {
457 | return $this->getXenconnection()->host__add_to_other_config($this->getHostId(), $key, $value);
458 | }
459 |
460 | /**
461 | * Remove the given key and its corresponding value from the other config field of the given host. If
462 | * the key is not in that Map, then do nothing.
463 | *
464 | * @param $key string
465 | *
466 | * @return XenResponse $response
467 | */
468 | public function removeFromOtherConfig($key)
469 | {
470 | return $this->getXenconnection()->host__remove_from_other_config($this->getHostId(), $key);
471 | }
472 |
473 | /**
474 | * Get the supported bootloaders field of the given host.
475 | *
476 | * @param
477 | *
478 | * @return XenResponse $response
479 | */
480 | public function getSupportedBootloaders()
481 | {
482 | return $this->getXenconnection()->host__get_supported_bootloaders($this->getHostId());
483 | }
484 |
485 | /**
486 | * Get the resident VMs field of the given host.
487 | *
488 | * @param
489 | *
490 | * @return XenResponse $response
491 | */
492 | public function getResidentVMs()
493 | {
494 | $response = $this->getXenconnection()->host__get_resident_VMs($this->getHostId());
495 | $VMs = array();
496 | if ($response->getValue() != "")
497 | {
498 | foreach ($response->getValue() as $key => $vm)
499 | {
500 | $xenVM = new XenVirtualMachine($this->getXenconnection(), null, $vm);
501 | $name = $xenVM->getNameLabel()->getValue();
502 | array_push($VMs, new XenVirtualMachine($this->getXenconnection(), $name, $vm));
503 | }
504 | $response->_setValue($VMs);
505 | }
506 |
507 | return $response;
508 | }
509 |
510 | /**
511 | * Get the patches field of the given host.
512 | *
513 | * @param
514 | *
515 | * @return XenResponse $response
516 | */
517 | public function getPatches()
518 | {
519 | return $this->getXenconnection()->host__get_patches($this->getHostId());
520 | }
521 |
522 | /**
523 | * Get the host CPUs field of the given host.
524 | *
525 | * @param
526 | *
527 | * @return XenResponse $response
528 | */
529 | public function getHostCPUs()
530 | {
531 | return $this->getXenconnection()->host__get_host_CPUs($this->getHostId());
532 | }
533 |
534 |
535 | /**
536 | * Get the cpu info field of the given host.
537 | *
538 | * @param
539 | *
540 | * @return XenResponse $response
541 | */
542 | public function getCPUInfo()
543 | {
544 | return $this->getXenconnection()->host__get_cpu_info($this->getHostId());
545 | }
546 |
547 | /**
548 | * Get the hostname of the given host.
549 | *
550 | * @param
551 | *
552 | * @return XenResponse $response
553 | */
554 | public function getHostname()
555 | {
556 | return $this->getXenconnection()->host__get_hostname($this->getHostId());
557 | }
558 |
559 | /**
560 | * Set the hostname of the given host.
561 | *
562 | * @param $name string
563 | *
564 | * @return XenResponse $response
565 | */
566 | public function setHostname($name)
567 | {
568 | return $this->getXenconnection()->host__set_hostname($this->getHostId(), $name);
569 | }
570 |
571 | /**
572 | * Get the address field of the given host.
573 | *
574 | * @param
575 | *
576 | * @return XenResponse $response
577 | */
578 | public function getAddress()
579 | {
580 | return $this->getXenconnection()->host__get_address($this->getHostId());
581 | }
582 |
583 | /**
584 | * Set the address field of the given host.
585 | *
586 | * @param $address string
587 | *
588 | * @return XenResponse $response
589 | */
590 | public function setAddress($address)
591 | {
592 | return $this->getXenconnection()->host__set_address($this->getHostId(), $address);
593 | }
594 |
595 | /**
596 | * Get the metrics field of the given host
597 | *
598 | * @param
599 | *
600 | * @return XenResponse $response
601 | */
602 | public function getMetrics()
603 | {
604 | return $this->getXenconnection()->host__get_metrics($this->getHostId());
605 | }
606 |
607 | /**
608 | * Get the license params field of the given host.
609 | *
610 | * @param
611 | *
612 | * @return XenResponse $response
613 | */
614 | public function getLicenseParam()
615 | {
616 | return $this->getXenconnection()->host__get_license_params($this->getHostId());
617 | }
618 |
619 | /**
620 | * Get the edition field of the given host.
621 | *
622 | * @param
623 | *
624 | * @return XenResponse $response
625 | */
626 | public function getEdition()
627 | {
628 | return $this->getXenconnection()->host__get_edition($this->getHostId());
629 | }
630 |
631 | /**
632 | * Get the license server field of the given host.
633 | *
634 | * @param
635 | *
636 | * @return XenResponse $response
637 | */
638 | public function getLicenseServer()
639 | {
640 | return $this->getXenconnection()->host__get_license_server($this->getHostId());
641 | }
642 |
643 | /**
644 | * Set the license server field of the given host.
645 | *
646 | * @param $license_server string
647 | *
648 | * @return XenResponse $response
649 | */
650 | public function setLicenseServer($license_server)
651 | {
652 | return $this->getXenconnection()->host__license_server($this->getHostId(), $license_server);
653 | }
654 |
655 | /**
656 | * Add the given key-value pair to the license server field of the given host.
657 | *
658 | * @param $key string
659 | *
660 | * @return XenResponse $response
661 | */
662 | public function addToLicenseServer($key, $value)
663 | {
664 | return $this->getXenconnection()->host__add_to_license_server($this->getHostId(), $key, $value);
665 | }
666 |
667 | /**
668 | * Remove the given key and its corresponding value from the license server field of the given host.
669 | * If the key is not in that Map, then do nothing.
670 | *
671 | * @param $key string
672 | *
673 | * @return XenResponse $response
674 | */
675 | public function removeFromLicenseServer($key)
676 | {
677 | return $this->getXenconnection()->host__remove_from_license_server($this->getHostId(), $key);
678 | }
679 |
680 | /**
681 | * Get the chipset info field of the given host.
682 | *
683 | * @param
684 | *
685 | * @return XenResponse $response
686 | */
687 | public function getChipsetInfo()
688 | {
689 | return $this->getXenconnection()->host__get_chipset_info($this->getHostId());
690 | }
691 | }
692 |
693 | ?>
694 |
--------------------------------------------------------------------------------
/src/Sircamp/Xenapi/Element/XenNetwork.php:
--------------------------------------------------------------------------------
1 | name = $name;
16 | $this->networkId = $networkId;
17 | }
18 |
19 | /**
20 | * Gets the value of name.
21 | *
22 | * @return mixed
23 | */
24 | public function getName()
25 | {
26 | return $this->name;
27 | }
28 |
29 | /**
30 | * Sets the value of name.
31 | *
32 | * @param mixed $name the name
33 | *
34 | * @return self
35 | */
36 | private function _setName($name)
37 | {
38 | $this->name = $name;
39 |
40 | return $this;
41 | }
42 |
43 | /**
44 | * Return a list of all the Networks known to the system.
45 | *
46 | * @param
47 | *
48 | * @return mixed
49 | */
50 | public function getAll()
51 | {
52 | return $this->getXenconnection()->network__get_all();
53 | }
54 | }
55 |
56 | ?>
57 |
--------------------------------------------------------------------------------
/src/Sircamp/Xenapi/Element/XenVirtualMachine.php:
--------------------------------------------------------------------------------
1 | name = $name;
17 | $this->vmId = $vmId;
18 | }
19 |
20 |
21 | /**
22 | * Return a list of all the VMs known to the system.
23 | *
24 | * @param
25 | *
26 | * @return mixed
27 | */
28 | public function getAll()
29 | {
30 | return $this->getXenconnection()->VM__get_all();
31 | }
32 |
33 | /**
34 | * Hard Reboot a VM by passing her uuid.
35 | *
36 | * @param mixed $VM the uuid of VM
37 | *
38 | * @return mixed
39 | */
40 | public function hardReboot()
41 | {
42 |
43 | return $this->getXenconnection()->VM__hard_reboot($this->getVmId());
44 | }
45 |
46 | /**
47 | * Shutdown a VM by passing her uuid.
48 | *
49 | * @param mixed $VM the uuid of VM
50 | *
51 | * @return mixed
52 | */
53 | public function hardShutdown()
54 | {
55 | return $this->getXenconnection()->VM__hard_shutdown($this->getVmId());
56 | }
57 |
58 | /**
59 | * Suspend a VM by passing her uuid.
60 | *
61 | * @param mixed $VM the uuid of VM
62 | *
63 | * @return mixed
64 | */
65 | public function suspend()
66 | {
67 | return $this->getXenconnection()->VM__suspend($this->getVmId());
68 | }
69 |
70 | /**
71 | * Resume a VM by passing her uuid.
72 | *
73 | * @param mixed $VM the uuid of VM
74 | *
75 | * @return mixed
76 | */
77 | public function resume()
78 | {
79 | return $this->getXenconnection()->VM__resume($this->getVmId());
80 | }
81 |
82 | /**
83 | * Awaken the specified VM and resume it on a particular Host. This can only be called when the
84 | * specified VM is in the Suspended state.
85 | *
86 | * @param mixed $VM the uuid of VM, $hostRef the ref of host whic resume the VM
87 | *
88 | * @return mixed
89 | */
90 | public function resumeOn($hostRef = null)
91 | {
92 | $hostRefString = "";
93 | if ($hostRef == null)
94 | {
95 | throw new \IllegalArgumentException("hostRef must be not NULL", 1);
96 |
97 | }
98 | else
99 | {
100 | if (is_object($hostRef))
101 | {
102 | $hostRefString = $hostRef->getHostId();
103 | }
104 | else
105 | {
106 | $hostRefString = $hostRef;
107 | }
108 | }
109 |
110 | return $this->getXenconnection()->VM__resume_on($this->getVmId(), $hostRefString);
111 | }
112 |
113 | /**
114 | * Migrate a VM to another Host. This can only be called when the specified VM is in the Running
115 | * state.
116 | *
117 | * @param mixed $VM the uuid of VM, $hostRef the target host
118 | * $optionsMap Extra configuration operations
119 | *
120 | * @return mixed
121 | */
122 |
123 | public function poolMigrate($hostRef = null, $optionsMap = array())
124 | {
125 | $hostRefString = "";
126 | if ($hostRef == null)
127 | {
128 | throw new \IllegalArgumentException("hostRef must be not NULL", 1);
129 |
130 | }
131 | else
132 | {
133 | if (is_object($hostRef))
134 | {
135 | $hostRefString = $hostRef->getHostId();
136 | }
137 | else
138 | {
139 | $hostRefString = $hostRef;
140 | }
141 | }
142 |
143 | return $this->getXenconnection()->VM__pool_migrate($this->getVmId(), $hostRefString, $optionsMap);
144 | }
145 |
146 | /**
147 | * Migrate the VM to another host. This can only be called when the specified VM is in the Running
148 | * state.
149 | *
150 | * @param mixed $VM the uuid of VM,
151 | * $def The result of a Host.migrate receive call.
152 | * $live The Live migration
153 | * $vdiMap of source VDI to destination SR
154 | * $vifMap of source VIF to destination network
155 | * $optionsMap Extra configuration operations
156 | *
157 | * @return mixed
158 | */
159 |
160 | public function migrateSend($dest, $vdiMap, $vifMap, $options, $live = false)
161 | {
162 | return $this->getXenconnection()->VM__migrate_send($this->getVmId(), $dest, $live, $vdiMap, $vifMap, $options);
163 | }
164 |
165 |
166 | /**
167 | * Assert whether a VM can be migrated to the specified destination.
168 | *
169 | * @param mixed $VM the uuid of VM,
170 | * $def The result of a Host.migrate receive call.
171 | * $live The Live migration
172 | * $vdiMap of source VDI to destination SR
173 | * $vifMap of source VIF to destination network
174 | * $optionsMap Extra configuration operations
175 | *
176 | * @return mixed
177 | */
178 | public function assertCanMigrate($dest, $vdiMap, $vifMap, $options, $live = false)
179 | {
180 | return $this->getXenconnection()->VM__assert_can_migrate($this->getVmId(), $dest, $live, $vdiMap, $vifMap, $options);
181 | }
182 |
183 | /**
184 | * Clean Reboot a VM by passing her uuid.
185 | *
186 | * @param mixed $VM the uuid of VM
187 | *
188 | * @return mixed
189 | */
190 | public function cleanReboot()
191 | {
192 | return $this->getXenconnection()->VM__clean_reboot($this->getVmId());
193 | }
194 |
195 | /**
196 | * Clean Shutdown a VM by passing her uuid.
197 | *
198 | * @param mixed $VM the uuid of VM
199 | *
200 | * @return mixed
201 | */
202 | public function cleanShutdown()
203 | {
204 | return $this->getXenconnection()->VM__clean_shutdown($this->getVmId());
205 | }
206 |
207 |
208 | /**
209 | * Pause a VM by passing her uuid.
210 | *
211 | * @param mixed $VM the uuid of VM
212 | *
213 | * @return mixed
214 | */
215 | public function pause()
216 | {
217 | return $this->getXenconnection()->VM__pause($this->getVmId());
218 | }
219 |
220 | /**
221 | * UnPause a VM by passing her uuid.
222 | *
223 | * @param mixed $VM the uuid of VM
224 | *
225 | * @return mixed
226 | */
227 | public function unpuse()
228 | {
229 | return $this->getXenconnection()->VM__unpause($this->getVmId());
230 | }
231 |
232 |
233 | /**
234 | * Start a VM by passing her uuid.
235 | *
236 | * @param mixed $VM the uuid of VM,
237 | * $pause Instantiate VM in paused state if set to true.
238 | * Attempt to force the VM to start. If this flag
239 | * is false then the VM may fail pre-boot safety
240 | * checks (e.g. if the CPU the VM last booted
241 | * on looks substantially different to the current one)
242 | *
243 | * @return mixed
244 | */
245 | public function start($pause = false, $force = true)
246 | {
247 |
248 | return $this->getXenconnection()->VM__start($this->getVmId(), $pause, $force);
249 | }
250 |
251 | /**
252 | * Start the specified VM on a particular host. This function can only be called with the VM is in
253 | * the Halted State.
254 | *
255 | * @param mixed $VM the uuid of VM, $hostRef the Host on which to start the VM
256 | * $pause Instantiate VM in paused state if set to true.
257 | * Attempt to force the VM to start. If this flag
258 | * is false then the VM may fail pre-boot safety
259 | * checks (e.g. if the CPU the VM last booted
260 | * on looks substantially different to the current one)
261 | *
262 | * @return mixed
263 | */
264 | public function startOn($hostRef, $pause = false, $force = true)
265 | {
266 |
267 | $hostRefString = "";
268 | if ($hostRef == null)
269 | {
270 | throw new \IllegalArgumentException("The where you want start new machine, must be set!", 1);
271 |
272 | }
273 | else
274 | {
275 | if (is_object($hostRef))
276 | {
277 | $hostRefString = $hostRef->getHostId();
278 | }
279 | else
280 | {
281 | $hostRefString = $hostRef;
282 | }
283 | }
284 |
285 | return $this->getXenconnection()->VM__start_on($this->getVmId(), $hostRefString, $pause, $force);
286 | }
287 |
288 | /**
289 | * Clone a VM by passing her uuid.
290 | *
291 | * @param mixed $VM the uuid of VM and $name the name of cloned vM
292 | *
293 | * @return mixed
294 | */
295 | public function clonevm($name)
296 | {
297 | return $this->getXenconnection()->VM__clone($this->getVmId(), $name);
298 | }
299 |
300 | /**
301 | * Get the UUID of a VM .
302 | *
303 | * @param
304 | *
305 | * @return mixed
306 | */
307 | function getUUID()
308 | {
309 | return $this->getXenconnection()->VM__get_uuid($this->getVmId());
310 | }
311 |
312 | /**
313 | * Get the consoles instances a VM by passing her uuid.
314 | *
315 | * @param
316 | *
317 | * @return mixed
318 | */
319 | function getConsoles()
320 | {
321 | return $this->getXenconnection()->VM__get_consoles($this->getVmId());
322 | }
323 |
324 | /**
325 | * Get the console UIID of a VM by passing her uuid.
326 | *
327 | * @param mixed $CN the uuid of conosle of VM
328 | *
329 | * @return mixed
330 | */
331 | function getConsoleUUID($CN)
332 | {
333 | return $this->getXenconnection()->console__get_uuid($CN);
334 | }
335 |
336 | /**
337 | * Get th VM status by passing her uuid.
338 | *
339 | * @param mixed $VM the uuid of VM and $name the name of cloned vM
340 | *
341 | * @return mixed
342 | */
343 | function getPowerState()
344 | {
345 | return $this->getXenconnection()->VM__get_power_state($this->getVmId());
346 | }
347 |
348 | /**
349 | * Reset the power-state of the VM to halted in the database only. (Used to recover from slave failures
350 | * in pooling scenarios by resetting the power-states of VMs running on dead slaves to halted.) This
351 | * is a potentially dangerous operation; use with care.
352 | *
353 | * @param mixed $VM the uuid of VM and $name the name of cloned vM
354 | *
355 | * @return mixed
356 | */
357 | function powerStateReset()
358 | {
359 | return $this->getXenconnection()->VM__power_state_reset($this->getVmId());
360 | }
361 |
362 |
363 | /**
364 | * Get the VM guest metrics by passing her uuid.
365 | *
366 | * @param mixed $VM the uuid of VM and $name the name of cloned vM
367 | *
368 | * @return mixed
369 | */
370 | function getGuestMetrics()
371 | {
372 | $VMG = $this->getXenconnection()->VM__get_guest_metrics($this->getVmId());
373 |
374 | return $this->getXenconnection()->VM_guest_metrics__get_record($VMG->getValue());
375 | }
376 |
377 | /**
378 | * Get the VM metrics by passing her uuid.
379 | *
380 | * @param mixed $VM the uuid of VM and $name the name of cloned vM
381 | *
382 | * @return mixed
383 | */
384 | function getMetrics()
385 | {
386 | $VMG = $this->getXenconnection()->VM__get_metrics($this->getVmId());
387 |
388 | return $this->getXenconnection()->VM_metrics__get_record($VMG->getValue());
389 | }
390 |
391 |
392 | /**
393 | * Get the VM stats by passing her uuid.
394 | *
395 | * @param
396 | *
397 | * @return XenResponse $response
398 | */
399 | function getStats()
400 | {
401 |
402 | $user = $this->getXenconnection()->getUser();
403 | $password = $this->getXenconnection()->getPassword();
404 | $ip = $this->getXenconnection()->getUrl();
405 | $uuid = $this->getUUID($this->getVmId());
406 |
407 | $url = 'http://' . $user . ':' . $password . '@' . $ip . '/vm_rrd?uuid=' . $uuid->getValue() . '&start=1000000000';
408 |
409 |
410 | $client = new Client();
411 | $response = $client->get($url);
412 |
413 | $body = $response->getBody();
414 | $xml = "";
415 |
416 | while (!$body->eof())
417 | {
418 | $xml .= $body->read(1024);
419 | }
420 |
421 | $response = new XenResponse(array('Value' => array(0 => '')));
422 |
423 | if (Validator::string()->validate($xml))
424 | {
425 | $response = new XenResponse(array('Value' => $xml, 'Status' => 'Success'));
426 | }
427 | else
428 | {
429 | $response = new XenResponse(array('Value' => '', 'Status' => 'Failed'));
430 | }
431 |
432 | return $response;
433 | }
434 |
435 | /**
436 | * Get the VM disk space by passing her uuid.
437 | *
438 | * @param mixe $size the currency of size of disk space
439 | *
440 | * @return XenResponse $response
441 | */
442 | function getDiskSpace($size = null)
443 | {
444 | $VBD = $this->getXenconnection()->VBD__get_all();
445 | $memory = 0;
446 | foreach ($VBD->getValue() as $bd)
447 | {
448 | $responsevm = $this->getXenconnection()->VBD__get_VM($bd);
449 | $responsetype = $this->getXenconnection()->VBD__get_type($bd);
450 |
451 | if ($responsevm->getValue() == $this->getVmId() && $responsetype->getValue() == "Disk")
452 | {
453 | $VDI = $this->getXenconnection()->VBD__get_VDI($bd);
454 | $memory += intval($this->getXenconnection()->VDI__get_virtual_size($VDI->getValue())->getValue());
455 | }
456 | }
457 |
458 | $response = null;
459 | if (Validator::numeric()->validate($memory))
460 | {
461 |
462 | return new XenResponse(array('Value' => $memory, 'Status' => 'Success'));
463 | }
464 | else
465 | {
466 | return new XenResponse(array('Value' => 0, 'Status' => 'Failed'));
467 | }
468 |
469 | return $response;
470 | }
471 |
472 | /**
473 | * Gets the value of name.
474 | *
475 | * @return mixed
476 | */
477 | public function getName()
478 | {
479 | return $this->name;
480 | }
481 |
482 | /**
483 | * Sets the value of name.
484 | *
485 | * @param mixed $name the name
486 | *
487 | * @return self
488 | */
489 | private function _setName($name)
490 | {
491 | $this->name = $name;
492 |
493 | return $this;
494 | }
495 |
496 | /**
497 | * Gets the value of vmId.
498 | *
499 | * @return mixed
500 | */
501 | public function getVmId()
502 | {
503 | return $this->vmId;
504 | }
505 |
506 | /**
507 | * Sets the value of vmId.
508 | *
509 | * @param mixed $vmId the vm id
510 | *
511 | * @return self
512 | */
513 | private function _setVmId($vmId)
514 | {
515 | $this->vmId = $vmId;
516 |
517 | return $this;
518 | }
519 |
520 | /**
521 | * Snapshots the specified VM, making a new VM.
522 | * Snapshot automatically exploits the capabilities of the underlying storage repository
523 | * in which the VM’s disk images are stored
524 | *
525 | * @param string $name the name of snapshot
526 | *
527 | * @return XenResponse $response
528 | */
529 | public function snapshot($name)
530 | {
531 | return $this->getXenconnection()->VM__snapshot($this->getVmId(), $name);
532 | }
533 |
534 | //TOFIX
535 |
536 | /**
537 | * Snapshots the specified VM with quiesce, making a new VM.
538 | * Snapshot automatically exploits the capabilities of the underlying
539 | * storage repository in which the VM’s disk images are stored
540 | *
541 | * @param string $name the name of snapshot
542 | *
543 | * @return XenResponse $response
544 | */
545 | public function snapshotWithQuiesce($name)
546 | {
547 | return $this->getXenconnection()->VM__snapshot_with_quiesce($this->getVmId(), $name);
548 | }
549 |
550 | /**
551 | * Get the snapshot info field of the given VM.
552 | *
553 | * @param
554 | *
555 | * @return XenResponse $response
556 | */
557 | public function getSnapshotInfo()
558 | {
559 | return $this->getXenconnection()->VM__get_snapshot_info($this->getVmId());
560 | }
561 |
562 |
563 | /**
564 | * Copied the specified VM, making a new VM. Unlike clone, copy does not exploits the capabilities
565 | * of the underlying storage repository in which the VM’s disk images are stored. Instead, copy
566 | * guarantees that the disk images of the newly created VM will be ’full disks’ - i.e. not part of a
567 | * CoW chain. This function can only be called when the VM is in the Halted State
568 | *
569 | * @param string $name the name of new vm
570 | *
571 | * @return XenResponse $response
572 | */
573 | public function copy($name)
574 | {
575 | return $this->getXenconnection()->VM__copy($this->getVmId(), $name, "");
576 | }
577 |
578 |
579 | /**
580 | * Destroy the specified VM. The VM is completely removed from the system. This function can
581 | * only be called when the VM is in the Halted State.
582 | *
583 | * @param
584 | *
585 | * @return XenResponse $response
586 | */
587 | public function destroy()
588 | {
589 | return $this->getXenconnection()->VM__destroy($this->getVmId());
590 | }
591 |
592 | /**
593 | * Reverts the specified VM to a previous state
594 | *
595 | * @param string $snapshotID the ID of snapshot
596 | *
597 | * @return XenResponse $response
598 | */
599 | public function revert($snapshotID)
600 | {
601 | return $this->getXenconnection()->VM__revert($this->getVmId(), $snapshotID);
602 | }
603 |
604 | /**
605 | * Checkpoints the specified VM, making a new VM. Checkpoint automatically exploits the capabil-
606 | * ities of the underlying storage repository in which the VM’s disk images are stored (e.g. Copy on
607 | * Write) and saves the memory image as well
608 | *
609 | * @param string $name the name of new VPS
610 | *
611 | * @return XenResponse $response
612 | */
613 | public function checkpoint($name)
614 | {
615 | return $this->getXenconnection()->VM__checkpoint($this->getVmId(), $name);
616 | }
617 |
618 |
619 | /**
620 | * Set this VM’s start delay in seconds.
621 | *
622 | * @param int seconds of delay
623 | *
624 | * @return XenResponse $response
625 | */
626 | public function setStartDelay($seconds)
627 | {
628 | return $this->getXenconnection()->VM__set_start_delay($this->getVmId(), $seconds);
629 | }
630 |
631 | /**
632 | * Set this VM’s start delay in seconds.
633 | *
634 | * @param int seconds of delay
635 | *
636 | * @return XenResponse $response
637 | */
638 | public function setShutdownDelay($seconds)
639 | {
640 | return $this->getXenconnection()->VM__set_shutdown_delay($this->getVmId(), $seconds);
641 | }
642 |
643 | /**
644 | * Get the start delay field of the given VM.
645 | *
646 | * @param
647 | *
648 | * @return XenResponse $response
649 | */
650 | public function getStartDelay()
651 | {
652 | return $this->getXenconnection()->VM__get_start_delay($this->getVmId());
653 | }
654 |
655 | /**
656 | * Get the shutdown delay field of the given VM.
657 | *
658 | * @param
659 | *
660 | * @return XenResponse $response
661 | */
662 | public function getShutdownDelay()
663 | {
664 | return $this->getXenconnection()->VM__get_shutdown_delay($this->getVmId());
665 | }
666 |
667 | /**
668 | * Get the current operations field of the given VM.
669 | *
670 | * @param
671 | *
672 | * @return XenResponse $response
673 | */
674 | public function getCurrentOperations()
675 | {
676 | return $this->getXenconnection()->VM__get_current_operations($this->getVmId());
677 | }
678 |
679 | /**
680 | * Get the allowed operations field of the given VM.
681 | *
682 | * @param
683 | *
684 | * @return XenResponse $response
685 | */
686 | public function getAllowedOperations()
687 | {
688 | return $this->getXenconnection()->VM__get_allowed_operations($this->getVmId());
689 | }
690 |
691 |
692 | /**
693 | * Get the name/description field of the given VM.
694 | *
695 | * @param
696 | *
697 | * @return XenResponse $response
698 | */
699 | public function getNameDescription()
700 | {
701 | return $this->getXenconnection()->VM__get_name_description($this->getVmId());
702 | }
703 |
704 | /**
705 | * Set the name/description field of the given VM.
706 | *
707 | * @param string name
708 | *
709 | * @return XenResponse $response
710 | */
711 | public function setNameDescription($name)
712 | {
713 | return $this->getXenconnection()->VM__set_name_description($this->getVmId(), $name);
714 | }
715 |
716 | /**
717 | * Get the is a template field of the given VM.
718 | *
719 | * @param
720 | *
721 | * @return XenResponse $response
722 | */
723 | public function getIsATemplate()
724 | {
725 | return $this->getXenconnection()->VM__get_is_a_template($this->getVmId());
726 | }
727 |
728 | /**
729 | * Set the is a template field of the given VM.
730 | *
731 | * @param bool $template
732 | *
733 | * @return XenResponse $response
734 | */
735 | public function setIsATemplate($template)
736 | {
737 | return $this->getXenconnection()->VM__set_is_a_template($this->getVmId(), $template);
738 | }
739 |
740 |
741 | /**
742 | * Get the resident on field of the given VM.
743 | *
744 | * @param
745 | *
746 | * @return XenResponse $response
747 | */
748 | public function getResidentOn()
749 | {
750 | $xenHost = null;
751 | $response = $this->getXenconnection()->VM__get_resident_on($this->getVmId());
752 | if ($response->getValue() != "")
753 | {
754 | $xenHost = new XenHost($this->getXenconnection(), null, $response->getValue());
755 | $name = $xenHost->getNameLabel()->getValue();
756 | $xenHost->_setName($name);
757 | }
758 | $response->_setValue($xenHost);
759 |
760 | return $response;
761 | }
762 |
763 | /**
764 | * Get the platform field of the given VM.
765 | *
766 | * @param
767 | *
768 | * @return XenResponse $response
769 | */
770 | public function getPlatform()
771 | {
772 | return $this->getXenconnection()->VM__get_platform($this->getVmId());
773 | }
774 |
775 |
776 | /**
777 | * Set the platform field of the given VM.
778 | *
779 | * @param $value array
780 | *
781 | * @return XenResponse $response
782 | */
783 | public function setPlatform($value = array())
784 | {
785 | return $this->getXenconnection()->VM__set_platform($this->getVmId(), $value);
786 | }
787 |
788 |
789 | /**
790 | * Get the other config field of the given VM.
791 | *
792 | * @param
793 | *
794 | * @return XenResponse $response
795 | */
796 | public function getOtherConfig()
797 | {
798 | return $this->getXenconnection()->VM__get_other_config($this->getVmId());
799 | }
800 |
801 | /**
802 | * Set the other config field of the given VM.
803 | *
804 | * @param $value array
805 | *
806 | * @return XenResponse $response
807 | */
808 | public function setOtherConfig($array = array())
809 | {
810 | return $this->getXenconnection()->VM__set_other_config($this->getVmId(), $array);
811 | }
812 |
813 | /**
814 | * Add the given key-value pair to the other config field of the given vm.
815 | *
816 | * @param $key string
817 | *
818 | * @return XenResponse $response
819 | */
820 | public function addToOtherConfig($key, $value)
821 | {
822 | return $this->getXenconnection()->VM__add_to_other_config($this->getVmId(), $key, $value);
823 | }
824 |
825 | /**
826 | * Remove the given key and its corresponding value from the other config field of the given vm. If
827 | * the key is not in that Map, then do nothing.
828 | *
829 | * @param $key string
830 | *
831 | * @return XenResponse $response
832 | */
833 | public function removeFromOtherConfig($key)
834 | {
835 | return $this->getXenconnection()->VM__remove_from_other_config($this->getVmId(), $key);
836 | }
837 |
838 | /**
839 | * Get name label VM.
840 | *
841 | * @param
842 | *
843 | * @return XenResponse $response
844 | */
845 | public function getNameLabel()
846 | {
847 | return $this->getXenconnection()->VM__get_name_label($this->getVmId());
848 | }
849 |
850 | }
851 |
852 | ?>
853 |
854 |
--------------------------------------------------------------------------------
/src/Sircamp/Xenapi/Exception/XenConnectionException.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/Sircamp/Xenapi/Xen.php:
--------------------------------------------------------------------------------
1 | validate($url))
19 | {
20 |
21 | throw new \InvalidArgumentException("'url' value mast be an ipv4 address", 1);
22 |
23 | }
24 | if (!Validator::stringType()->validate($user))
25 | {
26 | throw new \InvalidArgumentException("'user' value mast be an non empty string", 1);
27 | }
28 |
29 | if (!Validator::stringType()->validate($password))
30 | {
31 | throw new \InvalidArgumentException("'password' value mast be an non empty string", 1);
32 | }
33 |
34 | $this->xenconnection = new XenConnection();
35 | try
36 | {
37 | $this->xenconnection->_setServer($url, $user, $password);
38 | }
39 | catch (\Exception $e)
40 | {
41 | die($e->getMessage());
42 | }
43 | }
44 |
45 | /**
46 | * Get VM inside Hypervisor from name.
47 | *
48 | * @param mixed $name the name of VM
49 | *
50 | * @return mixed
51 | */
52 | public function getVMByNameLabel($name): XenVirtualMachine
53 | {
54 | $response = new XenResponse($this->xenconnection->VM__get_by_name_label($name));
55 |
56 | return new XenVirtualMachine($this->xenconnection, $name, $response->getValue()[0]);
57 | }
58 |
59 | /**
60 | * Get HOST from name.
61 | *
62 | * @param mixed $name the name of HOST
63 | *
64 | * @return mixed
65 | */
66 | public function getHOSTByNameLabel($name)
67 | {
68 | $response = new XenResponse($this->xenconnection->host__get_by_name_label($name));
69 |
70 | return new XenHost($this->xenconnection, $name, $response->getValue()[0]);
71 | }
72 |
73 |
74 | }
75 |
76 | ?>
--------------------------------------------------------------------------------
/tests/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sirCamp/Xenapi/44b6952b50141d8c40a33a5463b1f01b8f250b8f/tests/.gitkeep
--------------------------------------------------------------------------------