Pior Bastida avatar Pior Bastida committed 795e6b8

add a fabric module. Populate fabric roledefs from AWS API

Comments (0)

Files changed (1)


+import boto
+import awstools
+    %(Name)s
+    %(aws:cloudformation:stack-name)s
+def populate_roledefs():
+    roledefs = {}
+    config = awstools.read_config()
+    cfg_roletmpl = unicode(config.get("fabric", "roletemplates",
+                           DEFAULTTEMPLATES))
+    roletemplates = [t.strip() for t in cfg_roletmpl.split('\n') if t.strip()]
+    filters = {u'instance-state-name': u'running'}
+    reservations = boto.connect_ec2().get_all_instances(filters=filters)
+    instances = [i for r in reservations for i in r.instances]
+    def add_instance(role, instance):
+        roledefs.setdefault(role,
+                            set()).add(instance.public_dns_name)
+        roledefs.setdefault(u':'.join([role, instance.placement]),
+                            set()).add(instance.public_dns_name)
+    for instance in instances:
+        for templates in roletemplates:
+            try:
+                add_instance(templates % instance.tags, instance)
+            except:
+                pass
+    return dict([(k, list(v)) for k, v in roledefs.items()])
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.