Index: trunk/extensions/OpenStackManager/OpenStackManager.i18n.php |
— | — | @@ -232,6 +232,9 @@ |
233 | 233 | 'openstackmanager-addedrule' => 'Successfully added rule.', |
234 | 234 | 'openstackmanager-addrulefailed' => 'Failed to add rule.', |
235 | 235 | |
| 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 | + |
236 | 239 | ); |
237 | 240 | |
238 | 241 | /** 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 |
1 | 42 | + native |
Added: svn:executable |
2 | 43 | + * |
Index: trunk/extensions/OpenStackManager/OpenStackNovaHost.php |
— | — | @@ -593,6 +593,7 @@ |
594 | 594 | * @return OpenStackNovaHost |
595 | 595 | */ |
596 | 596 | static function addHost( $instance, $domain, $puppetinfo = array() ) { |
| 597 | + global $wgUser, $wgLang; |
597 | 598 | global $wgAuth; |
598 | 599 | global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword; |
599 | 600 | global $wgOpenStackManagerLDAPInstanceBaseDN, $wgOpenStackManagerPuppetOptions; |
— | — | @@ -625,7 +626,7 @@ |
626 | 627 | $hostEntry['puppetclass'][] = $class; |
627 | 628 | } |
628 | 629 | foreach ( $wgOpenStackManagerPuppetOptions['defaultvariables'] as $variable => $value ) { |
629 | | - $hostEntry['puppetvar'][] = $variable . '=' . $value; |
| 630 | + $hostEntry['puppetvar'][] = $variable . '="' . $value . '"'; |
630 | 631 | } |
631 | 632 | if ( $puppetinfo ) { |
632 | 633 | foreach ( $puppetinfo['classes'] as $class ) { |
— | — | @@ -633,10 +634,15 @@ |
634 | 635 | } |
635 | 636 | foreach ( $puppetinfo['variables'] as $variable => $value ) { |
636 | 637 | if ( $value ) { |
637 | | - $hostEntry['puppetvar'][] = $variable . '=' . $value; |
| 638 | + $hostEntry['puppetvar'][] = $variable . '="' . $value . '"'; |
638 | 639 | } |
639 | 640 | } |
640 | 641 | } |
| 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(); |
641 | 647 | } |
642 | 648 | $dn = 'dc=' . $instanceid . ',dc=' . $domain->getDomainName() . ',' . $wgOpenStackManagerLDAPInstanceBaseDN; |
643 | 649 | |
Index: trunk/extensions/OpenStackManager/OpenStackNovaController.php |
— | — | @@ -197,8 +197,7 @@ |
198 | 198 | $userdata .= $endl . $boundary; |
199 | 199 | } |
200 | 200 | if ( $wgOpenStackManagerInstanceUserData['scripts'] ) { |
201 | | - $i = 0; |
202 | | - foreach ( $wgOpenStackManagerInstanceUserData['scripts'] as $script ) { |
| 201 | + foreach ( $wgOpenStackManagerInstanceUserData['scripts'] as $scriptname => $script ) { |
203 | 202 | wfSuppressWarnings(); |
204 | 203 | $stat = stat( $script ); |
205 | 204 | wfRestoreWarnings(); |
— | — | @@ -206,14 +205,12 @@ |
207 | 206 | continue; |
208 | 207 | } |
209 | 208 | $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 ); |
211 | 210 | $userdata .= $endl . $boundary; |
212 | | - $i = $i + 1; |
213 | 211 | } |
214 | 212 | } |
215 | 213 | if ( $wgOpenStackManagerInstanceUserData['upstarts'] ) { |
216 | | - $i = 0; |
217 | | - foreach ( $wgOpenStackManagerInstanceUserData['upstarts'] as $upstart ) { |
| 214 | + foreach ( $wgOpenStackManagerInstanceUserData['upstarts'] as $upstartname => $upstart ) { |
218 | 215 | wfSuppressWarnings(); |
219 | 216 | $stat = stat( $upstart ); |
220 | 217 | wfRestoreWarnings(); |
— | — | @@ -221,9 +218,8 @@ |
222 | 219 | continue; |
223 | 220 | } |
224 | 221 | $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 ); |
226 | 223 | $userdata .= $endl . $boundary; |
227 | | - $i = $i + 1; |
228 | 224 | } |
229 | 225 | } |
230 | 226 | $userdata .= '--'; |