public static function executeAction($instanceAction, $account, $instanceID) { $response = ''; switch ($instanceAction) { case 'start': $response = self::getDriver($account)->startInstances(array('DryRun' => false, 'InstanceIds' => array($instanceID))); break; case 'stop': $response = self::getDriver($account)->stopInstances(array('DryRun' => false, 'InstanceIds' => array($instanceID))); break; case 'restart': $response = self::getDriver($account)->restartInstances(array('DryRun' => false, 'InstanceIds' => array($instanceID))); break; case 'terminate': $response = self::getDriver($account)->terminateInstances(array('DryRun' => false, 'InstanceIds' => array($instanceID))); break; case 'describeInstances': $response = self::getDriver($account)->describeInstances(array('DryRun' => false, 'InstanceIds' => array($instanceID))); break; case 'downloadKey': $responseJson = xDockerEngine::authenticate(array('username' => Auth::user()->username, 'password' => md5(Auth::user()->engine_key))); EngineLog::logIt(array('user_id' => Auth::id(), 'method' => 'authenticate-executeAction', 'return' => $responseJson)); $obj = json_decode($responseJson); if (!empty($obj) && $obj->status == 'OK') { $response = xDockerEngine::downloadKey(array('token' => $obj->token, 'cloudProvider' => $account->cloudProvider, 'instanceRegion' => $account->instanceRegion)); Log::info('downloadKey Json:' . $response); if (StringHelper::isJson($response)) { $response = json_decode($response, true); $response['message'] = 'Key is returned in field key'; } else { $response = array('status' => 'error', 'message' => 'Error occured while downloading keys'); } } else { if (!empty($obj) && $obj->status == 'error') { Log::error('Error occured while downloading key' . $obj->message); $response = array('status' => $obj->status, 'message' => 'Unexpected error! Contact Support'); } else { Log::error('Error occured while downloading key'); $response = array('status' => 'error', 'message' => 'Unexpected error! Contact Support'); } } break; } return $response; }
/** * Remove the specified user from storage. * * @param $user * @return Response */ public function postDelete($user) { // Check if we are not trying to delete ourselves if ($user->id === Confide::user()->id) { // Redirect to the user management page return Redirect::to('admin/users')->with('error', Lang::get('admin/users/messages.delete.impossible')); } AssignedRoles::where('user_id', $user->id)->delete(); $id = $user->id; $username = $user->username; $responseJson = xDockerEngine::authenticate(array('username' => $user->username, 'password' => md5($user->engine_key))); EngineLog::logIt(array('user_id' => Auth::id(), 'method' => 'authenticate', 'return' => $responseJson)); $obj = json_decode($responseJson); if (!empty($obj) && $obj->status == 'OK') { $response = xDockerEngine::removeUsername(array('token' => $obj->token)); Log::info('xDocker Engine user is deleted!'); } if (!empty($obj) && $obj->status == 'error') { Log::error('xDocker Engine user deletion : Failed in authentication'); } else { Log::error('xDocker Engine user deletion - Unexpected error'); } $user->delete(); // Was the comment post deleted? $user = User::find($id); if (empty($user)) { // TODO needs to delete all of that user's content return Redirect::to('admin/users')->with('success', Lang::get('admin/users/messages.delete.success')); } else { // There was a problem deleting the user return Redirect::to('admin/users')->with('error', Lang::get('admin/users/messages.delete.error')); } }
public static function getxDockerServiceStatus() { $responseJson = xDockerEngine::authenticate(array('username' => Auth::user()->username, 'password' => md5(Auth::user()->engine_key))); EngineLog::logIt(array('user_id' => Auth::id(), 'method' => 'getxDockerServiceStatus : authenticate', 'return' => $responseJson)); $status = 'error'; if (StringHelper::isJson($responseJson)) { $obj = json_decode($responseJson); if (!empty($obj) && $obj->status == 'OK') { $status = 'OK'; } } return $status; }
public function getLogs($id) { $this->check(); $deployment = Deployment::where('user_id', Auth::id())->find($id); if (!empty($deployment) && isset($deployment->job_id)) { $responseJson = xDockerEngine::authenticate(array('username' => Auth::user()->username, 'password' => md5(Auth::user()->engine_key))); EngineLog::logIt(array('user_id' => Auth::id(), 'method' => 'authenticate', 'return' => $responseJson)); $obj = json_decode($responseJson); if (!empty($obj) && $obj->status == 'OK') { $response = xDockerEngine::getLog(array('token' => $obj->token, 'job_id' => $deployment->job_id, "line_num" => 10)); return View::make('site/deployment/logs', array('response' => $response, 'deployment' => $deployment)); } else { if (!empty($obj) && $obj->status == 'error') { Log::error('Request to deploy failed :' . $obj2->fail_code . ':' . $obj2->fail_message); Log::error('Log :' . implode(' ', $obj2->job_log)); return Redirect::to('deployment')->with('error', $obj->fail_message); } else { return Redirect::to('ServiceStatus')->with('error', 'Backend API is down, please try again later!'); } } } else { if (empty($deployment)) { return Redirect::to('deployment')->with('info', 'No deployments found! '); } else { return Redirect::to('deployment')->with('info', 'No logs found! '); } } }