Index: trunk/extensions/OpenStackManager/OpenStackNovaHost.php |
— | — | @@ -75,7 +75,7 @@ |
76 | 76 | $arecords = array(); |
77 | 77 | if ( isset( $this->hostInfo[0]['arecord'] ) ) { |
78 | 78 | $arecords = $this->hostInfo[0]['arecord']; |
79 | | - $arecords = array_shift( $arecords ); |
| 79 | + array_shift( $arecords ); |
80 | 80 | } |
81 | 81 | |
82 | 82 | return $arecords; |
— | — | @@ -85,7 +85,7 @@ |
86 | 86 | $associateddomain = array(); |
87 | 87 | if ( isset( $this->hostInfo[0]['associateddomain'] ) ) { |
88 | 88 | $associateddomain = $this->hostInfo[0]['associateddomain']; |
89 | | - $associateddomain = array_shift( $associateddomain ); |
| 89 | + array_shift( $associateddomain ); |
90 | 90 | } |
91 | 91 | |
92 | 92 | return $associateddomain; |
— | — | @@ -95,7 +95,7 @@ |
96 | 96 | $cnamerecords = array(); |
97 | 97 | if ( isset( $this->hostInfo[0]['cnamerecord'] ) ) { |
98 | 98 | $cnamerecords = $this->hostInfo[0]['cnamearecord']; |
99 | | - $cnamerecords = array_shift( $cnamerecords ); |
| 99 | + array_shift( $cnamerecords ); |
100 | 100 | } |
101 | 101 | |
102 | 102 | return $cnamerecords; |
Index: trunk/extensions/OpenStackManager/special/SpecialNovaAddress.php |
— | — | @@ -255,7 +255,7 @@ |
256 | 256 | ); |
257 | 257 | $addressForm = new SpecialNovaAddressForm( $addressInfo, 'openstackmanager-novaaddress' ); |
258 | 258 | $addressForm->setTitle( SpecialPage::getTitleFor( 'NovaAddress' ) ); |
259 | | - $addressForm->setSubmitID( 'novaaddress-form-disassociateaddresssubmit' ); |
| 259 | + $addressForm->setSubmitID( 'novaaddress-form-addhostsubmit' ); |
260 | 260 | $addressForm->setSubmitCallback( array( $this, 'tryAddHostSubmit' ) ); |
261 | 261 | $addressForm->show(); |
262 | 262 | |
— | — | @@ -263,6 +263,54 @@ |
264 | 264 | } |
265 | 265 | |
266 | 266 | 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; |
267 | 315 | } |
268 | 316 | |
269 | 317 | function listAddresses() { |
— | — | @@ -298,13 +346,18 @@ |
299 | 347 | $hosts = OpenStackNovaHost::getHostsByIP( $ip ); |
300 | 348 | if ( $hosts ) { |
301 | 349 | $hostsOut = ''; |
302 | | - $msg = wfMsg( 'openstackmanager-removehost' ); |
| 350 | + $msg = wfMsg( 'openstackmanager-removehost-action' ); |
303 | 351 | foreach ( $hosts as $host ) { |
304 | 352 | $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 | + } |
309 | 362 | } |
310 | 363 | $hostsOut = Html::rawElement( 'ul', array(), $hostsOut ); |
311 | 364 | $addressOut .= Html::rawElement( 'td', array(), $hostsOut ); |
— | — | @@ -375,6 +428,21 @@ |
376 | 429 | global $wgOut, $wgUser; |
377 | 430 | |
378 | 431 | $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 | + } |
379 | 447 | $success = $this->userNova->releaseAddress( $ip ); |
380 | 448 | if ( $success ) { |
381 | 449 | $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-releasedaddress', array(), $ip ) ); |
— | — | @@ -449,7 +517,7 @@ |
450 | 518 | $hostbyip = OpenStackNovaHost::getHostByIP( $ip, $domain ); |
451 | 519 | if ( $hostbyname ) { |
452 | 520 | # We need to add an arecord, if the arecord doesn't already exist |
453 | | - $success = $host->addARecord( $ip ); |
| 521 | + $success = $hostbyname->addARecord( $ip ); |
454 | 522 | if ( $success ) { |
455 | 523 | $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-addedhost', array(), $hostname, $ip ) ); |
456 | 524 | } else { |
— | — | @@ -457,7 +525,7 @@ |
458 | 526 | } |
459 | 527 | } else if ( $hostbyip ) { |
460 | 528 | # 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() ); |
462 | 530 | if ( $success ) { |
463 | 531 | $out = Html::element( 'p', array(), wfMsgExt( 'openstackmanager-addedhost', array(), $hostname, $ip ) ); |
464 | 532 | } else { |
— | — | @@ -479,6 +547,56 @@ |
480 | 548 | return true; |
481 | 549 | } |
482 | 550 | |
| 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 | + |
483 | 601 | function validateHostName( $hostname, $alldata ) { |
484 | 602 | if ( ! preg_match( "/^[a-z][a-z0-9\-]*$/", $hostname ) ) { |
485 | 603 | return Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'openstackmanager-badinstancename' ) ); |
Index: trunk/extensions/OpenStackManager/OpenStackManager.i18n.php |
— | — | @@ -148,6 +148,7 @@ |
149 | 149 | 'openstackmanager-allocateaddress-confirm' => 'Are you sure you would like to allocate a new public IP address in project $1?', |
150 | 150 | 'openstackmanager-releasedaddress' => 'Successfully released address: $1', |
151 | 151 | '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.', |
152 | 153 | 'openstackmanager-associatedaddress' => 'Successfully associated $1 with instance id $2', |
153 | 154 | 'openstackmanager-associateaddressfailed' => 'Failed to associate $1 with instance id $2', |
154 | 155 | 'openstackmanager-disassociatedaddress' => 'Successfully disassociated $1', |
— | — | @@ -161,7 +162,12 @@ |
162 | 163 | 'openstackmanager-hostname' => 'Host Name', |
163 | 164 | 'openstackmanager-hostnames' => 'Host Names', |
164 | 165 | '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', |
166 | 172 | |
167 | 173 | 'openstackmanager-needsysadminrole' => 'Sysadmin Role Required', |
168 | 174 | 'openstackmanager-needsysadminrole2' => 'You must be a member of the sysadmin role to perform this action.', |