Andrew Bogott has submitted this change and it was merged.

Change subject: Add puppetcopy and puppetcopyregion args to createInstance.
......................................................................


Add puppetcopy and puppetcopyregion args to createInstance.

Change-Id: I44db7809f0e893dfb1ce56564643e714e949945f
---
M maintenance/createInstance.php
1 file changed, 39 insertions(+), 6 deletions(-)

Approvals:
  Andrew Bogott: Verified; Looks good to me, approved
  jenkins-bot: Checked



diff --git a/maintenance/createInstance.php b/maintenance/createInstance.php
index f7900a4..2c491a3 100644
--- a/maintenance/createInstance.php
+++ b/maintenance/createInstance.php
@@ -45,26 +45,59 @@
                $this->addOption( 'image', 'The image ID to use when creating', 
true, true );
                $this->addOption( 'flavor', 'The flavor of the new instance, 
e.g. m1.small', true, true );
                $this->addOption( 'securitygroups', 'Comma-separated list of 
security groups for new instance', false, true );
-               $this->addOption( 'puppetclasses', 'Comma-separated list of 
security groups for new instance', false, true );
+               $this->addOption( 'copypuppet', 'Instance id to copy puppet 
settings from', false, true );
+               $this->addOption( 'copypuppetregion', 'Region for copypuppet 
instance.', false, true );
        }
 
        public function execute() {
                global $wgAuth;
                global $wgOpenStackManagerLDAPUsername;
                global $wgOpenStackManagerLDAPUserPassword;
+               global $wgOpenStackManagerPuppetOptions;
 
 
+               $region = $this->getOption( 'region' );
                if ( $this->hasOption( 'securitygroups' ) ) {
                        $secGroups = explode(',', $this->getOption( 
'securitygroups' ) );
                } else {
                        $secGroups = array();
                }
-               if ( $this->hasOption( 'puppetclasses' ) ) {
-                       $pupClasses = explode(',', $this->getOption( 
'puppetclasses' ) );
+               if ( $this->hasOption( 'copypuppetregion' ) ) {
+                       $copypuppetregion = $this->getOption( 
'copypuppetregion' );
                } else {
-                       $pupClasses = array();
+                       $copypuppetregion = $region;
                }
-               $region = $this->getOption( 'region' );
+               $puppetinfo = array();
+               if ( $this->hasOption( 'copypuppet' ) ) {
+                       $puppetsource = OpenStackNovaHost::getHostByInstanceId( 
$this->getOption( 'copypuppet' ), $copypuppetregion );
+                       $info = $puppetsource->getPuppetConfiguration();
+                       if ( isset( $info['puppetclass'] ) ) {
+                               $puppetinfo['classes'] = array();
+                               foreach ( $info['puppetclass'] as $class ) {
+                                       if ( ! ( in_array( $class, 
$wgOpenStackManagerPuppetOptions['defaultclasses'] ) ) ) {
+                                               $puppetinfo['classes'][] = 
$class;
+                                       }
+                               }
+                       }
+                       if ( isset( $info['puppetvar'] ) ) {
+                               $puppetinfo['variables'] = array();
+                               foreach ( $info['puppetvar'] as $key => $value 
) {
+                                       if ( $key == 'instanceproject' ) {
+                                               continue;
+                                       }
+                                       if ( $key == 'instancename' ) {
+                                               continue;
+                                       }
+                                       if ( $key == 'realm' ) {
+                                               continue;
+                                       }
+                                       if ( ! ( in_array( $key, 
$wgOpenStackManagerPuppetOptions['defaultvariables'] ) ) ) {
+                                               $puppetinfo['variables'][$key] 
= $value;
+                                       }
+                               }
+                       }
+               }
+
                $flavor = $this->getOption( 'flavor' );
                $image = $this->getOption( 'image' );
                $instance = $this->getOption( 'instance' );
@@ -90,7 +123,7 @@
                        $instance = $this->userNova->getInstance( $instanceId );
                }
                if ( $instance ) {
-                       $host = OpenStackNovaHost::addHostFromInstance( 
$instance, $domain, $pupClasses );
+                       $host = OpenStackNovaHost::addHostFromInstance( 
$instance, $domain, $puppetinfo );
 
                        if ( $host ) {
                                $instance->setHost( $host );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I44db7809f0e893dfb1ce56564643e714e949945f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OpenStackManager
Gerrit-Branch: master
Gerrit-Owner: Andrew Bogott <abog...@wikimedia.org>
Gerrit-Reviewer: Andrew Bogott <abog...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to