Автор: Stuart Herbert (stuart.herbert@datasift.com)
Пример #1
0
 public function createVm($vmName, $osName, $amiId, $instanceType, $securityGroup)
 {
     // what are we doing?
     $log = usingLog()->startAction("start EC2 VM '{$vmName}', running guest OS '{$osName}', using AMI ID '{$amiId}' and security group '{$securityGroup}'");
     // get the aws settings
     $awsSettings = fromConfig()->getModuleSetting('aws');
     // put the details into an array
     $vmDetails = new Ec2VmDetails();
     $vmDetails->hostId = $vmName;
     $vmDetails->environment = $this->st->getTestEnvironmentName();
     $vmDetails->osName = $osName;
     $vmDetails->amiId = $amiId;
     $vmDetails->type = 'Ec2Vm';
     $vmDetails->instanceType = $instanceType;
     $vmDetails->securityGroup = $securityGroup;
     $vmDetails->keyPairName = $awsSettings->ec2->keyPairName;
     $vmDetails->sshUsername = $awsSettings->ec2->sshUsername;
     $vmDetails->sshKeyFile = $awsSettings->ec2->sshKeyFile;
     $vmDetails->sshOptions = array("-i '" . $awsSettings->ec2->sshKeyFile . "'");
     $vmDetails->scpOptions = array("-i '" . $awsSettings->ec2->sshKeyFile . "'");
     // create our host adapter
     $host = HostLib::getHostAdapter($this->st, $vmDetails->type);
     // create our virtual machine
     $host->createHost($vmDetails);
     // all done
     $log->endAction();
 }
 public function doPhase($thingBeingPlayed = null)
 {
     // shorthand
     $st = $this->st;
     // our return value
     $phaseResult = $this->getNewPhaseResult();
     // find out what we need to be doing
     $testEnvironmentConfig = $st->getTestEnvironmentConfig();
     // are there any machines to create?
     if (empty($testEnvironmentConfig)) {
         // nothing to do
         $phaseResult->setContinuePlaying();
         return $phaseResult;
     }
     // create the environments
     try {
         foreach ($testEnvironmentConfig->groups as $group) {
             // create the machine(s) in this environment, including:
             //
             // * building any virtual machines
             // * registering in the Hosts table
             // * registering in the Roles table
             $hostAdapter = HostLib::getHostAdapter($st, $group->type);
             $hostAdapter->createHost($group);
             // provision software onto the machines we've just
             // created
             if (isset($group->provisioning)) {
                 $provAdapter = ProvisioningLib::getProvisioner($st, $group->provisioning->engine);
                 $provDef = $provAdapter->buildDefinitionFor($group);
                 $provAdapter->provisionHosts($provDef, $group->provisioning);
             }
         }
         $st->usingTargetsTable()->addCurrentTestEnvironment();
         $phaseResult->setContinuePlaying();
     } catch (E5xx_ActionFailed $e) {
         $phaseResult->setPlayingFailed($phaseResult::FAILED, $e->getMessage(), $e);
     } catch (E5xx_ExpectFailed $e) {
         $phaseResult->setPlayingFailed($phaseResult::FAILED, $e->getMessage(), $e);
     } catch (E5xx_NotImplemented $e) {
         $phaseResult->setPlayingFailed($phaseResult::INCOMPLETE, $e->getMessage(), $e);
     } catch (Exception $e) {
         $phaseResult->setPlayingFailed($phaseResult::ERROR, $e->getMessage() . PHP_EOL . PHP_EOL . $e->getTraceAsString(), $e);
     }
     // all done
     return $phaseResult;
 }
Пример #3
0
 public function createVm($vmName, $osName, $homeFolder)
 {
     // what are we doing?
     $log = usingLog()->startAction("start vagrant VM '{$vmName}', running guest OS '{$osName}', using Vagrantfile in '{$homeFolder}'");
     // put the details into an array
     $vmDetails = new BaseObject();
     $vmDetails->hostId = $vmName;
     $vmDetails->osName = $osName;
     $vmDetails->homeFolder = $homeFolder;
     $vmDetails->type = 'VagrantVm';
     $vmDetails->sshUsername = '******';
     $vmDetails->sshKeyFile = $this->determinePrivateKey($vmDetails);
     $vmDetails->sshOptions = ["-i '" . $vmDetails->sshKeyFile . "'", "-o StrictHostKeyChecking=no", "-o UserKnownHostsFile=/dev/null", "-o LogLevel=quiet"];
     $vmDetails->scpOptions = ["-i '" . $vmDetails->sshKeyFile . "'", "-o StrictHostKeyChecking=no"];
     // create our host adapter
     $host = HostLib::getHostAdapter($this->st, $vmDetails->type);
     // create our virtual machine
     $host->createHost($vmDetails);
     // all done
     $log->endAction();
 }
 public function doPhase($thingBeingPlayed = null)
 {
     // shorthand
     $st = $this->st;
     // our return value
     $phaseResult = $this->getNewPhaseResult();
     // find out what we need to be doing
     $testEnvironmentConfig = $st->getTestEnvironmentConfig();
     // are there any machines to destroy?
     if (empty($testEnvironmentConfig)) {
         // nothing to do
         $phaseResult->setContinuePlaying();
         return $phaseResult;
     }
     // destroy the environments
     try {
         foreach ($testEnvironmentConfig->groups as $env) {
             // destroy the machine(s) in this environment, including:
             //
             // * destroying any virtual machines
             // * de-registering in the Hosts table
             // * de-registering in the Roles table
             $hostAdapter = HostLib::getHostAdapter($st, $env->type);
             $hostAdapter->destroyHost($env);
         }
         $st->usingTargetsTable()->removeCurrentTestEnvironment();
         $phaseResult->setContinuePlaying();
     } catch (E5xx_ActionFailed $e) {
         $phaseResult->setPlayingFailed($phaseResult::FAILED, $e->getMessage(), $e);
     } catch (E5xx_ExpectFailed $e) {
         $phaseResult->setPlayingFailed($phaseResult::FAILED, $e->getMessage(), $e);
     } catch (E5xx_NotImplemented $e) {
         $phaseResult->setPlayingFailed($phaseResult::INCOMPLETE, $e->getMessage(), $e);
     } catch (Exception $e) {
         $phaseResult->setPlayingFailed($phaseResult::ERROR, $e->getMessage(), $e);
     }
     // all done
     return $phaseResult;
 }
Пример #5
0
 public function startVm($vmName)
 {
     // what are we doing?
     $log = usingLog()->startAction("start VM '{$vmName}'");
     // get the VM details
     $vmDetails = fromHost($vmName)->getDetails();
     // create our host adapter
     $host = HostLib::getHostAdapter($this->st, $vmDetails->type);
     // restart our virtual machine
     $host->startHost($vmDetails);
     // all done
     $log->endAction();
 }
Пример #6
0
 /**
  * is a host up and running?
  *
  * @return boolean
  */
 public function getHostIsRunning()
 {
     // what are we doing?
     $log = usingLog()->startAction("is host '{$this->args[0]}' running?");
     // make sure we have valid host details
     $hostDetails = $this->getHostDetails();
     // get an object to talk to this host
     $host = HostLib::getHostAdapter($this->st, $hostDetails->type);
     // if the box is running, it should have a status of 'running'
     $result = $host->isRunning($hostDetails);
     if (!$result) {
         $log->endAction("host is not running");
         return false;
     }
     // all done
     $log->endAction("host is running");
     return true;
 }