Anonymous avatar Anonymous committed f573061

fixes and other worky stuff

Comments (0)

Files changed (5)

ec2control/config.py

         else:
             return default
 
+    def has_section(self, sectionname):
+        return self.config.has_section(sectionname)
+
     def section_dict(self, section):
-        return dict(self.config.items(section))
+        return dict(self.config.items(section))

ec2control/ec2.py

     pass
 
 class Instance(object):
+    instance = None
+
     def __init__(self, config, name):
         self.config_file = config
         if name is None:
         else:
             self.name = name
 
+        if not config.has_section("instance_%s" % name):
+            raise CommandError("Unknown instance name: %s" % name)
         self.config = config.section_dict("instance_%s" % name)
         self.descriptive_name = self.config['descriptive_name']
         self._conn = EC2Connection(config['aws_key'], config['aws_secret'])
     def start(self):
         instances = self._conn.start_instances(instance_ids=[self.config['instance_id']])
 
-        inst = instances[0]
+        self.instance = inst = instances[0]
 
         inst.update()
         while inst.state == 'pending':

ec2control/emailer.py

 
     def _render(self, **kw):
         t = Template(filename=self.config['response_template'])
-        body = t.render(**kw)
-        subject = t.get_def("subject").render(**kw)
+        body = t.render(**kw).strip()
+        subject = t.get_def("subject").render(**kw).strip()
         self._send(subject, body)
 
     def _send(self, subject, message):
         cc_addr = self.config['cc']
 
         msg['Subject'] = subject
-        msg['From'] = self.config['from_addr']
+        msg['From'] = from_addr = self.config['from_addr']
         msg['To'] = to_addr
         msg['Cc'] = cc_addr
         msg = msg.as_string()
         smtp = smtplib.SMTP(self.config['smtp_host'], int(self.config['smtp_port']))
 
-        for addr in set([to] + cc.split(",")):
+        for addr in set([to_addr] + re.split(r',\s*', cc_addr)):
             smtp.sendmail(from_addr, addr, msg)

ec2control/main.py

 import logging
 log = logging.getLogger(__name__)
 
+from logging.config import fileConfig
+
 def main(argv):
     parser = argparse.ArgumentParser()
     parser.add_argument("-c", "--config", 
 
     config = Config(options.config)
 
+    fileConfig(options.config)
+
     if options.read:
         email_data = file(options.read).read()
     else:
     except CommandError, ce:
         resp.send_command_error(ce, instance)
     except Exception, e:
-        log.error("Error occurred", e)
+        log.error("Error occurred", exc_info=True)
         resp.send_error(e, instance)
     print email_data
 

sample_templates/minecraft.mako

 
 <%def name="subject()">
     % if status == 'started':
-        % if instance.status == 'started':
+        % if instance.status == 'running':
             ${instance.descriptive_name} is online!  ${instance.ip_address}:${instance.config['minecraft_port']}
         % else:
             ${instance.descriptive_name} failed to start!
     % endif
 </%def>
 
+<%def name="body()">
+% if status == 'started':
+    % if instance.status == 'running':
+Your presence is welcome at ${instance.descriptive_name}!  ${instance.ip_address}:${instance.config['minecraft_port']}
+    % else:
+${instance.descriptive_name} wasn't able to start !   Status is ${instance.status}
+    % endif
+% elif status == 'command_error':
+Sorry, I wasn't able to understand your command.
+
+${exception}
+% elif status == 'error':
+    % if instance:
+${instance.descriptive_name} had a problem.
+    % else:
+An unknown error occurred.
+    % endif
+
+${exception}
+% endif
+</%def>
+
 Greetings Citizen -
 
-% if status == 'started':
-    % if instance.status == 'started':
-        Your presence is welcome at ${instance.descriptive_name}!  ${instance.ip_address}:${instance.config['minecraft_port']}
-    % else:
-        ${instance.descriptive_name} wasn't able to start !   Status is ${instance.status}
-    % endif
-% elif status == 'command_error':
-    Sorry, I wasn't able to understand your command.
-
-    ${exception}
-% elif status == 'error':
-    % if instance:
-        ${instance.descriptive_name} had a problem.
-    % else:
-        An unknown error occurred.
-    % endif
-
-    ${exception}
-% endif
+${body()}
 
 Regards, 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.