~jk0/nova/xs-ipv6

« back to all changes in this revision

Viewing changes to vendor/boto/bin/cfadmin

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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):
 
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 ""
 
16
 
 
17
def help(cf, fnc=None):
 
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)
 
41
 
 
42
def ls(cf):
 
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())
 
48
 
 
49
 
 
50
if __name__ == "__main__":
 
51
        import boto
 
52
        import sys
 
53
        cf = boto.connect_cloudfront()
 
54
        self = sys.modules['__main__']
 
55
        if len(sys.argv) >= 2:
 
56
                try:
 
57
                        cmd = getattr(self, sys.argv[1])
 
58
                except:
 
59
                        cmd = None
 
60
                args = sys.argv[2:]
 
61
        else:
 
62
                cmd = help
 
63
                args = []
 
64
        if not cmd:
 
65
                cmd = help
 
66
        try:
 
67
                cmd(cf, *args)
 
68
        except TypeError, e:
 
69
                print e
 
70
                help(cf, cmd.__name__)