r80118 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80117‎ | r80118 | r80119 >
Date:20:44, 12 January 2011
Author:laner
Status:deferred
Tags:
Comment:
Finished adding support for public DNS entry management
Modified paths:
  • /trunk/extensions/OpenStackManager/OpenStackManager.i18n.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaHost.php (modified) (history)
  • /trunk/extensions/OpenStackManager/special/SpecialNovaAddress.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/OpenStackNovaHost.php
@@ -75,7 +75,7 @@
7676 $arecords = array();
7777 if ( isset( $this->hostInfo[0]['arecord'] ) ) {
7878 $arecords = $this->hostInfo[0]['arecord'];
79 - $arecords = array_shift( $arecords );
 79+ array_shift( $arecords );
8080 }
8181
8282 return $arecords;
@@ -85,7 +85,7 @@
8686 $associateddomain = array();
8787 if ( isset( $this->hostInfo[0]['associateddomain'] ) ) {
8888 $associateddomain = $this->hostInfo[0]['associateddomain'];
89 - $associateddomain = array_shift( $associateddomain );
 89+ array_shift( $associateddomain );
9090 }
9191
9292 return $associateddomain;
@@ -95,7 +95,7 @@
9696 $cnamerecords = array();
9797 if ( isset( $this->hostInfo[0]['cnamerecord'] ) ) {
9898 $cnamerecords = $this->hostInfo[0]['cnamearecord'];
99 - $cnamerecords = array_shift( $cnamerecords );
 99+ array_shift( $cnamerecords );
100100 }
101101
102102 return $cnamerecords;
Index: trunk/extensions/OpenStackManager/special/SpecialNovaAddress.php
@@ -255,7 +255,7 @@
256256 );
257257 $addressForm = new SpecialNovaAddressForm( $addressInfo, 'openstackmanager-novaaddress' );
258258 $addressForm->setTitle( SpecialPage::getTitleFor( 'NovaAddress' ) );
259 - $addressForm->setSubmitID( 'novaaddress-form-disassociateaddresssubmit' );
 259+ $addressForm->setSubmitID( 'novaaddress-form-addhostsubmit' );
260260 $addressForm->setSubmitCallback( array( $this, 'tryAddHostSubmit' ) );
261261 $addressForm->show();
262262
@@ -263,6 +263,54 @@
264264 }
265265
266266 function removeHost() {
 267+ global $wgOut, $wgRequest;
 268+
 269+ $this->setHeaders();
 270+ $wgOut->setPagetitle( wfMsg( 'openstackmanager-removehost' ) );
 271+
 272+ $project = $wgRequest->getText( 'project' );
 273+ if ( ! $this->userLDAP->inRole( 'netadmin', $project ) ) {
 274+ $this->notInRole( 'netadmin' );
 275+ return false;
 276+ }
 277+ $userCredentials = $this->userLDAP->getCredentials( $project );
 278+ $this->userNova = new OpenStackNovaController( $userCredentials );
 279+ $ip = $wgRequest->getText( 'ip' );
 280+ $domain = $wgRequest->getText( 'domain' );
 281+ $hostname = $wgRequest->getText( 'hostname' );
 282+ if ( ! $wgRequest->wasPosted() ) {
 283+ $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-removehost-confirm', array(), $hostname, $ip ) );
 284+ $wgOut->addHTML( $out );
 285+ }
 286+ $addressInfo = Array();
 287+ $addressInfo['project'] = array(
 288+ 'type' => 'hidden',
 289+ 'default' => $project,
 290+ );
 291+ $addressInfo['ip'] = array(
 292+ 'type' => 'hidden',
 293+ 'default' => $ip,
 294+ );
 295+ $addressInfo['domain'] = array(
 296+ 'type' => 'hidden',
 297+ 'default' => $domain,
 298+ );
 299+ $addressInfo['hostname'] = array(
 300+ 'type' => 'hidden',
 301+ 'default' => $hostname,
 302+ );
 303+ $addressInfo['action'] = array(
 304+ 'type' => 'hidden',
 305+ 'default' => 'removehost',
 306+ );
 307+ $addressForm = new SpecialNovaAddressForm( $addressInfo, 'openstackmanager-novaaddress' );
 308+ $addressForm->setTitle( SpecialPage::getTitleFor( 'NovaAddress' ) );
 309+ $addressForm->setSubmitID( 'novaaddress-form-removehostsubmit' );
 310+ $addressForm->setSubmitCallback( array( $this, 'tryRemoveHostSubmit' ) );
 311+ $addressForm->setSubmitText( 'confirm' );
 312+ $addressForm->show();
 313+
 314+ return true;
267315 }
268316
269317 function listAddresses() {
@@ -298,13 +346,18 @@
299347 $hosts = OpenStackNovaHost::getHostsByIP( $ip );
300348 if ( $hosts ) {
301349 $hostsOut = '';
302 - $msg = wfMsg( 'openstackmanager-removehost' );
 350+ $msg = wfMsg( 'openstackmanager-removehost-action' );
303351 foreach ( $hosts as $host ) {
304352 $domain = $host->getDomain();
305 - $link = $sk->link( $this->getTitle(), $msg, array(),
306 - array( 'action' => 'removehost', 'ip' => $ip, 'project' => $project, 'domain' => $domain->getDomainName() ), array() );
307 - $hostOut = $host->getFullyQualifiedHostName() . ' ' . $link;
308 - $hostsOut .= Html::rawElement( 'li', array(), $hostOut );
 353+ $fqdns = $host->getAssociatedDomains();
 354+ foreach ( $fqdns as $fqdn ) {
 355+ $hostname = explode( '.', $fqdn );
 356+ $hostname = $hostname[0];
 357+ $link = $sk->link( $this->getTitle(), $msg, array(),
 358+ array( 'action' => 'removehost', 'ip' => $ip, 'project' => $project, 'domain' => $domain->getDomainName(), 'hostname' => $hostname ), array() );
 359+ $hostOut = $fqdn . ' ' . $link;
 360+ $hostsOut .= Html::rawElement( 'li', array(), $hostOut );
 361+ }
309362 }
310363 $hostsOut = Html::rawElement( 'ul', array(), $hostsOut );
311364 $addressOut .= Html::rawElement( 'td', array(), $hostsOut );
@@ -375,6 +428,21 @@
376429 global $wgOut, $wgUser;
377430
378431 $ip = $formData['ip'];
 432+ #TODO: Instead of throwing an error when host exist or the IP
 433+ # is associated, remove all host entries and disassociate the IP
 434+ # then release the address
 435+ $hosts = OpenStackNovaHost::getHostsByIP( $ip );
 436+ if ( $hosts ) {
 437+ $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-cannotreleaseaddress', array(), $ip ) );
 438+ $wgOut->addHTML( $out );
 439+ return false;
 440+ }
 441+ $address = $this->adminNova->getAddress( $ip );
 442+ if ( $address->getInstanceId() ) {
 443+ $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-cannotreleaseaddress', array(), $ip ) );
 444+ $wgOut->addHTML( $out );
 445+ return false;
 446+ }
379447 $success = $this->userNova->releaseAddress( $ip );
380448 if ( $success ) {
381449 $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-releasedaddress', array(), $ip ) );
@@ -449,7 +517,7 @@
450518 $hostbyip = OpenStackNovaHost::getHostByIP( $ip, $domain );
451519 if ( $hostbyname ) {
452520 # We need to add an arecord, if the arecord doesn't already exist
453 - $success = $host->addARecord( $ip );
 521+ $success = $hostbyname->addARecord( $ip );
454522 if ( $success ) {
455523 $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-addedhost', array(), $hostname, $ip ) );
456524 } else {
@@ -457,7 +525,7 @@
458526 }
459527 } else if ( $hostbyip ) {
460528 # We need to add an associateddomain, if the associateddomain doesn't already exist
461 - $success = $host->addAssociatedDomain( $hostname . '.' . $domain->getFullyQualifiedHostname() );
 529+ $success = $hostbyip->addAssociatedDomain( $hostname . '.' . $domain->getFullyQualifiedDomainName() );
462530 if ( $success ) {
463531 $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-addedhost', array(), $hostname, $ip ) );
464532 } else {
@@ -479,6 +547,56 @@
480548 return true;
481549 }
482550
 551+ function tryRemoveHostSubmit( $formData, $entryPoint = 'internal' ) {
 552+ global $wgOut, $wgUser;
 553+
 554+ $ip = $formData['ip'];
 555+ $project = $formData['project'];
 556+ $address = $this->adminNova->getAddress( $ip );
 557+ if ( ! $address ) {
 558+ $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-invalidaddress', array(), $ip ) );
 559+ $wgOut->addHTML( $out );
 560+ return false;
 561+ }
 562+ if ( $address->getProject() != $project ) {
 563+ $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-invalidaddressforproject', array(), $ip ) );
 564+ $wgOut->addHTML( $out );
 565+ return false;
 566+ }
 567+ $hostname = $formData['hostname'];
 568+ $domain = $formData['domain'];
 569+ $domain = OpenStackNovaDomain::getDomainByName( $domain );
 570+ $host = OpenStackNovaHost::getHostByName( $hostname, $domain );
 571+ if ( $host ) {
 572+ $fqdn = $hostname . '.' . $domain->getFullyQualifiedDomainName();
 573+ $records = $host->getAssociatedDomains();
 574+ if ( count( $records ) > 1 ) {
 575+ # We need to keep the host, but remove the fqdn
 576+ $success = $host->deleteAssociatedDomain( $fqdn );
 577+ if ( $success ) {
 578+ $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-removedhost', array(), $hostname, $ip ) );
 579+ } else {
 580+ $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-removehostfailed', array(), $ip, $instanceid ) );
 581+ }
 582+ } else {
 583+ # We need to remove the host entry
 584+ $success = OpenStackNovaHost::deleteHost( $hostname, $domain );
 585+ if ( $success ) {
 586+ $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-removedhost', array(), $hostname, $ip ) );
 587+ } else {
 588+ $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-removehostfailed', array(), $ip, $instanceid ) );
 589+ }
 590+ }
 591+ } else {
 592+ $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-nonexistenthost', array() ) );
 593+ }
 594+ $out .= '<br />';
 595+ $sk = $wgUser->getSkin();
 596+ $out .= $sk->link( $this->getTitle(), wfMsg( 'openstackmanager-backaddresslist' ), array(), array(), array() );
 597+ $wgOut->addHTML( $out );
 598+ return true;
 599+ }
 600+
483601 function validateHostName( $hostname, $alldata ) {
484602 if ( ! preg_match( "/^[a-z][a-z0-9\-]*$/", $hostname ) ) {
485603 return Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'openstackmanager-badinstancename' ) );
Index: trunk/extensions/OpenStackManager/OpenStackManager.i18n.php
@@ -148,6 +148,7 @@
149149 'openstackmanager-allocateaddress-confirm' => 'Are you sure you would like to allocate a new public IP address in project $1?',
150150 'openstackmanager-releasedaddress' => 'Successfully released address: $1',
151151 'openstackmanager-releaseaddressfailed' => 'Failed to release address: $1',
 152+ 'openstackmanager-cannotreleaseaddress' => 'Cannot release address that has DNS entries or is associated with an instance. Please remove all host entries and disassociate the IP before trying to release it.',
152153 'openstackmanager-associatedaddress' => 'Successfully associated $1 with instance id $2',
153154 'openstackmanager-associateaddressfailed' => 'Failed to associate $1 with instance id $2',
154155 'openstackmanager-disassociatedaddress' => 'Successfully disassociated $1',
@@ -161,7 +162,12 @@
162163 'openstackmanager-hostname' => 'Host Name',
163164 'openstackmanager-hostnames' => 'Host Names',
164165 'openstackmanager-addhost' => 'Add host name',
165 - 'openstackmanager-removehost' => '(Remove host name)',
 166+ 'openstackmanager-removehost' => 'Remove Host',
 167+ 'openstackmanager-removehost-action' => '(Remove host name)',
 168+ 'openstackmanager-removehost-confirm' => 'Are you sure you would like to remove host $1 from $2?',
 169+ 'openstackmanager-removedhost' => 'Successfully removed $1',
 170+ 'openstackmanager-removehostfailed' => 'Failed to remove $1',
 171+ 'openstackmanager-nonexistenthost' => 'The host requested does not exist',
166172
167173 'openstackmanager-needsysadminrole' => 'Sysadmin Role Required',
168174 'openstackmanager-needsysadminrole2' => 'You must be a member of the sysadmin role to perform this action.',

Status & tagging log