/** * @param ProvisionServiceRequest $request * @param array $options * * @return bool */ protected function doDeprovision($request, $options = []) { $_instance = $request->getInstance(); $this->info('[deprovisioning:database] instance "' . $_instance->instance_id_text . '" begin'); // Get a connection to the instance's database server list($_db, $_rootConfig, $_rootServer) = $this->getRootDatabaseConnection($_instance); try { // Try and get rid of the database we created if (!$this->dropDatabase($_db, $_instance->db_name_text)) { throw new ProvisioningException('Unable to delete database "' . $_instance->db_name_text . '".'); } } catch (\Exception $_ex) { $this->error('[deprovisioning:database] database "' . $_instance->db_name_text . '" FAILURE: ' . $_ex->getMessage()); return false; } // Fire off a "database.deprovisioned" event... \Event::fire('dfe.database.deprovisioned', [$this, $request]); $this->info('[deprovisioning:database] instance "' . $_instance->instance_id_text . '" complete'); return true; }
/** * @param ProvisionServiceRequest $request * @param array $options ['keep-database'=>true|false] * * @return bool * @throws ProvisioningException */ protected function deprovisionInstance($request, $options = []) { $_keepDatabase = array_get($options, 'keep-database', false); $_instance = $request->getInstance(); $_name = $_instance->instance_id_text; $this->info('[deprovisioning:instance] instance "' . $_name . '" begin'); if ($_keepDatabase) { $this->info('[deprovisioning:instance] "keep-database" specified. Keeping existing schema, if any.'); } else { // Deprovision the database $_dbService = Provision::getDatabaseProvisioner($_instance->guest_location_nbr); if (false === ($_dbConfig = $_dbService->deprovision($request))) { throw new ProvisioningException('Failed to deprovision database. Check logs for error.'); } } try { if (!$_instance->delete()) { throw new \RuntimeException('Instance row deletion failed.'); } } catch (\Exception $_ex) { $this->error('[deprovisioning:instance] exception while deleting instance row: ' . $_ex->getMessage()); return false; } // Fire off a "deprovisioned" event... \Event::fire('dfe.deprovisioned', [$this, $request]); $this->info('[deprovisioning:instance] instance "' . $_name . '" complete'); return true; }
/** * Deprovision an instance * * @param ProvisionServiceRequest $request * @param array $options * * @return bool */ protected function doDeprovision($request, $options = []) { $_instance = $request->getInstance(); $_filesystem = $request->getStorage(); $_storagePath = $_instance->instance_id_text; $this->info('[deprovisioning:storage] instance "' . $_instance->instance_id_text . '" begin'); // I'm not sure how hard this tries to delete the directory if (!$_filesystem->has($_storagePath)) { $this->notice('[deprovisioning:storage] unable to stat storage path "' . $_storagePath . '". not deleting!'); return false; } if (!$_filesystem->deleteDir($_storagePath)) { $this->error('[deprovisioning:storage] error deleting storage area "' . $_storagePath . '"'); return false; } // Fire off a "storage.deprovisioned" event... \Event::fire('dfe.storage.deprovisioned', [$this, $request]); $this->info('[deprovisioning:storage] instance "' . $_instance->instance_id_text . '" complete'); return true; }