123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * Class VM
- */
- class VM
- {
- protected $config;
- public $virtualMachine;
- /**
- * VM constructor.
- * @param $config
- */
- public function __construct($config)
- {
- $this->config = $config;
- }
- /**
- * @return array
- */
- public function getConfig()
- {
- return $this->config;
- }
- /**
- * @return bool
- */
- public function isEnabled()
- {
- $config = $this->getConfig();
- if (!isset($config)) {
-
- return false;
- }
- if (!is_array($config)) {
- return false;
- }
- if (isset($config['enabled']) && $config['enabled']) {
- return true;
- }
- return false;
- }
- /**
- * @return VirtualMachineInterface
- */
- public function getVirtualMachine()
- {
- return $this->virtualMachine;
- }
- /**
- * @param VirtualMachineInterface $virtualMachine
- */
- public function setVirtualMachine(VirtualMachineInterface $virtualMachine)
- {
- $this->virtualMachine = $virtualMachine;
- }
- /**
- * @return VirtualMachineInterface
- */
- public function getVirtualMachineFromConfig()
- {
- $vmList = $this->config['vms'];
- foreach ($vmList as $vm) {
- if (isset($vm['enabled']) && $vm['enabled'] == true) {
- $className = $vm['name'] . 'VM';
- return new $className($vm);
- break;
- }
- }
- return false;
- }
- /**
- * Resize the VM to the max size
- */
- public function resizeToMaxLimit()
- {
- $virtualMachine = $this->getVirtualMachineFromConfig();
- $this->setVirtualMachine($virtualMachine);
- $virtualMachine->resizeToMaxLimit();
- }
- /**
- * Resize the VM to the min size
- */
- public function resizeToMinLimit()
- {
- $virtualMachine = $this->getVirtualMachineFromConfig();
- $this->setVirtualMachine($virtualMachine);
- $virtualMachine->resizeToMinLimit();
- }
- public function runCron()
- {
- $virtualMachine = $this->getVirtualMachineFromConfig();
- $this->setVirtualMachine($virtualMachine);
- $virtualMachine->runCron();
- }
- }
|