/** * @return void */ function listDomains() { $this->setHeaders(); $this->getOutput()->setPagetitle($this->msg('openstackmanager-domainlist')); $this->getOutput()->addModuleStyles('ext.openstack'); $domainInfo = array(); $domainInfo['domainname'] = array('type' => 'text', 'label-message' => 'openstackmanager-domainname', 'default' => '', 'section' => 'domain', 'name' => 'domainname'); $domainInfo['fqdn'] = array('type' => 'text', 'label-message' => 'openstackmanager-fqdn', 'default' => '', 'section' => 'domain', 'name' => 'fqdn'); $domainInfo['location'] = array('type' => 'text', 'label-message' => 'openstackmanager-location', 'default' => '', 'section' => 'domain', 'help-message' => 'openstackmanager-location-help', 'name' => 'location'); $domainInfo['action'] = array('type' => 'hidden', 'default' => 'create', 'name' => 'action'); $domainForm = new HTMLForm($domainInfo, $this->getContext(), 'openstackmanager-novadomain'); $domainForm->setSubmitID('novadomain-form-createdomainsubmit'); $domainForm->setSubmitCallback(array($this, 'tryCreateSubmit')); $domainForm->show(); $headers = array('openstackmanager-domainname', 'openstackmanager-fqdn', 'openstackmanager-location', 'openstackmanager-actions'); $domains = OpenStackNovaDomain::getAllDomains(); $domainRows = array(); foreach ($domains as $domain) { $domainRow = array(); $domainName = $domain->getDomainName(); $this->pushResourceColumn($domainRow, $domainName); $this->pushResourceColumn($domainRow, $domain->getFullyQualifiedDomainName()); $this->pushResourceColumn($domainRow, $domain->getLocation()); $this->pushRawResourceColumn($domainRow, $this->createActionLink('openstackmanager-delete', array('action' => 'delete', 'domainname' => $domainName))); $domainRows[] = $domainRow; } if ($domainRows) { $out = $this->createResourceTable($headers, $domainRows); } else { $out = ''; } $this->getOutput()->addHTML($out); }
/** * @return bool */ function createProxy() { $this->setHeaders(); $this->getOutput()->setPagetitle($this->msg('openstackmanager-createproxy')); if (!$this->userLDAP->inRole('projectadmin', $this->projectName)) { $this->notInRole('projectadmin', $this->projectName); return false; } $instance_keys = array(); $region = $this->getRequest()->getText('region'); $this->userNova->setRegion($region); $instances = $this->userNova->getInstances(); foreach ($instances as $instance) { if ($instance->getProject() === $this->projectName) { if ($instance->getHost()) { $instancename = $instance->getHost()->getFullyQualifiedDisplayName(); $instance_keys[$instancename] = $instancename; } } } ksort($instance_keys); $domains = OpenStackNovaDomain::getAllDomains('public'); $domain_keys = array(); foreach ($domains as $domain) { $domainname = $domain->getDomainName(); $fqdn = $domain->getFullyQualifiedDomainName(); $domain_keys[$fqdn] = $domainname; } ksort($domain_keys); $proxyInfo = array(); $proxyInfo['proxyname'] = array('type' => 'text', 'label-message' => 'openstackmanager-proxyname', 'default' => '', 'section' => 'frontend', 'name' => 'proxyname'); $proxyInfo['domain'] = array('type' => 'select', 'options' => $domain_keys, 'label-message' => 'openstackmanager-dnsdomain', 'section' => 'frontend', 'name' => 'domain', 'default' => 'wmflabs'); $proxyInfo['backendhost'] = array('type' => 'select', 'label-message' => 'openstackmanager-proxybackend', 'options' => $instance_keys, 'section' => 'backend', 'name' => 'backendhost'); $proxyInfo['backendport'] = array('type' => 'text', 'label-message' => 'openstackmanager-proxyport', 'default' => '80', 'section' => 'backend', 'name' => 'backendport'); $proxyInfo['action'] = array('type' => 'hidden', 'default' => 'create', 'name' => 'action'); $proxyInfo['region'] = array('type' => 'hidden', 'default' => $region, 'name' => 'region'); $proxyInfo['project'] = array('type' => 'hidden', 'default' => $this->projectName, 'name' => 'project'); $proxyForm = new HTMLForm($proxyInfo, $this->getContext(), 'openstackmanager-novaproxy'); $proxyForm->setSubmitID('novaproxy-form-createproxysubmit'); $proxyForm->setSubmitCallback(array($this, 'tryCreateSubmit')); $proxyForm->show(); return true; }
/** * @return bool */ function createInstance() { global $wgOpenStackManagerPuppetOptions; global $wgOpenStackManagerInstanceDefaultImage; $this->setHeaders(); $this->getOutput()->setPagetitle(wfMsg('openstackmanager-createinstance')); $project = $this->getRequest()->getText('project'); if (!$this->userLDAP->inRole('sysadmin', $project)) { $this->notInRole('sysadmin'); 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->adminNova->getInstanceTypes(); $instanceType_keys = array(); foreach ($instanceTypes as $instanceType) { $instanceTypeName = $instanceType->getInstanceTypeName(); $cpus = $instanceType->getNumberOfCPUs(); $ram = $instanceType->getMemorySize(); $storage = $instanceType->getStorageSize(); $instanceLabel = $instanceTypeName . ' (' . wfMsgExt('openstackmanager-instancetypelabel', 'parsemag', $cpus, $ram, $storage) . ')'; $instanceType_keys["{$instanceLabel}"] = $instanceTypeName; } $instanceInfo['instanceType'] = array('type' => 'select', 'label-message' => 'openstackmanager-instancetype', 'section' => 'info', 'options' => $instanceType_keys, 'name' => 'instanceType'); # Availability zone names can't be translated. Get the keys, and make an array # where the name points to itself as a value $availabilityZones = $this->adminNova->getAvailabilityZones(); $availabilityZone_keys = array(); foreach (array_keys($availabilityZones) as $availabilityZone_key) { $availabilityZone_keys["{$availabilityZone_key}"] = $availabilityZone_key; } $instanceInfo['availabilityZone'] = array('type' => 'select', 'section' => 'info', 'options' => $availabilityZone_keys, 'label-message' => 'openstackmanager-availabilityzone', 'name' => 'availabilityZone'); # Image names can't be translated. Get the image, and make an array # where the name points to itself as a value $images = $this->adminNova->getImages(); $image_keys = array(); $default = ""; foreach ($images as $image) { if (!$image->imageIsPublic()) { continue; } if ($image->getImageState() != "available") { continue; } if ($image->getImageType() != "machine") { continue; } $imageName = $image->getImageName(); if ($imageName == '') { continue; } $imageLabel = $imageName . ' (' . $image->getImageArchitecture() . ')'; if ($image->getImageId() == $wgOpenStackManagerInstanceDefaultImage) { $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->adminNova->getSecurityGroups(); $group_keys = array(); $defaults = array(); foreach ($securityGroups as $securityGroup) { if ($securityGroup->getOwner() == $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'); if ($wgOpenStackManagerPuppetOptions['enabled']) { $this->setPuppetInfo($instanceInfo); } $instanceInfo['action'] = array('type' => 'hidden', 'default' => 'create', 'name' => 'action'); $instanceForm = new SpecialNovaInstanceForm($instanceInfo, 'openstackmanager-novainstance'); $instanceForm->setTitle(SpecialPage::getTitleFor('NovaInstance')); $instanceForm->addHeaderText(wfMsg('openstackmanager-createinstancepuppetwarning') . '<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; }
/** * @return void */ function listDomains() { $this->setHeaders(); $this->getOutput()->setPagetitle(wfMsg('openstackmanager-domainlist')); $domainInfo = array(); $domainInfo['domainname'] = array('type' => 'text', 'label-message' => 'openstackmanager-domainname', 'default' => '', 'section' => 'domain', 'name' => 'domainname'); $domainInfo['fqdn'] = array('type' => 'text', 'label-message' => 'openstackmanager-fqdn', 'default' => '', 'section' => 'domain', 'name' => 'fqdn'); $domainInfo['location'] = array('type' => 'text', 'label-message' => 'openstackmanager-location', 'default' => '', 'section' => 'domain', 'help-message' => 'openstackmanager-location-help', 'name' => 'location'); $domainInfo['action'] = array('type' => 'hidden', 'default' => 'create', 'name' => 'action'); $domainForm = new SpecialNovaDomainForm($domainInfo, 'openstackmanager-novadomain'); $domainForm->setTitle(SpecialPage::getTitleFor('NovaDomain')); $domainForm->setSubmitID('novadomain-form-createdomainsubmit'); $domainForm->setSubmitCallback(array($this, 'tryCreateSubmit')); $domainForm->show(); $out = ''; $domainsOut = Html::element('th', array(), wfMsg('openstackmanager-domainname')); $domainsOut .= Html::element('th', array(), wfMsg('openstackmanager-fqdn')); $domainsOut .= Html::element('th', array(), wfMsg('openstackmanager-location')); $domainsOut .= Html::element('th', array(), wfMsg('openstackmanager-actions')); $domains = OpenStackNovaDomain::getAllDomains(); foreach ($domains as $domain) { $domainName = $domain->getDomainName(); $fqdn = $domain->getFullyQualifiedDomainName(); $location = $domain->getLocation(); $domainOut = Html::element('td', array(), $domainName); $domainOut .= Html::element('td', array(), $fqdn); $domainOut .= Html::element('td', array(), $location); $msg = wfMsgHtml('openstackmanager-delete'); $link = Linker::link($this->getTitle(), $msg, array(), array('action' => 'delete', 'domainname' => $domainName)); $domainOut .= Html::rawElement('td', array(), $link); $domainsOut .= Html::rawElement('tr', array(), $domainOut); } if ($domains) { $out .= Html::rawElement('table', array('class' => 'wikitable sortable collapsible'), $domainsOut); } $this->getOutput()->addHTML($out); }
/** * @return bool */ function addHost() { $this->setHeaders(); $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-addhost' ) ); $project = $this->getRequest()->getText( 'project' ); if ( ! $this->userLDAP->inRole( 'netadmin', $project ) ) { $this->notInRole( 'netadmin' ); return false; } $ip = $this->getRequest()->getText( 'ip' ); $addressInfo = array(); $addressInfo['project'] = array( 'type' => 'hidden', 'default' => $project, 'name' => 'project', ); $addressInfo['ip'] = array( 'type' => 'hidden', 'default' => $ip, 'name' => 'ip', ); $addressInfo['hostname'] = array( 'type' => 'text', 'default' => '', 'validation-callback' => array( $this, 'validateDomain' ), 'label-message' => 'openstackmanager-hostname', 'name' => 'hostname', ); $domains = OpenStackNovaDomain::getAllDomains( 'public' ); $domain_keys = array(); foreach ( $domains as $domain ) { $domainname = $domain->getDomainName(); $domain_keys["$domainname"] = $domainname; } $addressInfo['domain'] = array( 'type' => 'select', 'options' => $domain_keys, 'label-message' => 'openstackmanager-dnsdomain', 'name' => 'domain', ); $addressInfo['action'] = array( 'type' => 'hidden', 'default' => 'addhost', 'name' => 'action', ); $addressForm = new SpecialNovaAddressForm( $addressInfo, 'openstackmanager-novaaddress' ); $addressForm->setTitle( SpecialPage::getTitleFor( 'NovaAddress' ) ); $addressForm->setSubmitID( 'novaaddress-form-addhostsubmit' ); $addressForm->setSubmitCallback( array( $this, 'tryAddHostSubmit' ) ); $addressForm->show(); return true; }