Browse Source

Add suppor to list events.

Now you can list EC2 events using:

	mico ec2 events
Andrés J. Díaz 5 years ago
parent
commit
86ac245ddf
3 changed files with 26 additions and 1 deletions
  1. 19 1
      mico/lib/aws/ec2/__init__.py
  2. 1 0
      mico/output.py
  3. 6 0
      mico/stack/ec2/__init__.py

+ 19 - 1
mico/lib/aws/ec2/__init__.py

@@ -19,7 +19,7 @@ from boto.ec2 import get_region
 from boto.ec2.connection import EC2Connection
 
 import mico.output
-
+from mico.util.dicts import AttrDict
 
 class EC2LibraryError(Exception):
     """Model an exception related with EC2 API."""
@@ -308,6 +308,24 @@ def ec2_list(*args):
                         instance.name = instance.tags["Name"]
                         yield instance
 
+def ec2_events():
+    """Return pending events in EC2"""
+    conn = ec2_connect()
+    stats = conn.get_all_instance_status()
+    l = []
+    for stat in stats:
+        if stat.events:
+           for ev in stat.events:
+               if "Completed" not in ev.description:
+                   ev.name = conn.get_all_instances([stat.id])[0].instances[0].tags.get("Name", "%s" % stat.id)
+                   ev.id = stat.id
+                   ev.zone = stat.zone
+                   ev.status = stat.state_name
+                   ev.begin = ev.not_before
+                   ev.end = ev.not_after
+                   l.append(ev)
+    return l
+
 ec2_launch = ec2_create = ec2_run = ec2_ensure
 
 from mico.lib.aws.ec2.sg import *

+ 1 - 0
mico/output.py

@@ -64,6 +64,7 @@ dump_keys = [
         '_state', 'root_device_type', 'instance_type',
         'image_id', '_placement', 'secgroups', 'ip_address',
         'ttl', 'resource_records', 'launch_time', 'paused',
+        'begin', 'end'
 ]
 
 prompt_usr = os.environ.get("MICO_PS1", None) or "mico: "

+ 6 - 0
mico/stack/ec2/__init__.py

@@ -90,6 +90,12 @@ def run(*args):
     if len(env.roledefs['mico']) > 0:
         mico.run.run(" ".join(args[1:]))
 
+def events(*args):
+    """Print pending events in EC2"""
+    for x in ec2_events():
+        print(dir(x))
+        mico.output.dump(x, layout=env.get("layout", "vertical"))
+
 
 def main(*args):
     if len(args) > 0: