/**
  * Default action
  * @return void
  */
 function listInstances()
 {
     $this->setHeaders();
     $this->getOutput()->addModules('ext.openstack.Instance');
     $projects = OpenStackNovaProject::getProjectsByName($this->userLDAP->getProjects());
     $instanceOut = '';
     $ownedProjects = array();
     $instanceCount = 0;
     foreach ($projects as $project) {
         $projectName = $project->getProjectName();
         $instancesInProject = 0;
         if ($this->userLDAP->inRole('projectadmin', $projectName)) {
             $ownedProjects[] = $projectName;
         }
         $projectactions = array('projectadmin' => array());
         $regions = '';
         $this->userNova->setProject($projectName);
         foreach ($this->userNova->getRegions('compute') as $region) {
             $regionactions = array();
             $thisCount = 0;
             $instances = $this->getInstances($projectName, $region, $thisCount);
             $instancesInProject += $thisCount;
             if ($thisCount > 0) {
                 $regions .= $this->createRegionSection($region, $projectName, $regionactions, $instances);
             }
         }
         if ($instancesInProject) {
             $instanceOut .= $this->createProjectSection($projectName, $projectactions, $regions);
             $instanceCount += $instancesInProject;
         } else {
         }
     }
     $out = '';
     if ($ownedProjects) {
         $this->getOutput()->setPagetitle($this->msg('openstackmanager-ownedprojects', count($ownedProjects)));
         foreach ($ownedProjects as $ownedProject) {
             $projectNameOut = $this->createResourceLink($ownedProject);
             $out .= $projectNameOut . " ";
         }
     } else {
         $this->getOutput()->setPagetitle($this->msg('openstackmanager-noownedprojects'));
     }
     if ($instanceCount) {
         $out .= Html::rawElement('h1', array(), $this->msg('openstackmanager-ownedinstances', $instanceCount)->text());
         $out .= $instanceOut;
     } else {
         $out .= Html::rawElement('h1', array(), $this->msg('openstackmanager-noownedinstances')->text());
     }
     $this->getOutput()->addHTML($out);
 }
 /**
  * @return void
  */
 function listVolumes()
 {
     $this->setHeaders();
     $this->getOutput()->addModuleStyles('ext.openstack');
     $this->getOutput()->setPagetitle($this->msg('openstackmanager-volumelist'));
     if ($this->getUser()->isAllowed('listall')) {
         $projects = OpenStackNovaProject::getAllProjects();
     } else {
         $projects = OpenStackNovaProject::getProjectsByName($this->userLDAP->getProjects());
     }
     $this->showProjectFilter($projects);
     $projectfilter = $this->getProjectFilter();
     if (!$projectfilter) {
         $this->getOutput()->addWikiMsg('openstackmanager-setprojectfilter');
         return null;
     }
     $out = '';
     foreach ($projects as $project) {
         $projectName = $project->getProjectName();
         if (!in_array($projectName, $projectfilter)) {
             continue;
         }
         $projectactions = array('projectadmin' => array());
         $regions = '';
         $this->userNova->setProject($projectName);
         foreach ($this->userNova->getRegions('compute') as $region) {
             $regionactions = array('projectadmin' => array($this->createActionLink('openstackmanager-createvolume', array('action' => 'create', 'project' => $projectName, 'region' => $region))));
             $volumes = $this->getVolumes($projectName, $region);
             $regions .= $this->createRegionSection($region, $projectName, $regionactions, $volumes);
         }
         $out .= $this->createProjectSection($projectName, $projectactions, $regions);
     }
     $this->getOutput()->addHTML($out);
 }
 /**
  * @param  $formData
  * @param string $entryPoint
  * @return bool
  */
 function tryCreateSubmit($formData, $entryPoint = 'internal')
 {
     global $wgOpenStackManagerDefaultSecurityGroupRules;
     $success = OpenStackNovaProject::createProject($formData['projectname']);
     if (!$success) {
         $this->getOutput()->addWikiMsg('openstackmanager-createprojectfailed');
         return false;
     }
     $project = OpenStackNovaProject::getProjectByName($formData['projectname']);
     $username = $this->userLDAP->getUsername();
     $project->addMember($username);
     $members = explode(',', $formData['member']);
     foreach ($members as $member) {
         $project->addMember($member);
     }
     $roles = $project->getRoles();
     foreach ($roles as $role) {
         if (in_array($role->getRoleName(), $formData['roles'])) {
             foreach ($members as $member) {
                 $role->addMember($member);
             }
         }
         // We also need to ensure the project creator is in all roles
         $role->addMember($username);
     }
     # Change the connection to reference this project
     $this->userNova->setProject($formData['projectname']);
     $regions = $this->userNova->getRegions('compute');
     foreach ($regions as $region) {
         $this->userNova->setRegion($region);
         $securityGroups = $this->userNova->getSecurityGroups();
         $groupid = '';
         foreach ($securityGroups as $securityGroup) {
             if ($securityGroup->getGroupName() === 'default') {
                 $groupid = $securityGroup->getGroupId();
             }
         }
         if (!$groupid) {
             continue;
         }
         foreach ($wgOpenStackManagerDefaultSecurityGroupRules as $rule) {
             $fromport = '';
             $toport = '';
             $protocol = '';
             $range = '';
             $sourcegroupid = '';
             if (array_key_exists('fromport', $rule)) {
                 $fromport = $rule['fromport'];
             }
             if (array_key_exists('toport', $rule)) {
                 $toport = $rule['toport'];
             }
             if (array_key_exists('protocol', $rule)) {
                 $protocol = $rule['protocol'];
             }
             if (array_key_exists('range', $rule)) {
                 $range = $rule['range'];
             }
             if (array_key_exists('group', $rule)) {
                 foreach ($securityGroups as $securityGroup) {
                     if ($rule['group'] === $securityGroup->getGroupName()) {
                         $sourcegroupid = $securityGroup->getGroupId();
                     }
                 }
             }
             $this->userNova->addSecurityGroupRule($groupid, $fromport, $toport, $protocol, $range, $sourcegroupid);
         }
     }
     $project->setVolumeSettings(array('home', 'project'));
     $project->editArticle();
     $this->getOutput()->addWikiMsg('openstackmanager-createdproject');
     $out = '<br />';
     $out .= Linker::link($this->getPageTitle(), $this->msg('openstackmanager-addadditionalproject')->escaped());
     $this->getOutput()->addHTML($out);
     return true;
 }