/**
  * Handle ?action=create
  * @return bool
  */
 function createInstance()
 {
     global $wgOpenStackManagerPuppetOptions;
     global $wgOpenStackManagerInstanceBannedInstanceTypes;
     global $wgOpenStackManagerInstanceDefaultImage;
     $this->setHeaders();
     $this->getOutput()->setPagetitle($this->msg('openstackmanager-createinstance'));
     $project = $this->getRequest()->getText('project');
     $region = $this->getRequest()->getText('region');
     if (!$this->userLDAP->inRole('projectadmin', $project)) {
         $this->notInRole('projectadmin', $project);
         return false;
     }
     $instanceInfo = array();
     $instanceInfo['instancename'] = array('type' => 'text', 'label-message' => 'openstackmanager-instancename', 'validation-callback' => array($this, 'validateText'), 'default' => '', 'section' => 'info', 'name' => 'instancename');
     $instanceTypes = $this->userNova->getInstanceTypes();
     $instanceType_keys = array();
     foreach ($instanceTypes as $instanceType) {
         $instanceTypeName = $instanceType->getInstanceTypeName();
         if (in_array($instanceTypeName, $wgOpenStackManagerInstanceBannedInstanceTypes)) {
             continue;
         }
         $instanceTypeId = $instanceType->getInstanceTypeId();
         $cpus = $instanceType->getNumberOfCPUs();
         $ram = $instanceType->getMemorySize();
         $root_storage = $instanceType->getRootStorageSize();
         $storage = $instanceType->getStorageSize();
         // @todo FIXME: Hard coded parentheses.
         $instanceLabel = $instanceTypeName . ' (' . $this->msg('openstackmanager-instancetypelabel', $cpus, $ram, $root_storage, $storage)->text() . ')';
         $instanceType_keys[$instanceLabel] = $instanceTypeId;
     }
     $instanceInfo['instanceType'] = array('type' => 'select', 'label-message' => 'openstackmanager-instancetype', 'section' => 'info', 'options' => $instanceType_keys, 'name' => 'instanceType');
     $instanceInfo['region'] = array('type' => 'hidden', 'default' => $region, 'name' => 'region');
     # Image names can't be translated. Get the image, and make an array
     # where the name points to itself as a value
     $images = $this->userNova->getImages();
     $image_keys = array();
     $default = "";
     foreach ($images as $image) {
         if ($image->getImageState() !== "ACTIVE") {
             continue;
         }
         $imageName = $image->getImageName();
         if ($imageName === '') {
             continue;
         }
         $showImage = $image->getImageMetadata('show');
         if (!$showImage) {
             continue;
         }
         $imageLabel = $imageName;
         $isDefault = $image->getImageMetadata('default');
         if ($isDefault) {
             $default = $imageLabel;
         }
         $image_keys[$imageLabel] = $image->getImageId();
     }
     if (isset($image_keys[$default])) {
         $default = $image_keys[$default];
     }
     $instanceInfo['imageType'] = array('type' => 'select', 'section' => 'info', 'options' => $image_keys, 'default' => $default, 'label-message' => 'openstackmanager-imagetype', 'name' => 'imageType');
     # Keypair names can't be translated. Get the keys, and make an array
     # where the name points to itself as a value
     # TODO: get keypairs as the user, not the admin
     # $keypairs = $this->userNova->getKeypairs();
     # $keypair_keys = array();
     # foreach ( array_keys( $keypairs ) as $keypair_key ) {
     #	$keypair_keys[$keypair_key] = $keypair_key;
     # }
     # $instanceInfo['keypair'] = array(
     #	'type' => 'select',
     #	'section' => 'info',
     #	'options' => $keypair_keys,
     #	'label-message' => 'keypair',
     # );
     #$domains = OpenStackNovaDomain::getAllDomains( 'local' );
     #$domain_keys = array();
     #foreach ( $domains as $domain ) {
     #	$domainname = $domain->getDomainName();
     #	$domain_keys[$domainname] = $domainname;
     #}
     #$instanceInfo['domain'] = array(
     #	'type' => 'select',
     #	'section' => 'info',
     #	'options' => $domain_keys,
     #	'label-message' => 'openstackmanager-dnsdomain',
     #	'name' => 'domain',
     #);
     $securityGroups = $this->userNova->getSecurityGroups();
     $group_keys = array();
     $defaults = array();
     foreach ($securityGroups as $securityGroup) {
         if ($securityGroup->getProject() === $project) {
             $securityGroupName = $securityGroup->getGroupName();
             $group_keys[$securityGroupName] = $securityGroupName;
             if ($securityGroupName === "default") {
                 $defaults["default"] = "default";
             }
         }
     }
     $instanceInfo['groups'] = array('type' => 'multiselect', 'section' => 'info', 'options' => $group_keys, 'default' => $defaults, 'label-message' => 'openstackmanager-securitygroups', 'name' => 'groups');
     $instanceInfo['project'] = array('type' => 'hidden', 'default' => $project, 'name' => 'project');
     $instanceInfo['action'] = array('type' => 'hidden', 'default' => 'create', 'name' => 'action');
     $instanceForm = new HTMLForm($instanceInfo, $this->getContext(), 'openstackmanager-novainstance');
     $instanceForm->addHeaderText($this->msg('openstackmanager-createinstancepuppetwarning')->text() . '<div class="mw-collapsible mw-collapsed">', 'puppetinfo');
     $instanceForm->addFooterText('</div>', 'puppetinfo');
     $instanceForm->setSubmitID('openstackmanager-novainstance-createinstancesubmit');
     $instanceForm->setSubmitCallback(array($this, 'tryCreateSubmit'));
     $instanceForm->show();
     return true;
 }