| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- /* * ********************************************************************
- * proxmoxCloud product developed. (2016-12-30)
- * *
- *
- * CREATED BY MODULESGARDEN -> http://modulesgarden.com
- * CONTACT -> contact@modulesgarden.com
- *
- *
- * This software is furnished under a license and may be used and copied
- * only in accordance with the terms of such license and with the
- * inclusion of the above copyright notice. This software or any other
- * copies thereof may not be provided or otherwise made available to any
- * other person. No title to and ownership of the software is hereby
- * transferred.
- *
- *
- * ******************************************************************** */
- namespace MGProvision\Proxmox\v2;
- use MGProvision\Proxmox\v2 as proxmox;
- /**
- * Description of Factory
- *
- * @author Pawel Kopec <pawelk@modulesgarden.com>
- * @version 1.0.0
- */
- class Factory
- {
- /**
- *
- * @param array $params WHMCS params
- * @return \MGProvision\Proxmox\v2\Api
- */
- static function api($params)
- {
- if(is_numeric($params['serverport']) && $params['serverip'] && !preg_match("/\:/",$params['serverip'])){
- $params['serverip'] .=":".$params['serverport'];
- }
- if(is_numeric($params['serverport']) && $params['serverhostname'] && !preg_match("/\:/",$params['serverhostname'])){
- $params['serverhostname'] .=":".$params['serverport'];
- }
- $host = $params['serverip'] ? $params['serverip'] : $params['serverhostname'];
- return new Api($host, $params['serverusername'], $params['serveraccesshash'], $params['serverpassword']);
- }
- /**
- *
- * @return \MGProvision\Proxmox\v2\Api
- */
- static function apiFromServer(\ModulesGarden\ProxmoxAddon\Core\Models\Whmcs\Server $server)
- {
- $host = $server->ipaddress ? $server->ipaddress : $server->hostname;
- return new Api($host, $server->username, $server->accesshash, decrypt($server->password));
- }
- static function vm($vServer)
- {
- if ($vServer instanceof \MGProvision\ProxmoxCloud\models\VServer)
- {
- $vmid = $vServer->getVmid();
- $node = $vServer->getNode();
- $virtualization = $vServer->getVirtualization();
- }
- else
- {
- $vmid = $vServer->vmid;
- $node = $vServer->node;
- $virtualization = $vServer->virtualization;
- }
- switch (strtolower($virtualization))
- {
- case 'kvm':
- case 'qemu':
- return new proxmox\models\Kvm($node, $vmid);
- break;
- case 'lxc':
- return new proxmox\models\Lxc($node, $vmid);
- break;
- default:
- throw new \Exception(sprintf("Invalid virtualization type '%s'", $virtualization));
- }
- }
- static function vmVps($product, $params)
- {
- if (is_string($product))
- {
- $virtualization = $product;
- }
- else if (is_object($product) && method_exists($product, 'getConfig'))
- {
- $virtualization = $product->getConfig('virtualization_type');
- }else if(is_object($product) && method_exists($product, 'getVirtualization')){
- $virtualization = $product->getVirtualization();
- }
- switch (strtolower($virtualization))
- {
- case 'kvm':
- case 'qemu':
- $vm = new proxmox\models\Kvm($params['customfields']['node'], $params['customfields']['vmid']);
- break;
- case 'lxc':
- $vm = new proxmox\models\Lxc($params['customfields']['node'], $params['customfields']['vmid']);
- break;
- default:
- throw new \Exception(sprintf("Invalid virtualization type '%s'", $virtualization));
- }
- $vm->setName(!empty($params['domain']) ? $params['domain'] : $params['customfields']['proxmoxHostname']);
- return $vm;
- }
- /**
- *
- * @param array $params
- * @return \MGProvision\Proxmox\v2\models\User
- */
- static function user(array $params)
- {
- if (empty($params['customfields']['Authentication']))
- {
- throw new \Exception("Custom field ('Authentication') is empty.");
- }
- if (empty($params['username']))
- {
- throw new \Exception("Servuce field ('Username') is empty.");
- }
- $userid = $params['username'] . "@" . $params['customfields']['Authentication'];
- return new proxmox\models\User($userid);
- }
- }
|