r81553 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81552‎ | r81553 | r81554 >
Date:02:07, 5 February 2011
Author:laner
Status:deferred
Tags:
Comment:
* Adding script and localization messages for sending notification emails when instances are fully created
* Further fixes for puppet variables; wrapping values in quotes, to ensure values are handled properly
* Adding default puppet variables for all instances created; adding the following variables, which represent the instance creator's email address, (wiki) user name, and interface language:
** instancecreator_email
** instancecreator_username
** instancecreator_lang
* Changing scripts and upstarts in clouddata to use named values in the arrays, where the named values are the name of the file that will be created on the instance
Modified paths:
  • /trunk/extensions/OpenStackManager/OpenStackManager.i18n.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaController.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaHost.php (modified) (history)
  • /trunk/extensions/OpenStackManager/scripts/mail-instance-creator.py (added) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/OpenStackManager.i18n.php
@@ -232,6 +232,9 @@
233233 'openstackmanager-addedrule' => 'Successfully added rule.',
234234 'openstackmanager-addrulefailed' => 'Failed to add rule.',
235235
 236+ 'openstackmanager-email-subject' => 'Your instance is ready to be logged into.',
 237+ 'openstackmanager-email-body' => 'The following instance has been created, and is ready to be logged into: ',
 238+
236239 );
237240
238241 /** Message documentation (Message documentation)
Index: trunk/extensions/OpenStackManager/scripts/mail-instance-creator.py
@@ -0,0 +1,40 @@
 2+#!/usr/bin/python
 3+import urllib
 4+import os
 5+
 6+from xml.dom import minidom
 7+from optparse import OptionParser
 8+from socket import gethostname;
 9+
 10+def main():
 11+ parser = OptionParser(conflict_handler="resolve")
 12+ parser.set_usage("mail-instance-creator.py <from-email-address> <to-email-address> <languagecode> <wikiaddress>\n\n\texample: mail-instance-creator.py 'test@example.com' 'es' 'http://example.com/w/'")
 13+
 14+ (options, args) = parser.parse_args()
 15+
 16+ if len(args) != 4:
 17+ parser.error("mail-instance-creator.py expects exactly four arguments.")
 18+
 19+ fromaddress = args[0]
 20+ toaddress = args[1]
 21+ lang = args[2]
 22+ wikiaddress = args[3]
 23+ subjecturl = wikiaddress + 'api.php?action=expandtemplates&text={{msgnw:mediawiki:openstackmanager-email-subject/' + lang + '}}&format=xml'
 24+ bodyurl = wikiaddress + 'api.php?action=expandtemplates&text={{msgnw:mediawiki:openstackmanager-email-body/' + lang + '}}&format=xml'
 25+ dom = minidom.parse(urllib.urlopen(subjecturl))
 26+ subject = dom.getElementsByTagName('expandtemplates')[0].firstChild.data
 27+ dom = minidom.parse(urllib.urlopen(bodyurl))
 28+ body = dom.getElementsByTagName('expandtemplates')[0].firstChild.data
 29+ body = body + ' ' + gethostname()
 30+ sendmail_location = "/usr/sbin/sendmail" # sendmail location
 31+ p = os.popen("%s -t" % sendmail_location, "w")
 32+ p.write("From: %s\n" % fromaddress)
 33+ p.write("To: %s\n" % toaddress)
 34+ p.write("Subject: %s\n" % subject)
 35+ p.write("\n") # blank line separating headers from body
 36+ p.write(body)
 37+ status = p.close()
 38+ return status
 39+
 40+if __name__ == "__main__":
 41+ main()
Property changes on: trunk/extensions/OpenStackManager/scripts/mail-instance-creator.py
___________________________________________________________________
Added: svn:eol-style
142 + native
Added: svn:executable
243 + *
Index: trunk/extensions/OpenStackManager/OpenStackNovaHost.php
@@ -593,6 +593,7 @@
594594 * @return OpenStackNovaHost
595595 */
596596 static function addHost( $instance, $domain, $puppetinfo = array() ) {
 597+ global $wgUser, $wgLang;
597598 global $wgAuth;
598599 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
599600 global $wgOpenStackManagerLDAPInstanceBaseDN, $wgOpenStackManagerPuppetOptions;
@@ -625,7 +626,7 @@
626627 $hostEntry['puppetclass'][] = $class;
627628 }
628629 foreach ( $wgOpenStackManagerPuppetOptions['defaultvariables'] as $variable => $value ) {
629 - $hostEntry['puppetvar'][] = $variable . '=' . $value;
 630+ $hostEntry['puppetvar'][] = $variable . '="' . $value . '"';
630631 }
631632 if ( $puppetinfo ) {
632633 foreach ( $puppetinfo['classes'] as $class ) {
@@ -633,10 +634,15 @@
634635 }
635636 foreach ( $puppetinfo['variables'] as $variable => $value ) {
636637 if ( $value ) {
637 - $hostEntry['puppetvar'][] = $variable . '=' . $value;
 638+ $hostEntry['puppetvar'][] = $variable . '="' . $value . '"';
638639 }
639640 }
640641 }
 642+ if ( $wgUser->getEmail() ) {
 643+ $hostEntry['puppetvar'][] = 'instancecreator_email=' . $wgUser->getEmail();
 644+ }
 645+ $hostEntry['puppetvar'][] = 'instancecreator_username=' . $wgUser->getName();
 646+ $hostEntry['puppetvar'][] = 'instancecreator_lang=' . $wgLang->getCode();
641647 }
642648 $dn = 'dc=' . $instanceid . ',dc=' . $domain->getDomainName() . ',' . $wgOpenStackManagerLDAPInstanceBaseDN;
643649
Index: trunk/extensions/OpenStackManager/OpenStackNovaController.php
@@ -197,8 +197,7 @@
198198 $userdata .= $endl . $boundary;
199199 }
200200 if ( $wgOpenStackManagerInstanceUserData['scripts'] ) {
201 - $i = 0;
202 - foreach ( $wgOpenStackManagerInstanceUserData['scripts'] as $script ) {
 201+ foreach ( $wgOpenStackManagerInstanceUserData['scripts'] as $scriptname => $script ) {
203202 wfSuppressWarnings();
204203 $stat = stat( $script );
205204 wfRestoreWarnings();
@@ -206,14 +205,12 @@
207206 continue;
208207 }
209208 $scripttext = file_get_contents( $script );
210 - $userdata .= $endl . $this->getAttachmentMime( $scripttext, 'text/x-shellscript', 'wiki-script-' . $i . '.sh' );
 209+ $userdata .= $endl . $this->getAttachmentMime( $scripttext, 'text/x-shellscript', $scriptname );
211210 $userdata .= $endl . $boundary;
212 - $i = $i + 1;
213211 }
214212 }
215213 if ( $wgOpenStackManagerInstanceUserData['upstarts'] ) {
216 - $i = 0;
217 - foreach ( $wgOpenStackManagerInstanceUserData['upstarts'] as $upstart ) {
 214+ foreach ( $wgOpenStackManagerInstanceUserData['upstarts'] as $upstartname => $upstart ) {
218215 wfSuppressWarnings();
219216 $stat = stat( $upstart );
220217 wfRestoreWarnings();
@@ -221,9 +218,8 @@
222219 continue;
223220 }
224221 $upstarttext = file_get_contents( $upstart );
225 - $userdata .= $endl . $this->getAttachmentMime( $upstarttext, 'text/upstart-job', 'wiki-upstart-config-' . $i . '.conf' );
 222+ $userdata .= $endl . $this->getAttachmentMime( $upstarttext, 'text/upstart-job', $upstartname );
226223 $userdata .= $endl . $boundary;
227 - $i = $i + 1;
228224 }
229225 }
230226 $userdata .= '--';

Status & tagging log