Пример #1
0
 public function postNew(Request $request)
 {
     try {
         $node = new NodeRepository();
         $new = $node->create($request->except(['_token']));
         Alert::success('Successfully created new node. You should allocate some IP addresses to it now.')->flash();
         return redirect()->route('admin.nodes.view', ['id' => $new]);
     } catch (DisplayValidationException $e) {
         return redirect()->route('admin.nodes.new')->withErrors(json_decode($e->getMessage()))->withInput();
     } catch (DisplayException $e) {
         Alert::danger($e->getMessage())->flash();
     } catch (\Exception $e) {
         Log::error($e);
         Alert::danger('An unhandled exception occured while attempting to add this node. Please try again.')->flash();
     }
     return redirect()->route('admin.nodes.new')->withInput();
 }
Пример #2
0
 /**
  * Create a New Node
  *
  * @Post("/nodes")
  * @Versions({"v1"})
  * @Transaction({
  *      @Request({
  *      	'name' => 'My API Node',
  *      	'location' => 1,
  *      	'public' => 1,
  *      	'fqdn' => 'daemon.wuzzle.woo',
  *      	'scheme' => 'https',
  *      	'memory' => 10240,
  *      	'memory_overallocate' => 100,
  *      	'disk' => 204800,
  *      	'disk_overallocate' => -1,
  *      	'daemonBase' => '/srv/daemon-data',
  *      	'daemonSFTP' => 2022,
  *      	'daemonListen' => 8080
  *      }, headers={"Authorization": "Bearer <jwt-token>"}),
  *       @Response(201),
  *       @Response(422, body={
  *          "message": "A validation error occured.",
  *          "errors": {},
  *          "status_code": 422
  *       }),
  *       @Response(503, body={
  *       	"message": "There was an error while attempting to add this node to the system.",
  *       	"status_code": 503
  *       })
  * })
  */
 public function create(Request $request)
 {
     try {
         $node = new NodeRepository();
         $new = $node->create($request->all());
         return $this->response->created(route('api.nodes.view', ['id' => $new]));
     } catch (DisplayValidationException $ex) {
         throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
     } catch (DisplayException $ex) {
         throw new ResourceException($ex->getMessage());
     } catch (\Exception $e) {
         throw new BadRequestHttpException('There was an error while attempting to add this node to the system.');
     }
 }