├── README.md └── solus.php /README.md: -------------------------------------------------------------------------------- 1 | php-solusvm-api 2 | =============== 3 | 4 | PHP Library for SolusVM's XMLRPC API 5 | 6 | 7 | 8 | * @author Benton Snyder 9 | * @website 10 | * @created 12/22/2012 11 | * @updated 4/2/2015 12 | 13 | ##### Usage 14 | 15 | ``` 16 | require('solus.php'); 17 | $solus = new Solus('https://solus.example.com:5656/api/admin', 'AFDi7342678A', 'SDFDJ83AF8AFA'); 18 | $clients = $solus->listClients(); 19 | ``` 20 | -------------------------------------------------------------------------------- /solus.php: -------------------------------------------------------------------------------- 1 | url = $url; 28 | $this->id = $id; 29 | $this->key = $key; 30 | } 31 | 32 | /** 33 | * Executes xmlrpc api call with given parameters 34 | * 35 | * @access private 36 | * @param array 37 | * @return str 38 | */ 39 | private function execute(array $params) { 40 | $params["id"] = $this->id; 41 | $params["key"] = $this->key; 42 | $params["rdtype"] = "json"; 43 | 44 | $ch = curl_init(); 45 | curl_setopt($ch, CURLOPT_URL, $this->url . "/command.php"); 46 | curl_setopt($ch, CURLOPT_POST, 1); 47 | curl_setopt($ch, CURLOPT_TIMEOUT, 20); 48 | curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); 49 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 50 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 51 | curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:")); 52 | curl_setopt($ch, CURLOPT_HEADER, 0); 53 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 54 | curl_setopt($ch, CURLOPT_POSTFIELDS, $params); 55 | $response = curl_exec($ch); 56 | 57 | if($response === false) 58 | throw new Exception("Curl error: " . curl_error($ch)); 59 | 60 | curl_close($ch); 61 | return $response; 62 | } 63 | 64 | /** 65 | * Get serial console details 66 | * 67 | * https://documentation.solusvm.com/display/DOCS/Serial+Console 68 | */ 69 | public function console($serverID, $access, $time) { 70 | if(!is_numeric($serverID)) 71 | throw new Exception("Invalid ServerID"); 72 | 73 | return $this->execute(array("action"=>"vserver-console", "vserverid"=>$serverID, "access"=>$access, "time"=>$time)); 74 | } 75 | 76 | /** 77 | * Disable TUN/TAP 78 | * 79 | * https://documentation.solusvm.com/pages/viewpage.action?pageId=558494 80 | */ 81 | public function disableTUN($serverID) { 82 | if(!is_numeric($serverID)) 83 | throw new Exception("Invalid ServerID"); 84 | 85 | return $this->execute(array("action"=>"vserver-tun-disable", "vserverid"=>$serverID)); 86 | } 87 | 88 | /** 89 | * Enable TUN/TAP 90 | * 91 | * https://documentation.solusvm.com/pages/viewpage.action?pageId=558498 92 | */ 93 | public function enableTUN($serverID) { 94 | if(!is_numeric($serverID)) 95 | throw new Exception("Invalid ServerID"); 96 | 97 | return $this->execute(array("action"=>"vserver-tun-enable", "vserverid"=>$serverID)); 98 | } 99 | 100 | /** 101 | * PAE Enable/Disable 102 | * 103 | * https://documentation.solusvm.com/pages/viewpage.action?pageId=558505 104 | */ 105 | public function paestatus($serverID, $pae) { 106 | if(!is_numeric($serverID)) 107 | throw new Exception("Invalid ServerID"); 108 | 109 | return $this->execute(array("action"=>"vserver-pae", "vserverid"=>$serverID, "pae"=>$pae)); 110 | } 111 | 112 | /** 113 | * Reboots specified vserver 114 | * 115 | * https://documentation.solusvm.com/display/DOCS/Reboot+Virtual+Server 116 | * 117 | * @access public 118 | * @param int 119 | * @return str 120 | */ 121 | public function reboot($serverID) { 122 | if(!is_numeric($serverID)) 123 | throw new Exception("Invalid ServerID"); 124 | 125 | return $this->execute(array("action"=>"vserver-reboot", "vserverid"=>$serverID)); 126 | } 127 | 128 | /** 129 | * Boots specified vserver 130 | * 131 | * https://documentation.solusvm.com/display/DOCS/Boot+Virtual+Server 132 | * 133 | * @access public 134 | * @param int 135 | * @return str 136 | */ 137 | public function boot($serverID) { 138 | if(!is_numeric($serverID)) 139 | throw new Exception("Invalid ServerID"); 140 | 141 | return $this->execute(array("action"=>"vserver-boot", "vserverid"=>$serverID)); 142 | } 143 | 144 | /** 145 | * Shuts down specified vserver 146 | * 147 | * https://documentation.solusvm.com/display/DOCS/Shutdown+Virtual+Server 148 | * 149 | * @access public 150 | * @param int 151 | * @return str 152 | */ 153 | public function shutdown($serverID) { 154 | if(!is_numeric($serverID)) 155 | throw new Exception("Invalid ServerID"); 156 | 157 | return $this->execute(array("action"=>"vserver-shutdown", "vserverid"=>$serverID)); 158 | } 159 | 160 | /** 161 | * Retrives list of available ISO images 162 | * 163 | * https://documentation.solusvm.com/display/DOCS/List+ISO+Images 164 | * 165 | * @access public 166 | * @param str 167 | * @return str 168 | */ 169 | public function listISO($type) { 170 | if(!in_array($type, array("xen hvm", "kvm", "xen", "openvz"))) 171 | throw new Exception("Invalid Type"); 172 | 173 | return $this->execute(array("action"=>"listiso", "type"=>$type)); 174 | } 175 | 176 | /** 177 | * Mounts ISO specified by its filename to vserver specified by ID 178 | * 179 | * https://documentation.solusvm.com/display/DOCS/Mount+ISO 180 | * 181 | * @access public 182 | * @param int, str 183 | * @return str 184 | */ 185 | public function mountISO($serverID, $iso) { 186 | if(!is_numeric($serverID)) 187 | throw new Exception("Invalid ServerID"); 188 | 189 | return $this->execute(array("action"=>"vserver-mountiso", "vserverid"=>$serverID, "iso"=>$iso)); 190 | } 191 | 192 | /** 193 | * Unmounts the currently mounted ISO of a vserver specified by its ID 194 | * 195 | * https://documentation.solusvm.com/display/DOCS/Unmount+ISO 196 | * 197 | * @access public 198 | * @param int 199 | * @return str 200 | */ 201 | public function unmountISO($serverID) { 202 | if(!is_numeric($serverID)) 203 | throw new Exception("Invalid ServerID"); 204 | 205 | return $this->execute(array("action"=>"vserver-unmountiso", "vserverid"=>$serverID)); 206 | } 207 | 208 | /** 209 | * Updates the boot order of a vserver specified by its ID 210 | * 211 | * https://documentation.solusvm.com/display/DOCS/Change+Boot+Order 212 | * 213 | * @access public 214 | * @param int, str 215 | * @return str 216 | */ 217 | public function changeBootOrder($serverID, $bootOrder) { 218 | if(!is_numeric($serverID)) 219 | throw new Exception("Invalid ServerID"); 220 | 221 | if(!in_array($bootOrder, array("cd", "dc", "c", "d"))) 222 | throw new Exception("Invalid bootorder"); 223 | 224 | return $this->execute(array("action"=>"vserver-bootorder", "vserverid"=>$serverID, "bootorder"=>$bootOrder)); 225 | } 226 | 227 | /** 228 | * Retrieves VNC ip, port and password for vserver specified by its ID 229 | * 230 | * https://documentation.solusvm.com/display/DOCS/VNC+Info 231 | * 232 | * @access public 233 | * @param int 234 | * @return str 235 | */ 236 | public function getVNC($serverID) { 237 | if(!is_numeric($serverID)) 238 | throw new Exception("Invalid ServerID"); 239 | 240 | return $this->execute(array("action"=>"vserver-vnc", "vserverid"=>$serverID)); 241 | } 242 | 243 | /** 244 | * Retrieves details of vserver specified by its ID 245 | * 246 | * https://documentation.solusvm.com/display/DOCS/Virtual+Server+Information 247 | * 248 | * @access public 249 | * @param int 250 | * @return str 251 | */ 252 | public function getServerInfo($serverID) { 253 | if(!is_numeric($serverID)) 254 | throw new Exception("Invalid ServerID"); 255 | 256 | return $this->execute(array("action"=>"vserver-info", "vserverid"=>$serverID)); 257 | } 258 | 259 | /** 260 | * Retrieves server state information of vserver specified by its ID 261 | * 262 | * https://documentation.solusvm.com/display/DOCS/Virtual+Server+State 263 | * 264 | * @access public 265 | * @param int 266 | * @return str 267 | */ 268 | public function getServerState($serverID,$nostatus,$nographs) { 269 | if(!is_numeric($serverID)) 270 | throw new Exception("Invalid ServerID"); 271 | 272 | return $this->execute(array("action"=>"vserver-infoall", "vserverid"=>$serverID, "nostatus"=>$nostatus, "nographs"=>$nographs)); 273 | } 274 | 275 | /** 276 | * Retrieves current status of vserver specified by ID 277 | * 278 | * https://documentation.solusvm.com/display/DOCS/Virtual+Server+Status 279 | * 280 | * @access public 281 | * @param int 282 | * @return str 283 | */ 284 | public function getServerStatus($serverID) { 285 | if(!is_numeric($serverID)) 286 | throw new Exception("Invalid ServerID"); 287 | 288 | return $this->execute(array("action"=>"vserver-status", "vserverid"=>$serverID)); 289 | } 290 | 291 | /** 292 | * Authenticates client credentials 293 | * 294 | * https://documentation.solusvm.com/display/DOCS/Client+Authenticate 295 | * 296 | * @access public 297 | * @param str, str 298 | * @return str 299 | */ 300 | public function authenticateClient($username, $password) { 301 | if(!ctype_alnum($username)) 302 | throw new Exception("Invalid Username"); 303 | 304 | return $this->execute(array("action"=>"vserver-authenticate", "username"=>$username, "password"=>$password)); 305 | } 306 | 307 | /** 308 | * Updates hostname associated with vserver specified by its ID 309 | * 310 | * https://documentation.solusvm.com/display/DOCS/Change+Hostname 311 | * 312 | * @access public 313 | * @param int, str 314 | * @return str 315 | */ 316 | public function changeHostname($serverID, $hostname) { 317 | if(!is_numeric($serverID)) 318 | throw new Exception("Invalid ServerID"); 319 | 320 | if(!preg_match('/[\w-.]+/', $hostname)) 321 | throw new Exception("Invalid Hostname"); 322 | 323 | return $this->execute(array("action"=>"vserver-hostname", "vserverid"=>$serverID, "hostname"=>$hostname)); 324 | } 325 | 326 | /** 327 | * Retrieves client list 328 | * 329 | * https://documentation.solusvm.com/display/DOCS/List+Clients 330 | * 331 | * @access public 332 | * @param 333 | * @return str 334 | */ 335 | public function listClients() { 336 | return $this->execute(array("action"=>"client-list")); 337 | } 338 | 339 | /** 340 | * Retrieves a list of virtual servers on specified node 341 | * 342 | * https://documentation.solusvm.com/display/DOCS/List+Virtual+Servers 343 | * 344 | * @access public 345 | * @param int 346 | * @return str 347 | */ 348 | public function listServers($nodeid) { 349 | if(!is_numeric($nodeid)) 350 | throw new Exception("Invalid NodeID"); 351 | 352 | return $this->execute(array("action"=>"node-virtualservers", "nodeid"=>$nodeid)); 353 | } 354 | 355 | /** 356 | * Determines if a vserver exists as specified by its ID 357 | * 358 | * https://documentation.solusvm.com/display/DOCS/Check+Exists 359 | * 360 | * @access public 361 | * @param int 362 | * @return str 363 | */ 364 | public function vserverExists($serverID) { 365 | if(!is_numeric($serverID)) 366 | throw new Exception("Invalid ServerID"); 367 | 368 | return $this->execute(array("action"=>"vserver-checkexists", "vserverid"=>$serverID)); 369 | } 370 | 371 | /** 372 | * Adds an IP address to specified vserver 373 | * 374 | * https://documentation.solusvm.com/display/DOCS/Add+IP+Address 375 | * 376 | * @access public 377 | * @param int, str, bool 378 | * @return str 379 | */ 380 | public function addIP($serverID, $ipv4addr=0, $forceaddip=0) { 381 | if(!is_numeric($serverID)) 382 | throw new Exception("Invalid ServerID"); 383 | 384 | $args = array( 385 | "action" => "vserver-addip", 386 | "vserverid" => $serverID 387 | ); 388 | 389 | if($ipv4addr) { 390 | if(filter_var($ipv4addr, FILTER_VALIDATE_IP) === false) 391 | throw new Exception("Invalid IPv4 Address"); 392 | 393 | if(filter_var($forceaddip, FILTER_VALIDATE_BOOLEAN) === false) 394 | throw new Exception("forceaddip must be boolean"); 395 | 396 | $args['ipv4addr'] = $ipv4addr; 397 | $args['forceaddip'] = $forceaddip; 398 | } 399 | 400 | return $this->execute($args); 401 | } 402 | 403 | /** 404 | * Deletes an IP address from the specified vserver 405 | * 406 | * https://documentation.solusvm.com/display/DOCS/Delete+IP+Address 407 | * 408 | * @access public 409 | * @param int, str 410 | * @return str 411 | */ 412 | public function deleteIP($serverID, $ipaddr) { 413 | if(!is_numeric($serverID)) 414 | throw new Exception("Invalid ServerID"); 415 | 416 | if(filter_var($ipaddr, FILTER_VALIDATE_IP) === false) 417 | throw new Exception("Invalid IPv4 Address"); 418 | 419 | return $this->execute(array("action"=>"vserver-delip", "vserverid"=>$serverID, "ipaddr"=>$ipaddr)); 420 | } 421 | 422 | /** 423 | * Updates owner of specified vserver 424 | * 425 | * https://documentation.solusvm.com/display/DOCS/Change+Owner 426 | * 427 | * @access public 428 | * @param int, int 429 | * @return str 430 | */ 431 | public function changeOwner($serverID, $clientID) { 432 | if(!is_numeric($serverID)) 433 | throw new Exception("Invalid ServerID"); 434 | 435 | if(!is_numeric($clientID)) 436 | throw new Exception("Invalid ClientID"); 437 | 438 | return $this->execute(array("action"=>"vserver-changeowner", "vserverid"=>$serverID, "clientid"=>$clientID)); 439 | } 440 | 441 | /** 442 | * Updates vserver plan 443 | * 444 | * https://documentation.solusvm.com/display/DOCS/Change+Plan 445 | * 446 | * @access public 447 | * @param int, str, bool 448 | * @return str 449 | */ 450 | public function changePlan($serverID, $plan, $changeHDD=false) { 451 | if(!is_numeric($serverID)) 452 | throw new Exception("Invalid ServerID"); 453 | 454 | if(filter_var($changeHDD, FILTER_VALIDATE_BOOLEAN) === false) 455 | throw new Exception("changeHDD must be boolean"); 456 | 457 | return $this->execute(array("action"=>"vserver-change", "vserverid"=>$serverID, "plan"=>$plan, "changehdd"=>$changeHDD)); 458 | } 459 | 460 | /** 461 | * Terminates specified vserver 462 | * 463 | * https://documentation.solusvm.com/display/DOCS/Terminate+Virtual+Server 464 | * 465 | * @access public 466 | * @param int, bool 467 | * @return str 468 | */ 469 | public function terminate($serverID, $deleteclient=false) { 470 | if(!is_numeric($serverID)) 471 | throw new Exception("Invalid ServerID"); 472 | 473 | if(filter_var($deleteclient, FILTER_VALIDATE_BOOLEAN) === false) 474 | throw new Exception("deleteclient must be boolean"); 475 | 476 | return $this->execute(array("action"=>"vserver-terminate", "vserverid"=>$serverID, "deleteclient"=>$deleteclient)); 477 | } 478 | 479 | /** 480 | * Suspends specified vserver 481 | * 482 | * https://documentation.solusvm.com/display/DOCS/Suspend+Virtual+Server 483 | * 484 | * @access public 485 | * @param int 486 | * @return str 487 | */ 488 | public function suspend($serverID) { 489 | if(!is_numeric($serverID)) 490 | throw new Exception("Invalid ServerID"); 491 | 492 | return $this->execute(array("action"=>"vserver-suspend", "vserverid"=>$serverID)); 493 | } 494 | 495 | /** 496 | * Unsuspends specified vserver 497 | * 498 | * https://documentation.solusvm.com/display/DOCS/Unsuspend+Virtual+Server 499 | * 500 | * @access public 501 | * @param int 502 | * @return str 503 | */ 504 | public function unsuspend($serverID) { 505 | if(!is_numeric($serverID)) 506 | throw new Exception("Invalid ServerID"); 507 | 508 | return $this->execute(array("action"=>"vserver-unsuspend", "vserverid"=>$serverID)); 509 | } 510 | 511 | /** 512 | * Updates vserver's bandwidth limit 513 | * 514 | * https://documentation.solusvm.com/display/DOCS/Change+Bandwidth+Limits 515 | * 516 | * @access public 517 | * @param int, int, int 518 | * @return str 519 | */ 520 | public function changeBandwidth($serverID, $limit, $overlimit) { 521 | if(!is_numeric($serverID)) 522 | throw new Exception("Invalid ServerID"); 523 | 524 | if(!is_numeric($limit)) 525 | throw new Exception("Invalid Limit"); 526 | 527 | if(!is_numeric($overlimit)) 528 | throw new Exception("Invalid OverLimit"); 529 | 530 | return $this->execute(array("action"=>"vserver-bandwidth", "vserverid"=>$serverID, "limit"=>$limit, "overlimit"=>$overlimit)); 531 | } 532 | 533 | /** 534 | * Updates vserver's memory 535 | * 536 | * https://documentation.solusvm.com/display/DOCS/Change+Memory 537 | * 538 | * @access public 539 | * @param int, int 540 | * @return str 541 | */ 542 | public function changeMemory($serverID, $memory) { 543 | if(!is_numeric($serverID)) 544 | throw new Exception("Invalid ServerID"); 545 | 546 | if(!is_numeric($memory)) 547 | throw new Exception("Invalid Memory"); 548 | 549 | return $this->execute(array("action"=>"vserver-change-memory", "vserverid"=>$serverID, "memory"=>$memory)); 550 | } 551 | 552 | /** 553 | * Updates vserver's hdd size 554 | * 555 | * https://documentation.solusvm.com/display/DOCS/Change+Hard+Disk+Size 556 | * 557 | * @access public 558 | * @param int, int 559 | * @return str 560 | */ 561 | public function changeDiskSize($serverID, $hdd) { 562 | if(!is_numeric($serverID)) 563 | throw new Exception("Invalid ServerID"); 564 | 565 | if(!is_numeric($hdd)) 566 | throw new Exception("Invalid HDD"); 567 | 568 | return $this->execute(array("action"=>"vserver-change-hdd", "vserverid"=>$serverID, "hdd"=>$hdd)); 569 | } 570 | 571 | /** 572 | * Rebuilds specified vserver 573 | * 574 | * https://documentation.solusvm.com/display/DOCS/Rebuild+Virtual+Server 575 | * 576 | * @access public 577 | * @param int, str 578 | * @return str 579 | */ 580 | public function rebuild($serverID, $template) { 581 | if(!is_numeric($serverID)) 582 | throw new Exception("Invalid ServerID"); 583 | 584 | return $this->execute(array("action"=>"vserver-rebuild", "vserverid"=>$serverID, "template"=>$template)); 585 | } 586 | 587 | /** 588 | * Changes vserver's root password 589 | * 590 | * https://documentation.solusvm.com/display/DOCS/Change+Root+Password 591 | * 592 | * @access public 593 | * @param int, str 594 | * @return str 595 | */ 596 | public function changeRootPassword($serverID, $rootpassword) { 597 | if(!is_numeric($serverID)) 598 | throw new Exception("Invalid ServerID"); 599 | 600 | return $this->execute(array("action"=>"vserver-rootpassword", "vserverid"=>$serverID, "rootpassword"=>$rootpassword)); 601 | } 602 | 603 | /** 604 | * Changes VNC password 605 | * 606 | * https://documentation.solusvm.com/display/DOCS/Change+VNC+Password 607 | * 608 | * @access public 609 | * @param int, str 610 | * @return str 611 | */ 612 | public function changeVNCpassword($serverID, $vncpassword) { 613 | if(!is_numeric($serverID)) 614 | throw new Exception("Invalid ServerID"); 615 | 616 | return $this->execute(array("action"=>"vserver-vncpass", "vserverid"=>$serverID, "vncpassword"=>$vncpassword)); 617 | } 618 | 619 | /** 620 | * Retrives list of available templates 621 | * 622 | * https://documentation.solusvm.com/display/DOCS/List+Templates 623 | * 624 | * @access public 625 | * @param str 626 | * @return str 627 | */ 628 | public function listTemplates($type, $listpipefriendly) { 629 | if(!in_array($type, array("xen hvm", "kvm", "xen", "openvz"))) 630 | throw new Exception("Invalid Type"); 631 | 632 | return $this->execute(array("action"=>"listtemplates", "type"=>$type, "listpipefriendly"=>$listpipefriendly)); 633 | } 634 | 635 | /** 636 | * Retrives list of available plans 637 | * 638 | * https://documentation.solusvm.com/display/DOCS/List+Plans 639 | * 640 | * @access public 641 | * @param str 642 | * @return str 643 | */ 644 | public function listPlans($type) { 645 | if(!in_array($type, array("xen hvm", "kvm", "xen", "openvz"))) 646 | throw new Exception("Invalid Type"); 647 | 648 | return $this->execute(array("action"=>"listplans", "type"=>$type)); 649 | } 650 | 651 | /** 652 | * Retrives list of nodes annotated by their ID 653 | * 654 | * https://documentation.solusvm.com/display/DOCS/List+Nodes+by+ID 655 | * 656 | * @access public 657 | * @param str 658 | * @return str 659 | */ 660 | public function listNodesByID($type) { 661 | if(!in_array($type, array("xen hvm", "kvm", "xen", "openvz"))) 662 | throw new Exception("Invalid Type"); 663 | 664 | return $this->execute(array("action"=>"node-idlist", "type"=>$type)); 665 | } 666 | 667 | /** 668 | * Retrives list of nodes annotated by their name 669 | * 670 | * https://documentation.solusvm.com/display/DOCS/List+Nodes+by+Name 671 | * 672 | * @access public 673 | * @param str 674 | * @return str 675 | */ 676 | public function listNodesByName($type) { 677 | if(!in_array($type, array("xen hvm", "kvm", "xen", "openvz"))) 678 | throw new Exception("Invalid Type"); 679 | 680 | return $this->execute(array("action"=>"listnodes", "type"=>$type)); 681 | } 682 | 683 | /** 684 | * Retrieves list of IP address associated with specified node 685 | * 686 | * https://documentation.solusvm.com/display/DOCS/List+All+IP+Addresses+for+a+Node 687 | * 688 | * @access public 689 | * @param int, int 690 | * @return str 691 | */ 692 | public function getNodeIPs($nodeid) { 693 | if(!is_numeric($nodeid)) 694 | throw new Exception("Invalid NodeID"); 695 | 696 | return $this->execute(array("action"=>"node-iplist", "nodeid"=>$nodeid)); 697 | } 698 | 699 | /** 700 | * Retrieves list of node groups 701 | * 702 | * https://documentation.solusvm.com/display/DOCS/List+Node+Groups 703 | * 704 | * @access public 705 | * @param int, str 706 | * @return str 707 | */ 708 | public function listNodeGroups($type) { 709 | if(!in_array($type, array("xen hvm", "kvm"))) 710 | throw new Exception("Invalid Type"); 711 | 712 | return $this->execute(array("action"=>"listnodegroups", "type"=>$type)); 713 | } 714 | 715 | /** 716 | * List node statistics 717 | * 718 | * https://documentation.solusvm.com/display/DOCS/Node+Statistics 719 | * 720 | * @access public 721 | * @param int, str 722 | * @return str 723 | */ 724 | public function getNodeStatistics($nodeid) { 725 | return $this->execute(array("action"=>"node-statistics","nodeid"=>$nodeid)); 726 | } 727 | } 728 | --------------------------------------------------------------------------------