get info about ec2 servers with boto:
import boto
from boto import ec2
def getEc2Hosts():
ec2Hosts = set()
AccessKey="""AccessKey"""
SecretAccessKey="""SecretAccessKey"""
# make connection
conn = ec2.connect_to_region('eu- west-1', aws_access_key_id = AccessKey, aws_secret_access_key = SecretAccessKey, )
# get servers status
instanceStatuses = conn.get_all_instance_status()
instanceStatuses = conn.get_all_instance_status()
# get info about all servers
allInst = conn.get_all_instances()
allInst = conn.get_all_instances()
# for our - only ID, name and system status of the each server:
instStatus = {i1.id: (i1.state_name, str(i1.system_status)) for i1 in instanceStatuses}
for i in allInst:
for g in i.groups:
instStatus = {i1.id: (i1.state_name, str(i1.system_status)) for i1 in instanceStatuses}
for i in allInst:
for g in i.groups:
# only servers for foto
if g.name == 'foto-servers':
if g.name == 'foto-servers':
#we can use only running servers with OK status
if instStatus[i.instances[0].id][ 0] == 'running' and instStatus[i.instances[0].id][ 1] == 'Status:ok':
if instStatus[i.instances[0].id][
# add public name to set
ec2Hosts.add(i.instances[0]. public_dns_name)
return ec2Hosts
ec2Hosts.add(i.instances[0].
return ec2Hosts
Комментариев нет:
Отправить комментарий