/** * @return bool */ function attachVolume() { $this->setHeaders(); $this->getOutput()->setPagetitle($this->msg('openstackmanager-attachvolume')); $project = $this->getRequest()->getText('project'); $region = $this->getRequest()->getText('region'); if (!$this->userLDAP->inRole('projectadmin', $project)) { $this->notInRole('projectadmin', $project); return false; } $instances = $this->userNova->getInstances(); $instance_keys = array(); foreach ($instances as $instance) { if ($instance->getProject() === $project) { $instancename = $instance->getInstanceName(); $instanceid = $instance->getInstanceId(); $instance_keys[$instancename] = $instanceid; } } $volumeInfo = array(); $volumeInfo['volumeinfo'] = array('type' => 'info', 'label-message' => 'openstackmanager-volumename', 'default' => $this->getRequest()->getText('volumeid'), 'section' => 'volume/info', 'name' => 'volumeinfo'); $volumeInfo['volumeid'] = array('type' => 'hidden', 'default' => $this->getRequest()->getText('volumeid'), 'name' => 'volumeid'); $volumeInfo['volumedescription'] = array('type' => 'info', 'label-message' => 'openstackmanager-volumedescription', 'section' => 'volume/info', 'name' => 'volumedescription'); $volumeInfo['instanceid'] = array('type' => 'select', 'label-message' => 'openstackmanager-instancename', 'options' => $instance_keys, 'section' => 'volume/info', 'name' => 'instanceid'); $volumeInfo['device'] = array('type' => 'select', 'label-message' => 'openstackmanager-device', 'options' => $this->getDrives(), 'section' => 'volume/info', 'name' => 'device'); $volumeInfo['project'] = array('type' => 'hidden', 'default' => $project, 'name' => 'project'); $volumeInfo['region'] = array('type' => 'hidden', 'default' => $region, 'name' => 'region'); $volumeInfo['action'] = array('type' => 'hidden', 'default' => 'attach', 'name' => 'action'); $volumeForm = new HTMLForm($volumeInfo, $this->getContext(), 'openstackmanager-novavolume'); $volumeForm->setSubmitID('novavolume-form-attachvolumesubmit'); $volumeForm->setSubmitCallback(array($this, 'tryAttachSubmit')); $volumeForm->show(); return true; }
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 ''; }
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 ''; } }