Exemplo n.º 1
0
 def __init__(self,
              name,
              process,
              platform,
              env,
              region,
              domain=None,
              public=False):
     self.name = name
     self.process = process
     self.platform = platform
     self.env = env
     self.loadbalancer_name = "%s-%s-%s-%s" % (self.process, self.name,
                                               self.platform, self.env)
     self.region = region
     self.connection = elb.connect_to_region(self.region)
     self.interval = 10
     self.healthy_threshold = 3
     self.unhealthy_threshold = 5
     self.target = 'HTTP:80/'
     self.listeners = {
         '80': [(80, 80, 'http')],
         '443': [(80, 80, 'http'), (443, 80, 'https')]
     }
     self.domain = domain
     self.listener = self.listeners['80']
     self.public = public
Exemplo n.º 2
0
def metrics_catalog(region):
    '''Build a catalog of available metrics'''
    
    conn_ec2 = ec2.connect_to_region(region)
    conn_elb = elb.connect_to_region(region)
    conn_rds = rds.connect_to_region(region)
    conn_cloudwatch = cloudwatch.connect_to_region(region)
    
    catalog = {'ec2':{}, 'ebs':{}, 'elb':{}, 'rds':{}}
    
    # EC2 instances
    for reservation in conn_ec2.get_all_instances():
        for instance in reservation.instances:
            catalog['ec2'][instance] = conn_cloudwatch.list_metrics(
                dimensions={'InstanceId': [instance.id]})

    # EBS Volumes
    for volume in conn_ec2.get_all_volumes():
        catalog['ebs'][volume] = conn_cloudwatch.list_metrics(
            dimensions={'VolumeId': [volume.id]})
    
    # ELB instances
    for balancer in conn_elb.get_all_load_balancers():
        catalog['elb'][balancer] = conn_cloudwatch.list_metrics(
            dimensions={'LoadBalancerName': [balancer.name]})
    
    # RDS instances
    for instance in conn_rds.get_all_dbinstances():
        catalog['rds'][instance] = conn_cloudwatch.list_metrics(
            dimensions={'DBInstanceIdentifier': [instance.id]})

    return catalog
Exemplo n.º 3
0
 def __init__(self, key, secret, region, elb_name):
     self.elb = elb.connect_to_region(
         region,
         aws_access_key_id=key,
         aws_secret_access_key=secret)
     self.elb_name = elb_name
     self._boto_lb = None
Exemplo n.º 4
0
def _get_conn(region, key, keyid, profile):
    '''
    Get a boto connection to ELB.
    '''
    if profile:
        if isinstance(profile, string_types):
            _profile = __salt__['config.option'](profile)
        elif isinstance(profile, dict):
            _profile = profile
        key = _profile.get('key', None)
        keyid = _profile.get('keyid', None)
        region = _profile.get('region', None)

    if not region and __salt__['config.option']('elb.region'):
        region = __salt__['config.option']('elb.region')

    if not region:
        region = 'us-east-1'

    if not key and __salt__['config.option']('elb.key'):
        key = __salt__['config.option']('elb.key')
    if not keyid and __salt__['config.option']('elb.keyid'):
        keyid = __salt__['config.option']('elb.keyid')

    try:
        conn = elb.connect_to_region(region, aws_access_key_id=keyid,
                                              aws_secret_access_key=key)
    except boto.exception.NoAuthHandlerFound:
        log.error('No authentication credentials found when attempting to'
                  ' make boto elb connection.')
        return None
    return conn
Exemplo n.º 5
0
def metrics_catalog(region):
    '''Build a catalog of available metrics'''

    conn_ec2 = ec2.connect_to_region(region)
    conn_elb = elb.connect_to_region(region)
    conn_rds = rds.connect_to_region(region)
    conn_cloudwatch = cloudwatch.connect_to_region(region)

    catalog = {'ec2': {}, 'ebs': {}, 'elb': {}, 'rds': {}}

    # EC2 instances
    for reservation in conn_ec2.get_all_instances():
        for instance in reservation.instances:
            catalog['ec2'][instance] = conn_cloudwatch.list_metrics(
                dimensions={'InstanceId': [instance.id]})

    # EBS Volumes
    for volume in conn_ec2.get_all_volumes():
        catalog['ebs'][volume] = conn_cloudwatch.list_metrics(
            dimensions={'VolumeId': [volume.id]})

    # ELB instances
    for balancer in conn_elb.get_all_load_balancers():
        catalog['elb'][balancer] = conn_cloudwatch.list_metrics(
            dimensions={'LoadBalancerName': [balancer.name]})

    # RDS instances
    for instance in conn_rds.get_all_dbinstances():
        catalog['rds'][instance] = conn_cloudwatch.list_metrics(
            dimensions={'DBInstanceIdentifier': [instance.id]})

    return catalog
Exemplo n.º 6
0
def _get_conn(region, key, keyid, profile):
    '''
    Get a boto connection to ELB.
    '''
    if profile:
        if isinstance(profile, string_types):
            _profile = __salt__['config.option'](profile)
        elif isinstance(profile, dict):
            _profile = profile
        key = _profile.get('key', None)
        keyid = _profile.get('keyid', None)
        region = _profile.get('region', None)

    if not region and __salt__['config.option']('elb.region'):
        region = __salt__['config.option']('elb.region')

    if not region:
        region = 'us-east-1'

    if not key and __salt__['config.option']('elb.key'):
        key = __salt__['config.option']('elb.key')
    if not keyid and __salt__['config.option']('elb.keyid'):
        keyid = __salt__['config.option']('elb.keyid')

    try:
        conn = elb.connect_to_region(region,
                                     aws_access_key_id=keyid,
                                     aws_secret_access_key=key)
    except boto.exception.NoAuthHandlerFound:
        log.error('No authentication credentials found when attempting to'
                  ' make boto elb connection.')
        return None
    return conn
Exemplo n.º 7
0
def connect_elb_region(region_name=_DEFAULT_REGION):
  """Connects to the ELB service for region_name and returns the ELB
  connection."""
  print ("Connecting to ELB service for region {}".format(region_name))
  return elb.connect_to_region(region_name,
                               aws_access_key_id=AWS_ACCESS_KEY_ID,
                               aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
Exemplo n.º 8
0
def get_loadbalancer(project):
    tenant = landlord.Tenant()
    tenant.load_properties()
    conn = elb.connect_to_region(tenant.get_property('deploy.region'),
                                 aws_access_key_id=tenant.get_property('aws.id'),
                                 aws_secret_access_key=tenant.get_property('aws.secret'))
    try:
        load_balancers = conn.get_all_load_balancers(load_balancer_names=[tenant.get_property('environment')+'-lb-' + project['name']])
        if load_balancers:
            print "[LB] Found load balancer ..."
            return load_balancers[0]
        else:
            raise BotoServerError('LoadBalancerNotFound', 'Load Balancer does not exists')
    except BotoServerError:
        print "[LB] No load balancer, creating one ..."
        #TODO: https://github.com/boto/boto/issues/509
        hc = HealthCheck(
            interval=20,
            healthy_threshold=3,
            unhealthy_threshold=5,
            target='HTTP:9000/public/version.txt')
        ports = [(80, 9000, 'http')]
        lb = conn.create_load_balancer(tenant.get_property('environment')+'-lb-' + project['name'], None, ports, [tenant.get_property('deploy.subnet')])
        dns.update_dns(lb.dns_name, project)
        print "[LB] Configuring health checks ... "
        lb.configure_health_check(hc)
        # TODO: Apply tags
        if lb.instances is None:
            lb.instances = []
        return lb
Exemplo n.º 9
0
 def aws_conn_elb(region, profile='default'):
     try:
         conn = elb.connect_to_region(region, profile_name=profile)
         return conn
     except Exception as e:
         logging.error(
             "Unable to connect to region, please investigate: {0}".format(
                 e))
Exemplo n.º 10
0
def dettach(load_balancer, instances):
    if instances is not None and len(instances) > 0:
        tenant = landlord.Tenant()
        tenant.load_properties()
        conn = elb.connect_to_region(tenant.get_property('deploy.region'),
                                     aws_access_key_id=tenant.get_property('aws.id'),
                                     aws_secret_access_key=tenant.get_property('aws.secret'))
        conn.deregister_instances(load_balancer.name, instances)
Exemplo n.º 11
0
def updateELB(conf, iam_certificate):
    LOG.info("Updating ELB with new certificate")
    elb_connection = elb.connect_to_region(conf['elb_region'])
    response = elb_connection.set_lb_listener_SSL_certificate(
        conf['elb'], 443, iam_certificate['upload_server_certificate_response']
        ['upload_server_certificate_result']['server_certificate_metadata']
        ['arn'])
    return response
Exemplo n.º 12
0
 def connect_elb(self):
     '''
     Connect to ELB
     '''
     try:
         for reg in elb.regions():
             if(reg.name == os.environ['AWS_DEFAULT_REGION']):
                 return elb.connect_to_region(reg.name)
         return None
     except Exception as e:
         print "%s" % e
         exit(-1)
Exemplo n.º 13
0
    def create_elb(self, scheme='internet-facing', include_https=True):

        name = self.random_name()

        conn = elb.connect_to_region('us-east-1')

        zones = ['us-east-1a', 'us-east-1b']
        ports = [(80, 80, 'http')]
        if include_https:
            ports.append((443, 80, 'https', 'arn:aws:iam::1234567890123:server-certificate/my.nifty.cert.net'))

        lb = conn.create_load_balancer(name, zones, ports, scheme=scheme)
Exemplo n.º 14
0
 def connect_elb(self):
     '''
     Connect to ELB
     '''
     try:
         for reg in elb.regions():
             if (reg.name == os.environ['AWS_DEFAULT_REGION']):
                 return elb.connect_to_region(reg.name)
         return None
     except Exception as e:
         print "%s" % e
         exit(-1)
Exemplo n.º 15
0
 def elb_connect(self, region, assumedRoleObject):
     ''' create connection to api server'''
     if self.eucalyptus:
         self.fail_with_error("Untested elb connection to eucalyptus. Please turn 'elbs' flag to False.")
     else:
         conn = elb.connect_to_region(region,
                         aws_access_key_id=assumedRoleObject.credentials.access_key,
                         aws_secret_access_key=assumedRoleObject.credentials.secret_key,
                         security_token=assumedRoleObject.credentials.session_token)
     # connect_to_region will fail "silently" by returning None if the region name is wrong or not supported
     if conn is None:
         self.fail_with_error("region name: %s likely not supported, or AWS is down.  connection to region failed." % region)
     return conn
Exemplo n.º 16
0
def get_ec2_connection(server_type, **kwargs):
    """
    Create and return a valid connection to AWS.

    To establish a valid connection, aws_access_key and aws_secret_key have to
    be defined in a file specified by env.AWS_CREDENTIAL, with a format similar
    to server.ini file.  You should define env.AWS_CREDENTIAL in your fabfile.
    By default, this function looks into $PROJECT_DIR/deploy/amazon.ini for the
    credential information, and this file should has a section named 'amazon-aws'
    and containing lines defining aws_access_key and aws_secret_key, like below

    [amazon-aws]
    aws_access_key =
    aws_secret_key =
    """

    amzn = env.get('AWS_CREDENTIAL', os.path.join(env.deploy_path,
                                                  'amazon.ini'))

    if not os.path.exists(amzn):
        print(
            "Cannot find environment variable AMAZON_CREDENTIALS which should"
            " point to a file with your aws_access_key and aws_secret_key info"
            " inside. You may specify it through your fab env.")
        sys.exit(1)

    parser = ConfigParser()
    parser.read(amzn)

    aws_access_key = parser.get('amazon-aws', 'aws_access_key')
    aws_secret_key = parser.get('amazon-aws', 'aws_secret_key')

    if not aws_access_key or not aws_secret_key:
        print "You must specify your amazon aws credentials to your env."
        sys.exit(1)

    region = kwargs.get('region', env.get('region'))
    if not region:
        region = DEFAULT_REGION

    if server_type == 'ec2':
        conn = ec2.connect_to_region(region,
                                     aws_access_key_id=aws_access_key,
                                     aws_secret_access_key=aws_secret_key)
        return conn
    elif server_type == 'elb':
        conn = elb.connect_to_region(region,
                                     aws_access_key_id=aws_access_key,
                                     aws_secret_access_key=aws_secret_key)
        return conn
    def _get_load_balancer_handle(self):
        try:
            conn = _elb.connect_to_region(self.region, **self.aws_credentials)
            for i in conn.get_all_load_balancers():
                if i.dns_name == self.load_balancer_dns_name:
                    return i
        except Exception as e:
            _logger.error(
                "Unable to connect to ELB with name '%s' in region '%s', error: %s"
                % (self.load_balancer_dns_name, self.region, e))

        raise Exception(
            "Cannot find load balancer with name '%s' in region '%s'." %
            (self.load_balancer_dns_name, self.region))
Exemplo n.º 18
0
def get_ec2_connection(server_type, **kwargs):
    """
    Create and return a valid connection to AWS.

    To establish a valid connection, aws_access_key and aws_secret_key have to
    be defined in a file specified by env.AWS_CREDENTIAL, with a format similar
    to server.ini file.  You should define env.AWS_CREDENTIAL in your fabfile.
    By default, this function looks into $PROJECT_DIR/deploy/amazon.ini for the
    credential information, and this file should has a section named 'amazon-aws'
    and containing lines defining aws_access_key and aws_secret_key, like below

    [amazon-aws]
    aws_access_key =
    aws_secret_key =
    """

    amzn = env.get('AWS_CREDENTIAL',
                   os.path.join(env.deploy_path, 'amazon.ini'))

    if not os.path.exists(amzn):
        print ("Cannot find environment variable AMAZON_CREDENTIALS which should"
               " point to a file with your aws_access_key and aws_secret_key info"
               " inside. You may specify it through your fab env.")
        sys.exit(1)

    parser = ConfigParser()
    parser.read(amzn)

    aws_access_key = parser.get('amazon-aws', 'aws_access_key')
    aws_secret_key = parser.get('amazon-aws', 'aws_secret_key')

    if not aws_access_key or not aws_secret_key:
        print "You must specify your amazon aws credentials to your env."
        sys.exit(1)

    region = kwargs.get('region', env.get('region'))
    if not region:
        region = DEFAULT_REGION

    if server_type == 'ec2':
        conn = ec2.connect_to_region(region,
                                     aws_access_key_id=aws_access_key,
                                     aws_secret_access_key=aws_secret_key)
        return conn
    elif server_type == 'elb':
        conn = elb.connect_to_region(region,
                                     aws_access_key_id=aws_access_key,
                                     aws_secret_access_key=aws_secret_key)
        return conn
Exemplo n.º 19
0
    def get_elb_instances_by_region(self, region):
        ''' Makes an AWS API call to the list of ELB instances in a particular
        region '''

        try:
            conn = elb.connect_to_region(region)
            if conn:
                instances = conn.get_all_load_balancers()
                for instance in instances:
                    self.add_elb_instance(instance, region)
        except boto.exception.BotoServerError, e:
            if not e.reason == "Forbidden":
                print "Looks like AWS ELB is down: "
                print e
                sys.exit(1)
Exemplo n.º 20
0
    def get_elb_instances_by_region(self, region):
        ''' Makes an AWS API call to the list of ELB instances in a particular
        region '''

        try:
            conn = elb.connect_to_region(region)
            if conn:
                instances = conn.get_all_load_balancers()
                for instance in instances:
                    self.add_elb_instance(instance, region)
        except boto.exception.BotoServerError, e:
            if not e.reason == "Forbidden":
                print "Looks like AWS ELB is down: "
                print e
                sys.exit(1)
Exemplo n.º 21
0
def _get_elb(name):
    '''
    Retrieves a boto ELB instance for the given name.

    '''
    try:
        elb_conn = _boto_elb.connect_to_region(__grains__['region'])
        elb = elb_conn.get_all_load_balancers(load_balancer_names=[name])
    except Exception:
        # TODO: Add support for using AWS keys. Right now you need IAM roles
        import traceback
        log.debug("Error getting ELB instance %s", name)
        log.debug(traceback.format_exc())
        return False

    return elb[0]
Exemplo n.º 22
0
def _get_elb(name):
    '''
    Retrieves a boto ELB instance for the given name.

    '''
    try:
        elb_conn = _boto_elb.connect_to_region(__grains__['region'])
        elb = elb_conn.get_all_load_balancers(load_balancer_names=[name])
    except Exception:
        # TODO: Add support for using AWS keys. Right now you need IAM roles
        import traceback
        log.debug("Error getting ELB instance %s", name)
        log.debug(traceback.format_exc())
        return False

    return elb[0]
Exemplo n.º 23
0
 def set_elb_dns(self, domain_name):
     elbo = elb.connect_to_region(self.region)
     lb = elbo.get_all_load_balancers(
         load_balancer_names=self.lb_name).pop()
     r53 = route53.connect_to_region(self.region)
     dns_zone = None
     for zone in r53.get_zones():
         if domain_name == zone.name:
             dns_zone = zone
     if not dns_zone:
         raise Exception(
             'DNS Hosting for {0} not setup in Route53'.format(domain_name))
     status = dns_zone.add_record(
         'CNAME', '{0}.{1}'.format(self.lb_name.strip(), domain_name),
         lb.dns_name)
     return status
Exemplo n.º 24
0
 def __init__(self, name, process, platform, env, region, domain=None, public=False):
     self.name = name
     self.process = process
     self.platform = platform
     self.env = env
     self.loadbalancer_name = "%s-%s-%s-%s" % (self.process, self.name, self.platform, self.env)
     self.region = region
     self.connection = elb.connect_to_region(self.region)
     self.interval = 10
     self.healthy_threshold = 3
     self.unhealthy_threshold = 5
     self.target = 'HTTP:80/'
     self.listeners = {
         '80': [(80, 80, 'http')],
         '443': [(80, 80, 'http'), (443, 80, 'https')]
     }
     self.domain = domain
     self.listener = self.listeners['80']
     self.public = public
Exemplo n.º 25
0
def get_aws_connection(service, region_name='eu-west-1'):

    credentials = {
        'aws_access_key_id': config.AWS_ACCESS_KEY_ID,
        'aws_secret_access_key': config.AWS_SECERET_ACCESS_KEY
    }

    if service == 'ec2':
        return ec2.connect_to_region(region_name, **credentials)
    elif service == 'cloudformation':
        return cloudformation.connect_to_region(region_name, **credentials)
    elif service == 'autoscale':
        return autoscale.connect_to_region(region_name, **credentials)
    elif service == 'elb':
        return elb.connect_to_region(region_name, **credentials)
    elif service == 'cloudwatch':
        return cloudwatch.connect_to_region(region_name, **credentials)
    else:
        raise Exception("Unkown service '%s'" % service)
Exemplo n.º 26
0
def _initialise_aws_connections():
    _log.info('Initialising AWS Connections')

    _validate_environment()

    # Even though the Boto lib can use the environment variables we'll import one
    # for easier re-use in this script
    _log.info('Loading credentials from Environment')
    aws_region = os.getenv('AWS_DEFAULT_REGION')

    _log.info('Initializing Boto resources')
    resources = {
        'vpc': vpc.connect_to_region(aws_region),
        'ec2': ec2.connect_to_region(aws_region),
        'elb': elb.connect_to_region(aws_region),
        'iam': iam.connect_to_region(aws_region),
        'route53': Route53Connection(),
        'cloudwatch': cloudwatch.connect_to_region(aws_region),
        'region': aws_region
    }

    return resources
Exemplo n.º 27
0
Arquivo: elb.py Projeto: eofs/aws
 def __init__(self, settings):
     super(ELBService, self).__init__(settings)
     region_name = settings.get('ELB', 'REGION_NAME', 'us-west-1')
     self.conn = elb.connect_to_region(region_name=region_name)
     assert self.conn is not None
Exemplo n.º 28
0
 def setUp(self):
     self.env_id = uuid.uuid4().hex
     from boto.ec2 import elb
     self.elb = elb.connect_to_region(self.region)
Exemplo n.º 29
0
        clean_env()
        self.conf = '%s/%s/%s.ini' % (os.getenv('AWS_CRED_DIR'),
                                      acct_name, acct_name)
        try:
            boto.config.load_credential_file(self.conf)
        except IOError, msg:
            print >> sys.stderr, 'ERROR: %s' % msg
            return False
        if service == 's3':
            self.conn = s3.connect_to_region(region)
        if service == 'ec2':
            self.conn = ec2.connect_to_region(region)
        if service == 'rds':
            self.conn = rds.connect_to_region(region)
        if service == 'rds2':
            self.conn = rds2.connect_to_region(region)
        if service == 'elb':
            self.conn = elb.connect_to_region(region)
        if service == 'sqs':
            self.conn = sqs.connect_to_region(region)
        if service == 'emr':
            self.conn = emr.connect_to_region(region)
        if service == 'route53':
            self.conn = route53.connect_to_region(region)
        if service == 'iam':
            self.conn = iam.connect_to_region('universal')
        if not self.conn:
            print >> sys.stderr, 'ERROR: Unknown service'
            return False
        return self.conn
Exemplo n.º 30
0
def connect_elb(region = None):
    """Return a boto ELBConnection using credentials specified in env.  Connects to env.aws_ec2_region unless otherwise specified.
    Use directly for AWS-specific tweaking not supported by other fabulous functionality."""
    region = region or env.aws_ec2_region
    return elb.connect_to_region(region, aws_access_key_id=env.aws_access_key_id, aws_secret_access_key=env.aws_secret_access_key)
Exemplo n.º 31
0
Arquivo: elb.py Projeto: s12v/taupage
 def __init__(self, region):
     configure_logging()
     self.logger = logging.getLogger(__name__)
     self.elb_client = elb.connect_to_region(region)
Exemplo n.º 32
0
def get_elb_connection():
    connection = elb.connect_to_region(config.get_value('Boto', 'elb_region_name'))
    if connection is None:
        raise ELBError.CannotGetConnection("cannot get elb connection. invalid 'elb_region_name'?")
    else:
        return connection
Exemplo n.º 33
0
 def __init__(self, region):
     configure_logging()
     self.logger = logging.getLogger(__name__)
     self.elb_client = elb.connect_to_region(region)
Exemplo n.º 34
0
def update_listeners(region_name, elb_name, proxy_rules):
    c = connect_to_region(region_name)
    c.create_load_balancer_listeners(elb_name, [(p.haproxy_port, p.haproxy_port, p.protocol) for p in proxy_rules])
Exemplo n.º 35
0
import urllib2
import redis
import boto.ec2 as ec2
import boto.ec2.elb as elb

instance_id = urllib2.urlopen(
    "http://169.254.169.254/latest/meta-data/instance-id").read()

print "I am %s" % instance_id
region = os.environ['AWS_REGION']
if region == 'compute-1':
    region = 'us-east-1'
print "We are in %s" % region

ec2_con = ec2.connect_to_region(region)
elb_con = elb.connect_to_region(region)

reservations = ec2_con.get_all_instances()
instances = [i for r in reservations for i in r.instances]
elb_name = None
for instance in instances:
    if instance.__dict__['id'] == instance_id:
        elb_name = instance.__dict__['tags']['bidderElb']
        break
if elb_name is None:
    print "ERROR: cannot figure out my ELB name!"
    sys.exit(1)
print "My ELB is %s" % elb_name
elbs = elb_con.get_all_load_balancers(load_balancer_names=[elb_name])
count = 0
for state in elbs[0].get_instance_health():
Exemplo n.º 36
0
 def __init__(self, region, **kwargs):
     self.conn = connect_to_region(region, **kwargs)
Exemplo n.º 37
0
import sys

AWS_REGION = ''
AWS_KEY = ''
AWS_SECRET = ''
ELB_NAME = ''

CRITICAL_LIMIT = 1

state = {}
state['InService'] = 0
state['OutOfService'] = 0
state['unknown'] = 0

conn = elb.connect_to_region(AWS_REGION,
                             aws_access_key_id=AWS_KEY,
                             aws_secret_access_key=AWS_SECRET)

instances = conn.describe_instance_health("tester")

for instance in instances:
    if instance.state == 'InService':
        state['InService'] += 1
    elif instance.state == 'OutOfService':
        state['OutOfService'] = +1
    else:
        state['unknown'] += 1

if state['unknown'] > 0:
    message = "WARN - instances in an unknown state | "
    EXIT = 1
Exemplo n.º 38
0
 def __init__(self, settings):
     super(ELBService, self).__init__(settings)
     region_name = settings.get('ELB', 'REGION_NAME', 'us-west-1')
     self.conn = elb.connect_to_region(region_name=region_name)
     assert self.conn is not None
Exemplo n.º 39
0
from time import mktime
from fabric import api as fab
from boto import ec2
from boto.ec2 import elb, ec2object
from fabric.operations import run, put

logger = logging.getLogger('AMIBackup')
hdlr = logging.FileHandler('fab.log')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
 
SERVER_USER = '******'
SSH_KEY_FILE = 'id_rsa.pem'
lb_conn = elb.connect_to_region("ap-southeast-1")
ec_conn = ec2.connect_to_region("ap-southeast-1")
env = fab.env
local = fab.local
cd = fab.cd
run = fab.run

env.user = '******'
env.disable_known_hosts = "True"  # for EC2
env.key = 'id_rsa.pem'
env.key_filename = '/home/ubuntu/id_rsa.pem'
env.dir = '/home/ubuntu/src/apps/'
# Sets the number of concurrent processes to use
# when executing tasks in parallel
env.pool_size = 5
Exemplo n.º 40
0
def get_elb_connection():
    c = elb.connect_to_region(config.region,
                              aws_access_key_id=config.aws_access_key_id,
                              aws_secret_access_key=config.aws_secret_access_key)

    return c
Exemplo n.º 41
0
        listc.append(i.placement)

    if placement =='d':
        listd.append(i.placement)

    if placement =='e':
        liste.append(i.placement)



connection=ec2.connect_to_region('us-east-1')
regions = connection.get_all_regions()
for region in regions:
    lbconnection = boto.ec2.elb.connect_to_region(region.name)
    ec2conn = ec2.connect_to_region(region.name)
    elbconn = elb.connect_to_region(region.name)
    elbs = lbconnection.get_all_load_balancers()
    if not elbs:
        with open('ELB.csv', 'a') as csvfile:
                        writer = csv.writer(csvfile, delimiter='\t')
                        writer.writerow(['ELB does not exists',region.name])

    else:
        for lb in elbs:
                number= len(lb.instances)
                if lb.instances:
                    lista = []
                    listb = []
                    listc = []
                    listd = []
                    liste = []
Exemplo n.º 42
0
 def aws_conn_elb(region, profile='default'):
   try:
     conn = elb.connect_to_region(region, profile_name=profile)
     return conn
   except Exception as e:
     logging.error("Unable to connect to region, please investigate: {0}".format(e))
Exemplo n.º 43
0
 def register_node(self, instance_id):
     elb = elb.connect_to_region(self.region)
     lb = elb.get_all_load_balancers(load_balancer_names=self.app_name)
     lb.register_instances([instance_id])
Exemplo n.º 44
0
from time import mktime
from fabric import api as fab
from boto import ec2
from boto.ec2 import elb, ec2object
from fabric.operations import run, put

logger = logging.getLogger('AMIBackup')
hdlr = logging.FileHandler('fab.log')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)

SERVER_USER = '******'
SSH_KEY_FILE = 'id_rsa.pem'
lb_conn = elb.connect_to_region("ap-southeast-1")
ec_conn = ec2.connect_to_region("ap-southeast-1")
env = fab.env
local = fab.local
cd = fab.cd
run = fab.run

env.user = '******'
env.disable_known_hosts = "True"  # for EC2
env.key = 'id_rsa.pem'
env.key_filename = '/home/ubuntu/id_rsa.pem'
env.dir = '/home/ubuntu/src/apps/'
# Sets the number of concurrent processes to use
# when executing tasks in parallel
env.pool_size = 5
Exemplo n.º 45
0
def _ConnectELB(region_name):
  """Connect to a given region for load balancer queries."""
  return elb.connect_to_region(region_name)
Exemplo n.º 46
0
 def configure(self, region='ap-southeast-2'):
     self.conn = connect_to_region(region_name=region, **self.aws_keys)
     return self.conn  # Hmm, if only I could inherit a class from this connection
Exemplo n.º 47
0
def load_balancer_deregister_instance(
        region_name, aws_creds, lb_name, instance_name):
    instance = get_instance(region_name, aws_creds, instance_name)
    elb_cxn = elb.connect_to_region(region_name, **aws_creds)
    elb_cxn.deregister_instances(lb_name, [instance.id])
Exemplo n.º 48
0
def get_elb_connection(region_name):
    return elb.connect_to_region(region_name)
Exemplo n.º 49
0
def load_balancer_deregister_instance(region_name, aws_creds, lb_name,
                                      instance_name):
    instance = get_instance(region_name, aws_creds, instance_name)
    elb_cxn = elb.connect_to_region(region_name, **aws_creds)
    elb_cxn.deregister_instances(lb_name, [instance.id])
Exemplo n.º 50
0
import sys

AWS_REGION = ''
AWS_KEY = ''
AWS_SECRET = ''
ELB_NAME = ''

CRITICAL_LIMIT = 1

state = {}
state['InService'] = 0
state['OutOfService'] = 0
state['unknown'] = 0


conn = elb.connect_to_region(AWS_REGION, aws_access_key_id=AWS_KEY,
                            aws_secret_access_key=AWS_SECRET)


instances = conn.describe_instance_health("tester")

for instance in instances:
    if instance.state == 'InService':
        state['InService'] += 1
    elif instance.state == 'OutOfService':
        state['OutOfService'] =+ 1
    else:
        state['unknown'] +=1

if state['unknown'] > 0:
    message = "WARN - instances in an unknown state | "
    EXIT = 1