/** * 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 bool */ function displayQuotas() { $this->setHeaders(); $projectName = $this->getRequest()->getText('projectname'); $this->getOutput()->setPagetitle($this->msg('openstackmanager-displayquotas', $projectName)); if (!$this->userCanExecute($this->getUser()) && !$this->userLDAP->inRole('projectadmin', $projectName)) { $this->notInRole('projectadmin', $projectName); return false; } # Change the connection to reference this project $this->userNova->setProject($projectName); $regions = $this->userNova->getRegions('compute'); foreach ($regions as $region) { $this->userNova->setRegion($region); $limits = $this->userNova->getLimits(); $ram = $this->msg('openstackmanager-displayquotas-ram', $limits->getRamUsed(), $limits->getRamAvailable()); $floatingIps = $this->msg('openstackmanager-displayquotas-floatingips', $limits->getFloatingIpsUsed(), $limits->getFloatingIpsAvailable()); $cores = $this->msg('openstackmanager-displayquotas-cores', $limits->getCoresUsed(), $limits->getCoresAvailable()); $instances = $this->msg('openstackmanager-displayquotas-instances', $limits->getInstancesUsed(), $limits->getInstancesAvailable()); $secGroups = $this->msg('openstackmanager-displayquotas-securitygroups', $limits->getSecurityGroupsUsed(), $limits->getSecurityGroupsAvailable()); $limitsOut = Html::element('li', array(), $cores); $limitsOut .= Html::element('li', array(), $ram); $limitsOut .= Html::element('li', array(), $floatingIps); $limitsOut .= Html::element('li', array(), $instances); $limitsOut .= Html::element('li', array(), $secGroups); $limitsOut = Html::rawElement('ul', array(), $limitsOut); $limitsOut = Html::element('h2', array(), $region) . $limitsOut; $this->getOutput()->addHTML($limitsOut); } return true; }
/** * @return bool */ function removeRule() { $this->setHeaders(); $this->getOutput()->setPagetitle($this->msg('openstackmanager-removerule')); $project = $this->getRequest()->getText('project'); $region = $this->getRequest()->getText('region'); if (!$this->userLDAP->inRole('projectadmin', $project)) { $this->notInRole('projectadmin', $project); return false; } $groupid = $this->getRequest()->getText('groupid'); $ruleid = $this->getRequest()->getText('ruleid'); if (!$this->getRequest()->wasPosted()) { $securitygroup = $this->userNova->getSecurityGroup($groupid); if ($securitygroup) { $securitygroupname = $securitygroup->getGroupName(); $this->getOutput()->addWikiMsg('openstackmanager-removerule-confirm', $securitygroupname); } else { $this->getOutput()->addWikiMsg('openstackmanager-nonexistantsecuritygroup'); return false; } } $securityGroupInfo = array(); $securityGroupInfo['groupid'] = array('type' => 'hidden', 'default' => $groupid, 'name' => 'groupid'); $securityGroupInfo['ruleid'] = array('type' => 'hidden', 'default' => $ruleid, 'name' => 'ruleid'); $securityGroupInfo['project'] = array('type' => 'hidden', 'default' => $project, 'name' => 'project'); $securityGroupInfo['region'] = array('type' => 'hidden', 'default' => $region, 'name' => 'region'); $securityGroupInfo['action'] = array('type' => 'hidden', 'default' => 'removerule', 'name' => 'action'); $securityGroupForm = new HTMLForm($securityGroupInfo, $this->getContext(), 'openstackmanager-novasecuritygroup'); $securityGroupForm->setSubmitID('novainstance-form-removerulesubmit'); $securityGroupForm->setSubmitCallback(array($this, 'tryRemoveRuleSubmit')); $securityGroupForm->show(); return true; }
/** * @return bool */ function modifyPuppetGroup() { $this->setHeaders(); $this->getOutput()->setPagetitle($this->msg('openstackmanager-modifypuppetgroup')); $puppetGroupId = $this->getRequest()->getInt('puppetgroupid'); $group = OpenStackNovaPuppetGroup::newFromId($puppetGroupId); if (!$group) { $this->getOutput()->addWikiMsg('openstackmanager-nonexistentresource'); return false; } $puppetGroupName = $group->getName(); $project = $group->getProject(); if ($project) { // Project specific if (!$this->userLDAP->inRole('projectadmin', $project)) { $this->notInRole('projectadmin', $project); return false; } } else { // Global project - requires manageglobalpuppet if (!$this->userCanExecute($this->getUser())) { $this->displayRestrictionError(); return false; } } $puppetGroupInfo = array(); $puppetGroupInfo['puppetgroupid'] = array('type' => 'hidden', 'default' => $puppetGroupId, 'name' => 'puppetgroupid'); $puppetGroupInfo['puppetgroupname'] = array('type' => 'hidden', 'default' => $puppetGroupName, 'name' => 'puppetgroupname'); $puppetGroupInfo['action'] = array('type' => 'hidden', 'default' => 'modify', 'name' => 'action'); $puppetGroupForm = new HTMLForm($puppetGroupInfo, $this->getContext(), 'openstackmanager-novapuppetgroup'); $puppetGroupForm->setSubmitID('novapuppetgroup-form-modifypuppetgroupsubmit'); $puppetGroupForm->setSubmitCallback(array($this, 'tryModifyGroupSubmit')); $puppetGroupForm->show(); return true; }
/** * @return bool */ function removeRule() { $this->setHeaders(); $this->getOutput()->setPagetitle(wfMsg('openstackmanager-removerule')); $project = $this->getRequest()->getText('project'); if (!$this->userLDAP->inRole('netadmin', $project)) { $this->notInRole('netadmin'); return false; } $securitygroupname = $this->getRequest()->getText('groupname'); if (!$this->getRequest()->wasPosted()) { $this->getOutput()->addWikiMsg('openstackmanager-removerule-confirm', $securitygroupname); } $securityGroupInfo = array(); $securityGroupInfo['groupname'] = array('type' => 'hidden', 'default' => $securitygroupname, 'name' => 'groupname'); $securityGroupInfo['project'] = array('type' => 'hidden', 'default' => $project, 'name' => 'project'); $securityGroupInfo['fromport'] = array('type' => 'hidden', 'default' => $this->getRequest()->getText('fromport'), 'name' => 'fromport'); $securityGroupInfo['toport'] = array('type' => 'hidden', 'default' => $this->getRequest()->getText('toport'), 'name' => 'toport'); $securityGroupInfo['protocol'] = array('type' => 'hidden', 'default' => $this->getRequest()->getText('protocol'), 'name' => 'protocol'); if ($this->getRequest()->getText('ranges')) { $securityGroupInfo['ranges'] = array('type' => 'hidden', 'default' => $this->getRequest()->getText('ranges'), 'name' => 'ranges'); } if ($this->getRequest()->getText('groups')) { $securityGroupInfo['groups'] = array('type' => 'hidden', 'default' => $this->getRequest()->getText('groups'), 'name' => 'groups'); } $securityGroupInfo['action'] = array('type' => 'hidden', 'default' => 'removerule', 'name' => 'action'); $securityGroupForm = new SpecialNovaSecurityGroupForm($securityGroupInfo, 'openstackmanager-novasecuritygroup'); $securityGroupForm->setTitle(SpecialPage::getTitleFor('NovaSecurityGroup')); $securityGroupForm->setSubmitID('novainstance-form-removerulesubmit'); $securityGroupForm->setSubmitCallback(array($this, 'tryRemoveRuleSubmit')); $securityGroupForm->show(); return true; }
/** * @return bool */ function removeHost() { $this->setHeaders(); $this->getOutput()->setPagetitle($this->msg('openstackmanager-removehost')); $project = $this->getRequest()->getText('project'); $region = $this->getRequest()->getText('region'); if (!$this->userLDAP->inRole('projectadmin', $project)) { $this->notInRole('projectadmin', $project); return false; } $id = $this->getRequest()->getText('id'); $fqdn = $this->getRequest()->getText('fqdn'); $hostname = $this->getRequest()->getText('hostname'); if (!$this->getRequest()->wasPosted()) { $address = $this->userNova->getAddress($id); $ip = $address->getPublicIP(); $this->getOutput()->addWikiMsg('openstackmanager-removehost-confirm', $hostname, $ip); } $addressInfo = array(); $addressInfo['project'] = array('type' => 'hidden', 'default' => $project, 'name' => 'project'); $addressInfo['region'] = array('type' => 'hidden', 'default' => $region, 'name' => 'region'); $addressInfo['id'] = array('type' => 'hidden', 'default' => $id, 'name' => 'id'); $addressInfo['fqdn'] = array('type' => 'hidden', 'default' => $fqdn, 'name' => 'fqdn'); $addressInfo['hostname'] = array('type' => 'hidden', 'default' => $hostname, 'name' => 'hostname'); $addressInfo['action'] = array('type' => 'hidden', 'default' => 'removehost', 'name' => 'action'); $addressForm = new HTMLForm($addressInfo, $this->getContext(), 'openstackmanager-novaaddress'); $addressForm->setSubmitID('novaaddress-form-removehostsubmit'); $addressForm->setSubmitCallback(array($this, 'tryRemoveHostSubmit')); $addressForm->setSubmitText('confirm'); $addressForm->show(); return true; }
/** * @return bool */ function removeHost() { $this->setHeaders(); $this->getOutput()->setPagetitle(wfMsg('openstackmanager-removehost')); $project = $this->getRequest()->getText('project'); if (!$this->userLDAP->inRole('netadmin', $project)) { $this->notInRole('netadmin'); return false; } $userCredentials = $this->userLDAP->getCredentials(); $this->userNova = new OpenStackNovaController($userCredentials, $project); $ip = $this->getRequest()->getText('ip'); $domain = $this->getRequest()->getText('domain'); $hostname = $this->getRequest()->getText('hostname'); if (!$this->getRequest()->wasPosted()) { $this->getOutput()->addWikiMsg('openstackmanager-removehost-confirm', $hostname, $ip); } $addressInfo = array(); $addressInfo['project'] = array('type' => 'hidden', 'default' => $project, 'name' => 'project'); $addressInfo['ip'] = array('type' => 'hidden', 'default' => $ip, 'name' => 'ip'); $addressInfo['domain'] = array('type' => 'hidden', 'default' => $domain, 'name' => 'domain'); $addressInfo['hostname'] = array('type' => 'hidden', 'default' => $hostname, 'name' => 'hostname'); $addressInfo['action'] = array('type' => 'hidden', 'default' => 'removehost', 'name' => 'action'); $addressForm = new SpecialNovaAddressForm($addressInfo, 'openstackmanager-novaaddress'); $addressForm->setTitle(SpecialPage::getTitleFor('NovaAddress')); $addressForm->setSubmitID('novaaddress-form-removehostsubmit'); $addressForm->setSubmitCallback(array($this, 'tryRemoveHostSubmit')); $addressForm->setSubmitText('confirm'); $addressForm->show(); return true; }
/** * @return bool */ function detachVolume() { $this->setHeaders(); $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-detachvolume' ) ); $project = $this->getRequest()->getText( 'project' ); if ( ! $this->userLDAP->inRole( 'sysadmin', $project ) ) { $this->notInRole( 'sysadmin' ); return false; } $volumeInfo = array(); $volumeInfo['volumeinfo'] = array( 'type' => 'info', 'label-message' => 'openstackmanager-volumename', 'default' => $this->getRequest()->getText( 'volumeid' ), 'section' => 'volume/info', 'name' => 'volumeinfo', ); $volumeInfo['force'] = array( 'type' => 'toggle', 'label-message' => 'openstackmanager-forcedetachment', 'help-message' => 'openstackmanager-forcedetachmenthelp', 'section' => 'volume/info', 'name' => 'volumeinfo', ); $volumeInfo['volumeid'] = array( 'type' => 'hidden', 'default' => $this->getRequest()->getText( 'volumeid' ), 'name' => 'volumeid', ); $volumeInfo['project'] = array( 'type' => 'hidden', 'default' => $project, 'name' => 'project', ); $volumeInfo['action'] = array( 'type' => 'hidden', 'default' => 'detach', 'name' => 'action', ); $volumeForm = new SpecialNovaVolumeForm( $volumeInfo, 'openstackmanager-novavolume' ); $volumeForm->setTitle( SpecialPage::getTitleFor( 'NovaVolume' ) ); $volumeForm->setSubmitID( 'novavolume-form-detachvolumesubmit' ); $volumeForm->setSubmitCallback( array( $this, 'tryDetachSubmit' ) ); $volumeForm->show(); return true; }
/** * getUserPermissionsErrors hook * * @param Title $title * @param User $user * @param string $action * @param $result * @return bool */ public static function getUserPermissionsErrors(Title $title, User $user, $action, &$result) { if (!$title->inNamespace(NS_HIERA)) { return true; } if ($action === 'create' || $action === 'edit') { if (!$user->isLoggedIn()) { $result = array('openstackmanager-notloggedin'); return false; } $userLDAP = new OpenStackNovaUser(); if (!$userLDAP->exists()) { $result = array('openstackmanager-nonovacred-admincreate'); } $project = $title->getText(); if (!$userLDAP->inRole('projectadmin', $project) && !$user->isAllowed('editallhiera')) { $result = array('openstackmanager-hiera-noadmin', $project); return false; } } return true; }
/** * @return void */ function listInstances() { $this->setHeaders(); $this->getOutput()->addModuleStyles('ext.openstack'); $this->getOutput()->setPagetitle(wfMsg('openstackmanager-instancelist')); $userProjects = $this->userLDAP->getProjects(); $out = ''; $instances = $this->adminNova->getInstances(); $header = Html::element('th', array(), wfMsg('openstackmanager-instancename')); $header .= Html::element('th', array(), wfMsg('openstackmanager-instanceid')); $header .= Html::element('th', array(), wfMsg('openstackmanager-instancestate')); $header .= Html::element('th', array(), wfMsg('openstackmanager-instancetype')); $header .= Html::element('th', array(), wfMsg('openstackmanager-instanceip')); $header .= Html::element('th', array(), wfMsg('openstackmanager-instancepublicip')); $header .= Html::element('th', array(), wfMsg('openstackmanager-securitygroups')); $header .= Html::element('th', array(), wfMsg('openstackmanager-availabilityzone')); $header .= Html::element('th', array(), wfMsg('openstackmanager-imageid')); $header .= Html::element('th', array(), wfMsg('openstackmanager-launchtime')); $header .= Html::element('th', array(), wfMsg('openstackmanager-actions')); $projectArr = array(); /** * @var $instance OpenStackNovaInstance */ foreach ($instances as $instance) { $project = $instance->getOwner(); if (!in_array($project, $userProjects)) { continue; } $instanceOut = Html::element('td', array(), $instance->getInstanceName()); $instanceId = $instance->getInstanceId(); $instanceId = htmlentities($instanceId); $title = Title::newFromText($instanceId, NS_NOVA_RESOURCE); $instanceIdLink = Linker::link($title, $instanceId); $instanceOut .= Html::rawElement('td', array(), $instanceIdLink); $instanceOut .= Html::element('td', array(), $instance->getInstanceState()); $instanceOut .= Html::element('td', array(), $instance->getInstanceType()); $privateip = $instance->getInstancePrivateIP(); $publicip = $instance->getInstancePublicIP(); $instanceOut .= Html::element('td', array(), $privateip); if ($privateip != $publicip) { $instanceOut .= Html::element('td', array(), $publicip); } else { $instanceOut .= Html::element('td', array(), ''); } $groupsOut = ''; foreach ($instance->getSecurityGroups() as $group) { $groupsOut .= Html::element('li', array(), $group); } $groupsOut = Html::rawElement('ul', array(), $groupsOut); $instanceOut .= Html::rawElement('td', array(), $groupsOut); $instanceOut .= Html::element('td', array(), $instance->getAvailabilityZone()); $instanceOut .= Html::element('td', array(), $instance->getImageId()); $instanceOut .= Html::element('td', array(), $instance->getLaunchTime()); $actions = ''; if ($this->userLDAP->inRole('sysadmin', $project)) { $msg = wfMsgHtml('openstackmanager-delete'); $link = Linker::link($this->getTitle(), $msg, array(), array('action' => 'delete', 'project' => $project, 'instanceid' => $instance->getInstanceId())); $actions = Html::rawElement('li', array(), $link); $msg = wfMsgHtml('openstackmanager-reboot'); $link = Linker::link($this->getTitle(), $msg, array(), array('action' => 'reboot', 'project' => $project, 'instanceid' => $instance->getInstanceId())); $actions .= Html::rawElement('li', array(), $link); $msg = wfMsgHtml('openstackmanager-configure'); $link = Linker::link($this->getTitle(), $msg, array(), array('action' => 'configure', 'project' => $project, 'instanceid' => $instance->getInstanceId())); $actions .= Html::rawElement('li', array(), $link); $msg = wfMsgHtml('openstackmanager-getconsoleoutput'); $link = Linker::link($this->getTitle(), $msg, array(), array('action' => 'consoleoutput', 'project' => $project, 'instanceid' => $instance->getInstanceId())); $actions .= Html::rawElement('li', array(), $link); $actions = Html::rawElement('ul', array(), $actions); } $instanceOut .= Html::rawElement('td', array(), $actions); if (isset($projectArr["{$project}"])) { $projectArr["{$project}"] .= Html::rawElement('tr', array(), $instanceOut); } else { $projectArr["{$project}"] = Html::rawElement('tr', array(), $instanceOut); } } foreach ($userProjects as $project) { $action = ''; if ($this->userLDAP->inRole('sysadmin', $project)) { $action = Linker::link($this->getTitle(), wfMsgHtml('openstackmanager-createinstance'), array(), array('action' => 'create', 'project' => $project)); $action = Html::rawElement('span', array('id' => 'novaaction'), "[{$action}]"); } $projectName = Html::rawElement('span', array('class' => 'mw-customtoggle-' . $project, 'id' => 'novaproject'), $project); $out .= Html::rawElement('h2', array(), "{$projectName} {$action}"); $projectOut = ''; if (isset($projectArr["{$project}"])) { $projectOut .= $header; $projectOut .= $projectArr["{$project}"]; $projectOut = Html::rawElement('table', array('id' => 'novainstancelist', 'class' => 'wikitable sortable'), $projectOut); } $out .= Html::rawElement('div', array('class' => 'mw-collapsible', 'id' => 'mw-customcollapsible-' . $project), $projectOut); } $this->getOutput()->addHTML($out); }
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 ''; } }