Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 89 lines (84 sloc) 2.753 kB
b10310b Added initial cloudfront admin tool and bundle_image tool
kopertop authored
1 #!/usr/bin/env python
2 # Author: Chris Moyer
3 #
4 # cfadmin is similar to sdbadmin for CloudFront, it's a simple
5 # console utility to perform the most frequent tasks with CloudFront
6 #
7 def _print_distributions(dists):
6421232 @kopertop Updated cfadmin to optionally take arguments from STDIN for
kopertop authored
8 """Internal function to print out all the distributions provided"""
9 print "%-12s %-50s %s" % ("Status", "Domain Name", "Origin")
10 print "-"*80
11 for d in dists:
12 print "%-12s %-50s %-30s" % (d.status, d.domain_name, d.origin)
13 for cname in d.cnames:
14 print " "*12, "CNAME => %s" % cname
15 print ""
b10310b Added initial cloudfront admin tool and bundle_image tool
kopertop authored
16
17 def help(cf, fnc=None):
6421232 @kopertop Updated cfadmin to optionally take arguments from STDIN for
kopertop authored
18 """Print help message, optionally about a specific function"""
19 import inspect
20 self = sys.modules['__main__']
21 if fnc:
22 try:
23 cmd = getattr(self, fnc)
24 except:
25 cmd = None
26 if not inspect.isfunction(cmd):
27 print "No function named: %s found" % fnc
28 sys.exit(2)
29 (args, varargs, varkw, defaults) = inspect.getargspec(cmd)
30 print cmd.__doc__
31 print "Usage: %s %s" % (fnc, " ".join([ "[%s]" % a for a in args[1:]]))
32 else:
33 print "Usage: cfadmin [command]"
34 for cname in dir(self):
35 if not cname.startswith("_"):
36 cmd = getattr(self, cname)
37 if inspect.isfunction(cmd):
38 doc = cmd.__doc__
39 print "\t%s - %s" % (cname, doc)
40 sys.exit(1)
b10310b Added initial cloudfront admin tool and bundle_image tool
kopertop authored
41
42 def ls(cf):
6421232 @kopertop Updated cfadmin to optionally take arguments from STDIN for
kopertop authored
43 """List all distributions and streaming distributions"""
44 print "Standard Distributions"
45 _print_distributions(cf.get_all_distributions())
46 print "Streaming Distributions"
47 _print_distributions(cf.get_all_streaming_distributions())
b10310b Added initial cloudfront admin tool and bundle_image tool
kopertop authored
48
8ff181a Added initial support for invalidation.
Chris Moyer authored
49 def invalidate(cf, origin_or_id, *paths):
6421232 @kopertop Updated cfadmin to optionally take arguments from STDIN for
kopertop authored
50 """Create a cloudfront invalidation request"""
51 # Allow paths to be passed using stdin
52 if not paths:
53 paths = []
54 for path in sys.stdin.readlines():
55 path = path.strip()
56 if path:
57 paths.append(path)
58 dist = None
59 for d in cf.get_all_distributions():
60 if d.id == origin_or_id or d.origin.dns_name == origin_or_id:
61 dist = d
62 break
63 if not dist:
64 print "Distribution not found: %s" % origin_or_id
65 sys.exit(1)
66 cf.create_invalidation_request(dist.id, paths)
b10310b Added initial cloudfront admin tool and bundle_image tool
kopertop authored
67
68 if __name__ == "__main__":
6421232 @kopertop Updated cfadmin to optionally take arguments from STDIN for
kopertop authored
69 import boto
70 import sys
71 cf = boto.connect_cloudfront()
72 self = sys.modules['__main__']
73 if len(sys.argv) >= 2:
74 try:
75 cmd = getattr(self, sys.argv[1])
76 except:
77 cmd = None
78 args = sys.argv[2:]
79 else:
80 cmd = help
81 args = []
82 if not cmd:
83 cmd = help
84 try:
85 cmd(cf, *args)
86 except TypeError, e:
87 print e
88 help(cf, cmd.__name__)
Something went wrong with that request. Please try again.