function getVolumes($projectName, $region)
 {
     $headers = array('openstackmanager-volumename', 'openstackmanager-volumeid', 'openstackmanager-volumedescription', 'openstackmanager-volumeattachmentinstance', 'openstackmanager-volumeattachmentdevice', 'openstackmanager-volumeattachmentstatus', 'openstackmanager-volumesize', 'openstackmanager-volumecreationtime', 'openstackmanager-actions');
     $this->userNova->setRegion($region);
     $volumes = $this->userNova->getVolumes();
     $volumeRows = array();
     foreach ($volumes as $volume) {
         $volumeRow = array();
         $this->pushResourceColumn($volumeRow, $volume->getVolumeName());
         $volumeId = $volume->getVolumeId();
         $this->pushRawResourceColumn($volumeRow, $this->createResourceLink($volumeId));
         $this->pushResourceColumn($volumeRow, $volume->getVolumeDescription());
         $this->pushResourceColumn($volumeRow, $volume->getAttachedInstanceId());
         $this->pushResourceColumn($volumeRow, $volume->getAttachedDevice());
         $this->pushResourceColumn($volumeRow, $volume->getAttachmentStatus());
         $this->pushResourceColumn($volumeRow, $volume->getVolumeSize());
         $this->pushResourceColumn($volumeRow, $volume->getVolumeCreationTime());
         $actions = array();
         $actions[] = $this->createActionLink('openstackmanager-delete', array('action' => 'delete', 'project' => $projectName, 'region' => $region, 'volumeid' => $volumeId));
         $actions[] = $this->createActionLink('openstackmanager-attach', array('action' => 'attach', 'project' => $projectName, 'region' => $region, 'volumeid' => $volumeId));
         $actions[] = $this->createActionLink('openstackmanager-detach', array('action' => 'detach', 'project' => $projectName, 'region' => $region, 'volumeid' => $volumeId));
         $this->pushRawResourceColumn($volumeRow, $this->createResourceList($actions));
         $volumeRows[] = $volumeRow;
     }
     if ($volumeRows) {
         return $this->createResourceTable($headers, $volumeRows);
     } else {
         return '';
     }
 }
 function getInstances($projectName, $region, &$instanceCount)
 {
     global $wgMemc;
     $this->userNova->setRegion($region);
     $headers = array('openstackmanager-instancename', 'openstackmanager-instanceid', 'openstackmanager-instancestate', 'openstackmanager-instanceip', 'openstackmanager-projectname', 'openstackmanager-launchtime', 'openstackmanager-instancecreator');
     $instances = $this->userNova->getInstances();
     $instanceRows = array();
     $instanceCount = 0;
     /**
      * @var $instance OpenStackNovaInstance
      */
     foreach ($instances as $instance) {
         # Only display instances created by the current user.
         if ($instance->getInstanceCreator() != $this->userLDAP->getUid()) {
             continue;
         }
         $instanceRow = array();
         $this->pushResourceColumn($instanceRow, $instance->getInstanceName(), array('class' => 'novainstancename'));
         $host = $instance->getHost();
         if ($host) {
             $this->pushRawResourceColumn($instanceRow, $this->createResourceLink($host->getFullyQualifiedHostName()), array('class' => 'novainstanceid'));
         } else {
             $this->pushResourceColumn($instanceRow, $instance->getInstanceId(), array('class' => 'novainstanceid'));
         }
         $state = $instance->getInstanceState();
         $taskState = $instance->getInstanceTaskState();
         if ($taskState) {
             $stateDisplay = "{$state} ({$taskState})";
         } else {
             $stateDisplay = $state;
         }
         $this->pushResourceColumn($instanceRow, $stateDisplay, array('class' => 'novainstancestate'));
         $this->pushRawResourceColumn($instanceRow, $this->createResourceList($instance->getInstancePrivateIPs()));
         $this->pushResourceColumn($instanceRow, $projectName);
         $this->pushResourceColumn($instanceRow, $instance->getLaunchTime());
         $this->pushResourceColumn($instanceRow, $instance->getInstanceCreator());
         $actions = array();
         $instanceDataAttributes = array('data-osid' => $instance->getInstanceOSId(), 'data-id' => $instance->getInstanceId(), 'data-name' => $instance->getInstanceName(), 'data-project' => $projectName, 'data-region' => $region, 'class' => 'novainstanceaction');
         $instanceRows[] = $instanceRow;
         $instanceCount += 1;
     }
     if ($instanceRows) {
         return $this->createResourceTable($headers, $instanceRows);
     }
     return '';
 }
 /**
  * @return bool
  */
 function listSecurityGroups()
 {
     $this->setHeaders();
     $this->getOutput()->addModuleStyles('ext.openstack');
     $this->getOutput()->setPagetitle($this->msg('openstackmanager-securitygrouplist'));
     if ($this->userCanExecute($this->getUser())) {
         $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) {
             $this->userNova->setRegion($region);
             $regionactions = array('projectadmin' => array($this->createActionLink('openstackmanager-createnewsecuritygroup', array('action' => 'create', 'project' => $projectName, 'region' => $region))));
             $securityGroups = $this->getSecurityGroups($projectName, $region);
             $regions .= $this->createRegionSection($region, $projectName, $regionactions, $securityGroups);
         }
         $out .= $this->createProjectSection($projectName, $projectactions, $regions);
     }
     $this->getOutput()->addHTML($out);
     return true;
 }
 /**
  * @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;
 }
 function getInstances($projectName, $region)
 {
     global $wgMemc;
     $this->userNova->setRegion($region);
     $headers = array('openstackmanager-instancename', 'openstackmanager-instanceid', 'openstackmanager-instancestate', 'openstackmanager-instanceip', 'openstackmanager-instancepublicip', 'openstackmanager-securitygroups', 'openstackmanager-imageid', 'openstackmanager-launchtime', 'openstackmanager-actions');
     $instances = $this->userNova->getInstances();
     $instanceRows = array();
     /**
      * @var $instance OpenStackNovaInstance
      */
     foreach ($instances as $instance) {
         $instanceRow = array();
         $this->pushResourceColumn($instanceRow, $instance->getInstanceName(), array('class' => 'novainstancename'));
         $host = $instance->getHost();
         if ($host) {
             $this->pushRawResourceColumn($instanceRow, $this->createResourceLink($host->getFullyQualifiedHostName()), array('class' => 'novainstanceid'));
         } else {
             $this->pushResourceColumn($instanceRow, $instance->getInstanceId(), array('class' => 'novainstanceid'));
         }
         $state = $instance->getInstanceState();
         $taskState = $instance->getInstanceTaskState();
         if ($taskState) {
             $stateDisplay = "{$state} ({$taskState})";
         } else {
             $stateDisplay = $state;
         }
         $this->pushResourceColumn($instanceRow, $stateDisplay, array('class' => 'novainstancestate'));
         $this->pushRawResourceColumn($instanceRow, $this->createResourceList($instance->getInstancePrivateIPs()));
         $this->pushRawResourceColumn($instanceRow, $this->createResourceList($instance->getInstancePublicIPs()));
         $this->pushRawResourceColumn($instanceRow, $this->createResourceList($instance->getSecurityGroups()));
         $imageId = $instance->getImageId();
         $key = wfMemcKey('openstackmanager', "imagename", $imageId);
         $imageNameRet = $wgMemc->get($key);
         if (is_string($imageNameRet)) {
             $imageName = $imageNameRet;
         } else {
             $image = $this->userNova->getImage($imageId);
             if ($image) {
                 $imageName = $image->getImageName();
                 $wgMemc->set($key, $imageName, 86400);
             } else {
                 $imageName = $this->msg('openstackmanager-missingimage')->text();
             }
         }
         $this->pushResourceColumn($instanceRow, $imageName);
         $this->pushResourceColumn($instanceRow, $instance->getLaunchTime());
         $actions = array();
         $instanceDataAttributes = array('data-osid' => $instance->getInstanceOSId(), 'data-id' => $instance->getInstanceId(), 'data-name' => $instance->getInstanceName(), 'data-project' => $projectName, 'data-region' => $region, 'class' => 'novainstanceaction');
         if ($this->userLDAP->inRole('projectadmin', $projectName)) {
             $actions[] = $this->createActionLink('openstackmanager-delete', array('action' => 'delete', 'instanceid' => $instance->getInstanceOSId(), 'project' => $projectName, 'region' => $region), null, $instanceDataAttributes);
             $actions[] = $this->createActionLink('openstackmanager-reboot', array('action' => 'reboot', 'instanceid' => $instance->getInstanceOSId(), 'project' => $projectName, 'region' => $region), null, $instanceDataAttributes);
             $actions[] = $this->createActionLink('openstackmanager-configure', array('action' => 'configure', 'instanceid' => $instance->getInstanceOSId(), 'project' => $projectName, 'region' => $region));
             $actions[] = $this->createActionLink('openstackmanager-getconsoleoutput', array('action' => 'consoleoutput', 'instanceid' => $instance->getInstanceOSId(), 'project' => $projectName, 'region' => $region), null, $instanceDataAttributes);
         }
         $this->pushRawResourceColumn($instanceRow, $this->createResourceList($actions));
         $instanceRows[] = $instanceRow;
     }
     if ($instanceRows) {
         return $this->createResourceTable($headers, $instanceRows);
     } else {
         return '';
     }
 }