Ryan Lane has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/104144


Change subject: Fully qualify instance resource pages
......................................................................

Fully qualify instance resource pages

With multi-region support it's necessary to use FQDNs for instance
resource pages rather than basic instance IDs. This change switches
all instance links to FQDNs as well as article creation and deletion.
This change also adds a maintenance script that will rename existing
articles from IDs to FQDNs.

Change-Id: I828c216b45ef8b56e579b0e0b378fbb0388ab240
---
A maintenance/qualifyInstancePages.php
M nova/OpenStackNovaInstance.php
M special/SpecialNovaAddress.php
M special/SpecialNovaInstance.php
M special/SpecialNovaResources.php
5 files changed, 106 insertions(+), 24 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/OpenStackManager 
refs/changes/44/104144/1

diff --git a/maintenance/qualifyInstancePages.php 
b/maintenance/qualifyInstancePages.php
new file mode 100644
index 0000000..923cf1e
--- /dev/null
+++ b/maintenance/qualifyInstancePages.php
@@ -0,0 +1,61 @@
+<?php
+if ( getenv( 'MW_INSTALL_PATH' ) ) {
+       $IP = getenv( 'MW_INSTALL_PATH' );
+} else {
+       $IP = dirname( __FILE__ ) . '/../../..';
+}
+require_once( "$IP/maintenance/Maintenance.php" );
+
+class OpenStackNovaQualifyInstancePages extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Move instance pages from id to fqdn.";
+       }
+
+       public function execute() {
+               global $wgAuth;
+               global $wgOpenStackManagerLDAPUsername;
+               global $wgOpenStackManagerLDAPUserPassword;
+
+               $user = new OpenStackNovaUser( $wgOpenStackManagerLDAPUsername 
);
+               $userNova = OpenStackNovaController::newFromUser( $user );
+               $projects = OpenStackNovaProject::getAllProjects();
+               # HACK (please fix): Keystone doesn't deliver services and 
endpoints unless
+               # a project token is returned, so we need to feed it a project. 
Ideally this
+               # should be configurable, and not hardcoded like this.
+               $userNova->setProject( 'bastion' );
+               $userNova->authenticate( $wgOpenStackManagerLDAPUsername, 
$wgOpenStackManagerLDAPUserPassword );
+               $regions = $userNova->getRegions( 'compute' );
+               foreach ( $regions as $region ) {
+                       $this->output( "Running region: " . $region . "\n" );
+                       foreach ( $projects as $project ) {
+                               $projectName = $project->getProjectName();
+                               $this->output( "Running project: " . 
$projectName . "\n" );
+                               $userNova->setProject( $projectName );
+                               $userNova->setRegion( $region );
+                               $instances = $userNova->getInstances();
+                               if ( ! $instances ) {
+                                       $wgAuth->printDebug( "No instance, 
continuing", NONSENSITIVE );
+                                       continue;
+                               }
+                               foreach ( $instances as $instance ) {
+                                       $host = $instance->getHost();
+                                       if ( !$host ) {
+                                               $this->output( "Skipping 
instance due to missing host entry: " . $instance->getInstanceId() . "\n" );
+                                               continue;
+                                       }
+                                       $this->output( "Renaming instance: " . 
$instance->getInstanceId() . "\n" );
+                                       $ot = Title::newFromText( 
$instance->getInstanceId(), NS_NOVA_RESOURCE );
+                                       $nt = Title::newFromText( 
$host->getFullyQualifiedHostName(), NS_NOVA_RESOURCE );
+                                       $ot->moveTo( $nt, false, 'Maintenance 
script move from id to fqdn.' );
+                               }
+                       }
+               }
+
+               $this->output( "Done.\n" );
+       }
+
+}
+
+$maintClass = "OpenStackNovaQualifyInstancePages";
+require_once( RUN_MAINTENANCE_IF_MAIN );
diff --git a/nova/OpenStackNovaInstance.php b/nova/OpenStackNovaInstance.php
index 44d5325..bfd2197 100644
--- a/nova/OpenStackNovaInstance.php
+++ b/nova/OpenStackNovaInstance.php
@@ -279,22 +279,24 @@
                        return;
                }
 
-        // There might already be an autogenerated instance status on this 
page,
-        // so set it aside in $instanceStatus.  We'll re-insert it at
-        // the start of the new page.
-        $instanceStatus = '';
-        $oldtext = OpenStackNovaArticle::getText( $this->getInstanceId() );
-        if ( $oldtext ) {
-            $startFlag = '<!-- autostatus begin -->';
-            $endFlag = '<!-- autostatus end -->';
-            $statusStart = strpos( $oldtext, $startFlag );
-            if ($statusStart !== false) {
-                $statusEnd = strpos( $oldtext, $endFlag, $statusStart );
-                if ( $statusEnd !== false ) {
-                    $instanceStatus = substr( $oldtext, $statusStart, 
$statusEnd - $statusStart + strlen( $endFlag ) );
-                }
-            }
-        }
+               $host = $this->getHost();
+
+               // There might already be an autogenerated instance status on 
this page,
+               // so set it aside in $instanceStatus.  We'll re-insert it at
+               // the start of the new page.
+               $instanceStatus = '';
+               $oldtext = OpenStackNovaArticle::getText( 
$host->getFullyQualifiedHostName() );
+               if ( $oldtext ) {
+                   $startFlag = '<!-- autostatus begin -->';
+                   $endFlag = '<!-- autostatus end -->';
+                   $statusStart = strpos( $oldtext, $startFlag );
+                   if ($statusStart !== false) {
+                       $statusEnd = strpos( $oldtext, $endFlag, $statusStart );
+                       if ( $statusEnd !== false ) {
+                           $instanceStatus = substr( $oldtext, $statusStart, 
$statusEnd - $statusStart + strlen( $endFlag ) );
+                       }
+                   }
+               }
 
                $format = <<<RESOURCEINFO
 %s
@@ -308,7 +310,6 @@
 |Puppet Class=%s
 |Puppet Var=%s}}
 RESOURCEINFO;
-               $host = $this->getHost();
                $puppetinfo = $host->getPuppetConfiguration();
                if ( $puppetinfo['puppetclass'] ) {
                        $puppetclasses = implode( ',', 
$puppetinfo['puppetclass'] );
@@ -332,11 +333,14 @@
                        $puppetclasses,
                        $puppetvars
                );
-               OpenStackNovaArticle::editArticle( $this->getInstanceId(), 
$text );
+               OpenStackNovaArticle::editArticle( 
$host->getFullyQualifiedHostName(), $text );
        }
 
        function deleteArticle() {
-               OpenStackNovaArticle::deleteArticle( $this->getInstanceId() );
+               $host = $this->getHost();
+               if ( $host ) {
+                       OpenStackNovaArticle::deleteArticle( 
$host->getFullyQualifiedHostName() );
+               }
        }
 
        function deleteInstance( $userNova ) {
diff --git a/special/SpecialNovaAddress.php b/special/SpecialNovaAddress.php
index 68d1130..4927307 100644
--- a/special/SpecialNovaAddress.php
+++ b/special/SpecialNovaAddress.php
@@ -458,9 +458,16 @@
                        if ( $instanceosid ) {
                                $instancename = 
$instances[$instanceosid]->getInstanceName();
                                $instanceid = 
$instances[$instanceosid]->getInstanceId();
-                               $this->pushRawResourceColumn( $addressRow, 
$this->createResourceLink( $instanceid ), array(
-                                       'class' => 'instance-id'
-                               ) );
+                               $host = $instances[$instanceosid]->getHost();
+                               if ( $host ) {
+                                       $this->pushRawResourceColumn( 
$addressRow, $this->createResourceLink( $host->getFullyQualifiedHostName() ), 
array(
+                                               'class' => 'instance-id'
+                                       ) );
+                               } else {
+                                       $this->pushResourceColumn( $addressRow, 
$instanceid, array(
+                                               'class' => 'instance-id'
+                                       ) );
+                               }
                                $this->pushResourceColumn( $addressRow, 
$instancename, array(
                                        'class' => 'instance-name'
                                ) );
diff --git a/special/SpecialNovaInstance.php b/special/SpecialNovaInstance.php
index 5e42e9f..80e6ff0 100644
--- a/special/SpecialNovaInstance.php
+++ b/special/SpecialNovaInstance.php
@@ -528,7 +528,12 @@
                foreach ( $instances as $instance ) {
                        $instanceRow = array();
                        $this->pushResourceColumn( $instanceRow, 
$instance->getInstanceName(), array( 'class' => 'novainstancename' ) );
-                       $this->pushRawResourceColumn( $instanceRow, 
$this->createResourceLink( $instance->getInstanceId() ), array( 'class' => 
'novainstanceid' ) );
+                       $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 ) {
diff --git a/special/SpecialNovaResources.php b/special/SpecialNovaResources.php
index 5d98568..deae965 100644
--- a/special/SpecialNovaResources.php
+++ b/special/SpecialNovaResources.php
@@ -129,7 +129,12 @@
 
                        $instanceRow = array();
                        $this->pushResourceColumn( $instanceRow, 
$instance->getInstanceName(), array( 'class' => 'novainstancename' ) );
-                       $this->pushRawResourceColumn( $instanceRow, 
$this->createResourceLink( $instance->getInstanceId() ), array( 'class' => 
'novainstanceid' ) );
+                       $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 ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/104144
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I828c216b45ef8b56e579b0e0b378fbb0388ab240
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OpenStackManager
Gerrit-Branch: master
Gerrit-Owner: Ryan Lane <rl...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to