def __init__(self): mock = moto.ec2.mock_ec2() mock.start() mapfile = os.getcwd() + '/tests/conf/account_aliases_map.txt' cmgr = ZambiConn(mapfile=mapfile) os.environ['AWS_CRED_DIR'] = os.getcwd() + '/tests' self.conn = cmgr.get_connection('opsqa') self.ec2 = instances.C3Instance(self.conn)
def __init__(self): self.cconfig = self.get_test_config() mock = moto.elb.mock_elb() mock.start() mapfile = os.getcwd() + '/tests/conf/account_aliases_map.txt' cmgr = ZambiConn(mapfile=mapfile) os.environ['AWS_CRED_DIR'] = os.getcwd() + '/tests' self.conn = cmgr.get_connection('opsqa', service='elb') self.elb = None
class Nv2Route53(object): ''' Update Route53 with AWS hostnames in nventory. ''' def __init__(self, options): self.options = options self.cmgr = ZambiConn() self.accounts = self.cmgr.get_accounts(self.options.aws_account) for self.account in self.accounts: self.dns = None self.update_records() if self.options.graphite: self.send_metrics() def send_metrics(self): ''' Send route53 metrics to graphite ''' mpfx = 'business.aws.route53.%s' % self.account (creates, updates, count) = self.dns.get_metrics() grp = Graphite(server=self.options.graphite_server) grp.send_metric(mpfx + ".updates", updates, self.options.debug) grp.send_metric(mpfx + ".creates", creates, self.options.debug) grp.send_metric(mpfx + ".count", count, self.options.debug) def update_records(self): ''' Run route53 updates based on nventory ''' nvd = Nventory(ini_file=self.options.nv_ini) conn = self.cmgr.get_connection(self.account, service='route53') self.dns = HostedZone(conn, self.account, self.options.comment, domain=self.options.domain) data = { 'loc': '', 'env': '', 'sclass': '', 'acct': self.account, 'domain': self.options.domain} nodes = nvd.get_nodes(data) nvec2nodes = dict() for node in nodes: if node['name'] and node['ec2_instance_id']: nvec2nodes[node['name']] = { 'type': 'CNAME', 'ttl': self.options.ttl, 'resource': [node['ec2_public_hostname']]} if nvec2nodes: self.dns.add_update_records( nvec2nodes, record_type='CNAME', ttl=self.options.ttl) else: print 'INFO: No nodes found in external data source.'
def send_to_aws(data, account, bucket, tagset, region, verbose): ''' Creates a connection to AWS and sends data ''' conn_manager = ZambiConn() conn = conn_manager.get_connection(account, service='s3') s3_bucket = C3S3Bucket(conn, bucket, region) print 'INFO: Updating %s:%s' % (account, bucket) print 'INFO: Setting tags' if verbose: print 'INFO: TAGS:\n%s' % tagset s3_bucket.set_tags(tagset, verbose) if data: print 'INFO: Setting bucket policy' if verbose: print 'INFO: JSON OUTPUT:\n%s' % data s3_bucket.upload_policy(data) else: s3_bucket.upload_policy(data)
def aws_conn(self, service): """ Gets a connection to EC2. """ zambi = ZambiConn() conn = zambi.get_connection(self.cconfig.get_aws_account(), service, self.cconfig.get_aws_region()) return conn