https://gist.github.com/1653405
I have "ipython -i ec2connection.py" aliased in bash. I typically
want quick access to all my instances, regardless of the region,
and it's tedious to open each connection by region. But it also
takes time to open connections to all the regions, so I use
RegionRegex to limit connections to US regions.
There's a some hackery to assign attributes and manipulate
__builtins__, but it makes everything easily accessible with
simple tab-completion.
It should be fairly easy to expand this code for your own
purposes. Comments and suggestions are welcome.
Jeff Bauer
Rubicon, Inc.
Sample session:
$ ipython -i ec2connection.py
In [1]: ec2. <TAB>
ec2.i ec2.regions ec2.us_east_1 ec2.us_west_2
ec2.instances ec2.reload ec2.us_west_1
In [1]: ec2.regions
Out[1]:
{u'ap-northeast-1': RegionInfo:ap-northeast-1,
u'ap-southeast-1': RegionInfo:ap-southeast-1,
u'eu-west-1': RegionInfo:eu-west-1,
u'sa-east-1': RegionInfo:sa-east-1,
u'us-east-1': RegionInfo:us-east-1,
u'us-west-1': RegionInfo:us-west-1,
u'us-west-2': RegionInfo:us-west-2}
In [2]: ec2.us_east_1
Out[2]: EC2Connection:ec2.us-east-1.amazonaws.com
In [3]: i. <TAB>
i.07b9e56f i.688c1958 i.bates i.carriage i.chat i.e4d68c86
i.17cc887d i.84201dec i.beta i.collator i.dc7077bc i.fbdc9e91
i.59c40c3a i.a0b7b0c2 i.bouncer i.c75daaa4 i.df4a6db7 i.itrack
In [4]: i.beta.state
Out[4]: u'running'
In [5]: i.beta.remove_tag?
Definition: i.beta.remove_tag(self, key, value=None)
Docstring:
Remove a tag from this object. Removing a tag involves a round-trip
to the EC2 service.
:type key: str
:param key: The key or name of the tag being stored.
:type value: str
:param value: An optional value that can be stored with the tag.
If a value is provided, it must match the value
currently stored in EC2. If not, the tag will not
be removed. If a value of None is provided, all
tags with the specified name will be deleted.
NOTE: There is an important distinction between
a value of '' and a value of None.