def get_rds_info(region, identifier=None):
    """Function for fetching RDS details"""
    rds = boto.rds.connect_to_region(region)
    try:
        if identifier:
            info = rds.get_all_dbinstances(identifier)[0]
        else:
            info = rds.get_all_dbinstances()
    except (boto.exception.BotoServerError, AttributeError):
        info = None
    return info
def get_rds_info(region, indentifier=None):
    """Function for fetching RDS details"""
    rds = boto.rds.connect_to_region(region)
    try:
        if indentifier:
            info = rds.get_all_dbinstances(indentifier)[0]
        else:
            info = rds.get_all_dbinstances()
    except boto.exception.BotoServerError:
        info = None
    return info
Example #3
0
 def wait_for_db_instance(self, rds, instance_id):
     # Don't wait more than 10m
     print "test: waiting for db instance", instance_id,
     t = time.time()
     seen = set()
     while True:
         time.sleep(3)
         sys.stdout.write(".")
         try:
             dbs = rds.get_all_dbinstances(instance_id)
         except boto.exception.EC2ResponseError, e:
             if e.error_code == "InvalidInstanceId.NotFound":
                 continue
         db = dbs.pop()
         if db.status == "available":
             print "\ntest: db %s available in %s" % (
                 instance_id, time.time() - t)
             return db
         elif db.status not in seen:
             print "\n  db status", db.status, (time.time() - t),
             seen.add(db.status)
         if time.time() - t > 15 * 60:
             raise RuntimeError(
                 "Database not provisioned within threshold %s" % (
                     instance_id))
def db_info(region):
    rds = boto.rds.connect_to_region(region)
    info = {}
    instances = rds.get_all_dbinstances()
    for instance in instances:
        info[instance.id] = {'region': region, 'engine': instance.engine}
    return info
Example #5
0
    def __init__(self, region, profile=None, identifier=None):
        """Get RDS instance details"""
        self.region = region
        self.profile = profile
        self.identifier = identifier

        if self.region == 'all':
            self.regions_list = [reg.name for reg in boto.rds.regions()]
        else:
            self.regions_list = [self.region]

        self.info = None
        if self.identifier:
            for reg in self.regions_list:
                try:
                    rds = boto.rds.connect_to_region(reg,
                                                     profile_name=self.profile)
                    self.info = rds.get_all_dbinstances(self.identifier)
                except (boto.provider.ProfileNotFoundError,
                        boto.exception.BotoServerError) as msg:
                    print 'msg'
                else:
                    # Exit on the first region and identifier match
                    self.region = reg
                    break
Example #6
0
def get_storage(metric, identifier):
    rds = conn_rds()
    info = rds.get_all_dbinstances(identifier)[0]
    free = get_metric(metrics[metric],
                      now - datetime.timedelta(seconds=5 * 60), now, 1 * 60,
                      identifier)
    return (free, info)
def get_rds_info(indentifier=None):
    """Function for fetching RDS details"""
    
    regions_list = [None]
    if all_regions:
        regions_list = [ region.name for region in boto.rds.regions() ]
    
    info = []
            
    # Search in all regions, or the default region if all_regions is None
    for region in regions_list:
        if not region:
            rds = boto.connect_rds()
        else:
            rds = boto.rds.connect_to_region(region)
        
        try:
            info.extend(rds.get_all_dbinstances(indentifier))
        except boto.exception.BotoServerError:
            pass

    if indentifier:
        if len(info)>0:
            return info[0]
            
        return None
    
    return info
Example #8
0
def build_databag(dbname):
    print(_yellow("--BUILDING DATA BAG--"))
    rds = connect_to_rds()

    # Get database host information
    try:
        inst = rds.get_all_dbinstances(instance_id=dbname)[0]
    except rds.ResponseError, e:
        print "{}: {}".format(e.code, e.message)
        return
Example #9
0
def build_databag(dbname):
    print(_yellow("--BUILDING DATA BAG--"))
    rds = connect_to_rds()

    # Get database host information
    try:
        inst = rds.get_all_dbinstances(instance_id=dbname)[0]
    except rds.ResponseError, e:
        print "{}: {}".format(e.code, e.message)
        return
Example #10
0
    def get_list(self):
        """Get list of available instances by region(s)"""
        result = dict()
        for reg in self.regions_list:
            try:
                rds = boto.rds.connect_to_region(reg, profile_name=self.profile)
                result[reg] = rds.get_all_dbinstances()
            except (boto.provider.ProfileNotFoundError, boto.exception.BotoServerError) as msg:
                debug(msg)

        return result
Example #11
0
def backupDatabase():
    ts = time.time()
    st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d-%H-%M-%S')
    snapshot_id = "mhfowler-" + str(st)
    snapshot_id = snapshot_id.replace(" ", "")
    rds = boto.connect_rds()
    instances = rds.get_all_dbinstances()
    db = instances[0]
    db.snapshot(snapshot_id)
    print("backing up database...")
    waitForDatabaseBackupToComplete()
    print("database back up successful.")
def backupDatabase():
    ts = time.time()
    st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d-%H-%M-%S')
    snapshot_id = "mhfowler-" + str(st)
    snapshot_id = snapshot_id.replace(" ","")
    rds = boto.connect_rds()
    instances = rds.get_all_dbinstances()
    db = instances[0]
    db.snapshot(snapshot_id)
    print("backing up database...")
    waitForDatabaseBackupToComplete()
    print("database back up successful.")
Example #13
0
    def on_broken(self):
        # Takes a final snapshot
        config = Config(self.unit.config_get()).validate()
        rds = self.get_rds(config)

        ident = self.get_db_identifier()
        db = rds.get_all_dbinstances(ident)
        if db is None:
            return
        rds.delete_dbinstance(db.id, final_snapshot_id="final-%s" % ident)

        # Probably doesn't work..
        rds.delete_dbsecurity_group(db.id)
Example #14
0
    def get_list(self):
        """Get list of available instances by region(s)"""
        result = dict()
        for reg in self.regions_list:
            try:
                rds = boto.rds.connect_to_region(
                    reg,
                    aws_access_key_id=self.aws_key,
                    aws_secret_access_key=self.aws_secret
                )
                result[reg] = rds.get_all_dbinstances()
            except (boto.provider.ProfileNotFoundError,
                    boto.exception.BotoServerError):
                result = {}

        return result
Example #15
0
def check_rds(region, groups, names):
    rds = boto.rds.connect_to_region(region)
    # Check EC2 classic
    rds_groups = rds.get_all_dbsecurity_groups()
    for rds_group in rds_groups:
        for ec2_group in rds_group.ec2_groups:
            if ec2_group.EC2SecurityGroupId in groups:
                raise ValueError('Security group [%s] is used in RDS security group [%s] and cannot be deleted' % 
                    (ec2_group.EC2SecurityGroupId, rds_group.name))
    # Check VPC
    instances = rds.get_all_dbinstances()
    for instance in instances:
        for rds_group in instance.vpc_security_groups:
            if rds_group.vpc_group in groups:
                raise ValueError('Security group [%s] is used by RDS database [%s] and cannot be deleted' % 
                    (rds_group.vpc_group, instance.DBName))
def get_rds_hostnames(key, secret):
    ''' returns public hostnames for rds instances '''
    hosts = []

    ec2 = boto.connect_ec2(key, secret)
    regions = ec2.get_all_regions()
    regions = [i.name for i in regions]

    for region in regions:
        rds = boto.rds.connect_to_region(region,
                                         aws_access_key_id=key,
                                         aws_secret_access_key=secret)
        rds_instances = rds.get_all_dbinstances()
        for i in rds_instances:
            hostname = i.endpoint[0]
            port = i.endpoint[1]
            hosts.append(hostname)

    return hosts
Example #17
0
def get_rds_hostnames(key, secret):
    ''' returns public hostnames for rds instances '''
    hosts = []

    ec2 = boto.connect_ec2(key, secret)
    regions = ec2.get_all_regions()
    regions = [i.name for i in regions]

    for region in regions:
        rds = boto.rds.connect_to_region(region,
                                         aws_access_key_id=key,
                                         aws_secret_access_key=secret)
        rds_instances = rds.get_all_dbinstances()
        for i in rds_instances:
            hostname = i.endpoint[0]
            port = i.endpoint[1]
            hosts.append(hostname)

    return hosts
    def __init__(self, region, profile=None, identifier=None):
        """Get RDS instance details"""
        self.region = region
        self.profile = profile
        self.identifier = identifier

        if self.region == 'all':
            self.regions_list = [reg.name for reg in boto.rds.regions()]
        else:
            self.regions_list = [self.region]

        self.info = None
        if self.identifier:
            for reg in self.regions_list:
                try:
                    rds = boto.rds.connect_to_region(reg, profile_name=self.profile)
                    self.info = rds.get_all_dbinstances(self.identifier)
                except (boto.provider.ProfileNotFoundError, boto.exception.BotoServerError) as msg:
                    debug(msg)
                else:
                    # Exit on the first region and identifier match
                    self.region = reg
                    break
# Get all instances security groups
groups_in_use = ['default']
reservations = ec2.get_all_instances()
for r in reservations:
    for ec2_group_list in r.groups:
        if ec2_group_list.name not in groups_in_use:
            groups_in_use.append(ec2_group_list.name)

elb = boto.ec2.elb.connect_to_region(args.region, aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY)
load_balancers = elb.get_all_load_balancers()
for load_balancer in load_balancers:
    if load_balancer.source_security_group.name not in groups_in_use:
        groups_in_use.append(load_balancer.source_security_group.name)

rds = boto.rds.connect_to_region(args.region, aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY)
dbs = rds.get_all_dbinstances()
for db in dbs:
    if len(db.vpc_security_groups) > 0:
        sg_name = lookup_by_id(db.vpc_security_groups[0].vpc_group)
        if sg_name not in groups_in_use:
            groups_in_use.append(sg_name)

enis = ec2.get_all_network_interfaces()
for eni in enis:
    for eni_grp in eni.groups:
        if eni_grp.name not in groups_in_use:
            groups_in_use.append(eni_grp.name)

delete_candidates = []
for group in allgroups:
    if group not in groups_in_use and not group.startswith('AWS-OpsWorks-'):
Example #20
0
#!/usr/bin/python

import boto.rds
from pprint import pprint
rds=boto.rds.connect_to_region("ap-southeast-1", aws_access_key_id='',aws_secret_access_key='')

instances=rds.get_all_dbinstances()
#dbsecurity=rds.get_all_dbsecurity_groups()

print("DBName,create_time,endpoint,status,instance_type,muti_az,storage,engine,Version,masterUsername")
for dbi in instances:
	print("%s,%s,%s,%s,%s,%s,%s" % (dbi.__dict__['id'],dbi.__dict__['create_time'],dbi.__dict__['endpoint'][0],dbi.__dict__['status'],dbi.__dict__['instance_class'],dbi.__dict__['multi_az'],dbi.__dict__['allocated_storage']))

#pprint(instances)
#pprint(dbsecurity)
 def get_entities_for_region(self, region):
     rds = boto.connect_rds(self.access_key_id,
                            self.secret_access_key,
                            region=region)
     return rds.get_all_dbinstances()
Example #22
0
def get_list(rds):
    return [i.DBName for i in rds.get_all_dbinstances()]
 def get_entities_for_region(self, region):
     rds = boto.connect_rds(self.access_key_id, self.secret_access_key, region=region)
     return rds.get_all_dbinstances()