Created
May 18, 2011 00:17
-
-
Save mbabineau/977747 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import urllib2 | |
from jabberbot import JabberBot, botcmd | |
import boto | |
class EA2DJabberBot(JabberBot): | |
def __init__(self, *args, **kwargs): | |
super(EA2DJabberBot, self).__init__(*args, **kwargs) | |
@botcmd | |
def as_list_hosts(self, msg, args): | |
"""Returns the hostnames for instances within an Auto Scaling Group""" | |
if args: | |
asg_name = args | |
else: | |
return "Error: You must pass an Auto Scaling Group name" | |
c = boto.connect_autoscale() | |
asgs = c.get_all_groups([asg_name]) | |
if len(asgs) > 0: | |
asg = asgs.pop() | |
else: | |
return 'Error: "%s" not found' % asg_name | |
instance_ids = [i.instance_id for i in asg.instances] | |
if len(instance_ids) > 0: | |
c = boto.connect_ec2() | |
reservations = c.get_all_instances(instance_ids) | |
instances = [] | |
for r in reservations: | |
instances += [i.dns_name for i in r.instances] | |
return "\n".join(instances) | |
else: | |
return 'No instances found in "%s(asg_name)"' | |
if __name__ == '__main__': | |
username = '[email protected]' | |
#### password = | |
chatroom = '[email protected]' | |
nickname = 'Soundwave' | |
bot = EA2DJabberBot(username, password) | |
bot.PING_FREQUENCY = 15 | |
bot.join_room(chatroom, nickname) | |
bot.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment