示例#1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     session_start();
     if (!isset($_SESSION['AUTH']) || $_SESSION['AUTH'] == false) {
         \App::abort(500, 'User not authenticated');
     }
     $post = file_get_contents('php://input');
     $data = json_decode($post, true);
     if ($data['ipAddr'] != null && $data['type'] != null) {
         //creates a new VM in middleware database. Expects ipaddress and type
         $v = new vm();
         $v->id = \Uuid::generate(4);
         $v->ipAddr = $data['ipAddr'];
         $v->type = $data['type'];
         try {
             //emit request to make vm
             $redis = \Redis::connection();
             // Using the Redis extension provided client
             $redis->publish('demeter', json_encode(array('command' => 'init', 'vm' => $v->id->string, 'type' => $v->type, 'netId' => $_SESSION['AUTH_USER'])));
             if ($v->save()) {
                 echo "success";
             } else {
                 \App::abort(500, 'VM could not be created, please contact an Administrator');
             }
         } catch (Exception $e) {
             \App::abort(500, 'VM could not be created, please contact an Administrator');
         }
     } else {
         \App::abort(500, 'VM could not be created, please contact an Administrator');
     }
 }