Andrew Bogott has uploaded a new change for review.

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


Change subject: Require user to specify region for a given instance.
......................................................................

Require user to specify region for a given instance.

Change-Id: I61c6549c4acc61de8ec4c2c04a0adfb28f4db7d2
---
M maintenance/puppetValues.php
1 file changed, 14 insertions(+), 5 deletions(-)


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

diff --git a/maintenance/puppetValues.php b/maintenance/puppetValues.php
index 09abc79..4b400b8 100644
--- a/maintenance/puppetValues.php
+++ b/maintenance/puppetValues.php
@@ -40,6 +40,7 @@
        public function __construct() {
                parent::__construct();
                $this->addOption( 'instance', 'The instance hostname, e.g. 
i-00000001', false, true );
+               $this->addOption( 'region', 'The instance region, e.g. pmtpa', 
false, true );
                $this->addOption( 'all-instances', 'Run this command on every 
instance.', false, false );
                $this->addOption( 'delete-var', 'The variable name to delete', 
false, true );
                $this->addOption( 'delete-class', 'The class index to delete', 
false, true );
@@ -53,6 +54,9 @@
                global $wgOpenStackManagerLDAPUserPassword;
 
                if ( $this->hasOption( 'all-instances' ) ) {
+                       if ( $this->hasOption( 'region' ) ) {
+                               $this->error( "--all-instances cannot be used 
with --region.\n", true );
+                       }
                        $instancelist = array();
                        $user = new OpenStackNovaUser( 
$wgOpenStackManagerLDAPUsername );
                        $userNova = OpenStackNovaController::newFromUser( $user 
);
@@ -69,13 +73,16 @@
                                        if ( $instances ) {
                                                foreach ( $instances as 
$instance ) {
                                                        $id = 
$instance->getInstanceId();
-                                                       $instancelist[] = 
$instance->getInstanceId();
+                                                       $instancelist[] = 
array( $instance->getInstanceId(), $region );
                                                }
                                        }
                                }
                        }
                } elseif ( $this->hasOption( 'instance' ) )  {
-                       $instancelist = array( $this->getOption( 'instance' ) );
+                       if ( ! $this->hasOption( 'region' ) ) {
+                               $this->error( "--instance requires 
--region.\n", true );
+                       }
+                       $instancelist = array( array( $this->getOption( 
'instance' ), $this->getOption( 'region' ) ) );
                } else {
                        $this->error( "Must specify either --instance or 
--all-instances.\n", true );
                }
@@ -84,9 +91,11 @@
                        $this->error( "Couldn't find OpenStackNovaHost 
class.\n", true );
                }
                OpenStackNovaLdapConnection::connect();
-               foreach ( $instancelist as $instance ) {
-                       print "\nFor instance $instance:\n\n";
-                       $host = OpenStackNovaHost::getHostByInstanceId( 
$instance );
+               foreach ( $instancelist as $instancepair ) {
+                       $instance = $instancepair[0];
+                       $instanceregion = $instancepair[1];
+                       print "\nFor instance $instance in region 
$instanceregion:\n\n";
+                       $host = OpenStackNovaHost::getHostByInstanceId( 
$instance, $instanceregion );
                        $puppetconf = $host->getPuppetConfiguration();
                        $puppetclasses = $puppetconf['puppetclass'];
                        $puppetvars = $puppetconf['puppetvar'];

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I61c6549c4acc61de8ec4c2c04a0adfb28f4db7d2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OpenStackManager
Gerrit-Branch: master
Gerrit-Owner: Andrew Bogott <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to