/**
  * Handle the event.
  *
  * @param  UserWasCreated  $event
  * @return void
  */
 public function handle(UserWasCreated $event)
 {
     // $event has user at $user.
     // Extract first and last name.  ACS wants them separate.
     if (str_word_count($event->user->name) > 1) {
         list($fname, $lname) = explode(' ', $event->user->name, 2);
     } else {
         $fname = $event->user->name;
         $lname = ' ';
     }
     // Grab Site Configuration
     $cfg = SiteConfig::all()->makeKVArray();
     $acsData = ['accounttype' => '0', 'email' => $event->user->email, 'firstname' => $fname, 'lastname' => $lname, 'password' => $event->user->password, 'username' => $event->user->email, 'domainid' => $cfg['domainId']];
     $result = app('Cloudstack\\CloudStackClient')->createAccount($acsData);
     // !!NEEDS REVISION!! Error checking
     $event->user->acs_id = $result->account->user[0]->id;
     $event->user->save();
 }
示例#2
0
 public function create($request)
 {
     /**
      * ACS requires the following for deployVirtualMachine():
      * serviceofferingid
      * templateid
      * zoneid
      * account
      * domainid
      * name
      * keypair (if needed)
      * rootdisksize (if allowed)
      * hypervisor (if specifying rootdisksize)
      */
     $instanceData = [];
     // Get site configuration.  We're looking for hypervisor, rootdiskresize, and domainId.
     $cfg = SiteConfig::all()->makeKVArray();
     // Did we receive a package or a custom configuration?
     if (isset($request['package'])) {
         $pkg = Package::find($request['package']);
         $instanceData['serviceofferingid'] = $this->findServiceOffering(['cpu' => $pkg->cpu_number, 'memory' => $pkg->ram, 'diskType' => $pkg->diskType->tags]);
     } else {
         $instanceData['serviceofferingid'] = $this->findServiceOffering(['cpu' => $request->coreSlider, 'memory' => $request->ramSlider * 1024, 'diskType' => $request->diskType]);
     }
     // If we can't find a service offering, error out.
     if (empty($instanceData['serviceofferingid'])) {
         abort(500);
     }
     if (isset($request->myTemplate)) {
         // Template is one created by the user.
         $instanceData['templateid'] = $request->myTemplate;
     } else {
         // Find the template we need.
         $templateGroup = TemplateGroup::find($request['template']);
         if ('FALSE' == $cfg['rootdiskresize']) {
             // Size can come from a package or a custom size slider.
             $disk_size = isset($request['package']) ? $pkg->disk_size : stristr($request['hdSlider'], ' ', true);
             // Find the specific size of template
             $templateGroup->templates->each(function ($tpl) use($disk_size, &$instanceData) {
                 if ($tpl->size == $disk_size) {
                     $instanceData['templateid'] = $tpl->template_id;
                 }
             });
         } else {
             if ('TRUE' == $cfg['rootdiskresize']) {
                 // We don't care about template size.  We resize whatever we need.
                 // Grab the template ID of the first (only) template in the group.
                 $instanceData['templateid'] = $templateGroup->templates->first()->template_id;
                 // If we have a package get the disk size from there.  If not we have a custom size.
                 $instanceData['rootdisksize'] = isset($request['package']) ? $pkg->disk_size : $request['disk_size'];
                 // We also need to set the hypervisor type.
                 $instanceData['hypervisor'] = $cfg['hypervisor'];
             }
         }
     }
     // Error out if we don't find a template
     if (empty($instanceData['templateid'])) {
         abort(500);
     }
     // Get the user object
     $user = Auth::User();
     // Add a network interface to the system
     $networks = $this->acs->listNetworks(['canusefordeploy' => 'true', 'account' => $user->email, 'domainid' => $cfg['domainId']]);
     // !!REVISE!!
     $instanceData['networkids'] = $networks[0]->id;
     // Select a security group for the instance
     $instanceData['securitygroupids'] = $request->secGroup;
     // Name the new instance
     $instanceData['name'] = $request['name'];
     // Add user data to the request
     $instanceData['account'] = $user->email;
     $instanceData['domainid'] = $cfg['domainId'];
     // What zone is being deployed to?
     $instanceData['zoneid'] = $request['zone'];
     // Do we need to add a keypair to the system?
     if (isset($request['keypair'])) {
         $instanceData['keypair'] = $request['keypair'];
     }
     return $this->acs->deployVirtualMachine($instanceData);
 }
 public function edit()
 {
     $settings = SiteConfig::all()->makeKVArray();
     return view('admin.settings.edit')->with(compact('settings'));
 }