/**
  * Handle a provisioning request
  *
  * @param ProvisionJob $command
  *
  * @return mixed
  */
 public function handle(ProvisionJob $command)
 {
     $_options = $command->getOptions();
     $_guestLocation = array_get($_options, 'guest-location', config('provisioning.default-guest-location'));
     if (is_string($_guestLocation) && !is_numeric($_guestLocation)) {
         $_options['guest-location'] = GuestLocations::resolve($_guestLocation, true);
         \Log::debug('[Provision] guest location "' . $_options['guest-location'] . '" resolved from "' . $_guestLocation . '".');
         $_guestLocation = $_options['guest-location'];
     }
     \Log::info('[Provision] Request [guest=' . $_guestLocation . ']: ' . Json::encode($_options));
     try {
         //  Create the instance record
         $_instance = InstanceManager::make($command->getInstanceId(), $_options);
         if (!$_instance) {
             throw new ProvisioningException('InstanceManager::make() failed');
         }
     } catch (\Exception $_ex) {
         \Log::error('[Provision] failure, exception creating instance: ' . $_ex->getMessage());
         return false;
     }
     try {
         $_guest = array_get($_options, 'guest-location', config('provisioning.default-guest-location'));
         $_provisioner = Provision::getProvisioner($_guest);
         if (empty($_provisioner)) {
             throw new \RuntimeException('The provisioner of the request is not valid.');
         }
         if (false === ($_response = $_provisioner->provision(new ProvisionServiceRequest($_instance)))) {
             throw new ProvisioningException('provisioning error');
         }
         \Log::info('[Provision] completed in ' . number_format($_response->getElapsedTime(), 4) . 's');
         return $_response;
     } catch (\Exception $_ex) {
         \Log::error('[Provision] failure: ' . $_ex->getMessage());
         //  Delete instance record...
         if (!$_instance->delete()) {
             throw new \LogicException('Unable to remove created instance "' . $_instance->instance_id_text . '".');
         }
     }
     return false;
 }
 /**
  * @param int $guestLocation
  *
  * @return InstanceStorageService
  */
 public function setGuestLocation($guestLocation)
 {
     if (!is_numeric($guestLocation)) {
         $guestLocation = GuestLocations::resolve($guestLocation, true);
     }
     $this->guestLocation = $guestLocation;
     return $this;
 }
Beispiel #3
0
 /**
  * Get the console command arguments.
  *
  * @return array
  */
 protected function getArguments()
 {
     return array_merge(parent::getArguments(), [['owner-id', InputArgument::REQUIRED, 'The id of the owner of the new instance'], ['instance-id', InputArgument::REQUIRED, 'The name of the new instance'], ['guest-location', InputArgument::OPTIONAL, 'The location of the new instance. Values: ' . GuestLocations::prettyList('"', true), config('provisioning.default-guest-location')]]);
 }
 /**
  * @param string $tag
  * @param string $subkey
  * @param string $connector The config key connector from $tag to $subkey
  *
  * @return mixed
  */
 protected function _buildTag(&$tag, $subkey = null, $connector = '.provides.')
 {
     $tag = trim(GuestLocations::resolve($tag ?: $this->getDefaultProvisioner()));
     if (null === $subkey) {
         $subkey = PortableTypes::INSTANCE;
     }
     return $tag . $connector . $subkey;
 }
Beispiel #5
0
 /**
  * @return string the base resource URI to use
  */
 public function getResourceUri()
 {
     return config('provisioners.hosts.' . GuestLocations::resolve($this->guest_location_nbr) . '.resource-uri');
 }