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; }
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 static function getStatus($json) { if (StringHelper::isJson($json)) { $obj = json_decode($json); return self::getLabel($obj->status); } else { return self::getLabel('error'); } }