Commit fec255a3 by John Jarvis

adding play mappings for the commoncluster

parent 9af1878a
...@@ -35,9 +35,19 @@ import sys ...@@ -35,9 +35,19 @@ import sys
# up the dns name to be unique # up the dns name to be unique
ELB_BAN_LIST = [ ELB_BAN_LIST = [
'prod-mcki-AprosELB-887241654.us-east-1.elb.amazonaws.com', 'Apros',
] ]
# If the ELB name has the key in its name these plays
# will be used for the DNS CNAME tuple. This is used for
# commoncluster.
ELB_PLAY_MAPPINGS = {
'RabbitMQ': 'rabbitmq',
'Xqueue': 'xqueue',
'Elastic': 'elasticsearch',
}
class DNSRecord(): class DNSRecord():
...@@ -88,8 +98,8 @@ def add_or_update_record(dns_records): ...@@ -88,8 +98,8 @@ def add_or_update_record(dns_records):
if record.record_name in old_records.keys(): if record.record_name in old_records.keys():
if record.record_name + "." == old_records[record.record_name].name and \ if record.record_name + "." == old_records[record.record_name].name and \
record.record_type == old_records[record.record_name].type: record.record_type == old_records[record.record_name].type:
print "Record for {} already exists and is identical, skipping.\n".format( print("Record for {} already exists and is identical, skipping.\n".format(
record.record_name) record.record_name))
continue continue
if args.force: if args.force:
...@@ -119,7 +129,7 @@ def add_or_update_record(dns_records): ...@@ -119,7 +129,7 @@ def add_or_update_record(dns_records):
if args.noop: if args.noop:
print("Would have submitted the following change set:\n") print("Would have submitted the following change set:\n")
xml_doc = xml.dom.minidom.parseString(change_set.to_xml()) xml_doc = xml.dom.minidom.parseString(change_set.to_xml())
print xml_doc.toprettyxml(newl='') # newl='' to remove extra newlines print(xml_doc.toprettyxml(newl='')) # newl='' to remove extra newlines
else: else:
r53.change_rrsets(zone_id, change_set.to_xml()) r53.change_rrsets(zone_id, change_set.to_xml())
print("Updated DNS record:\n{}".format(status_msg)) print("Updated DNS record:\n{}".format(status_msg))
...@@ -170,7 +180,6 @@ def get_security_group_dns(group_name): ...@@ -170,7 +180,6 @@ def get_security_group_dns(group_name):
def get_dns_from_instances(elb): def get_dns_from_instances(elb):
for inst in elb.instances: for inst in elb.instances:
try: try:
instance = ec2_con.get_all_instances( instance = ec2_con.get_all_instances(
...@@ -186,7 +195,6 @@ def get_dns_from_instances(elb): ...@@ -186,7 +195,6 @@ def get_dns_from_instances(elb):
else: else:
# deprecated, for backwards compatibility # deprecated, for backwards compatibility
play_tag = instance.tags['role'] play_tag = instance.tags['role']
break # only need the first instance for tag info break # only need the first instance for tag info
except KeyError: except KeyError:
print("Instance {}, attached to elb {} does not " print("Instance {}, attached to elb {} does not "
...@@ -218,16 +226,24 @@ def update_elb_rds_dns(zone): ...@@ -218,16 +226,24 @@ def update_elb_rds_dns(zone):
stack_elbs = [elb for elb in elb_con.get_all_load_balancers() stack_elbs = [elb for elb in elb_con.get_all_load_balancers()
if elb.vpc_id == vpc_id] if elb.vpc_id == vpc_id]
for elb in stack_elbs: for elb in stack_elbs:
if "RabbitMQ" in elb.source_security_group.name or "ElasticSearch" in elb.source_security_group.name:
env_tag, deployment_tag, play_tag = get_security_group_dns(elb.source_security_group.name)
fqdn = "{}-{}-{}.{}".format(env_tag, play_tag, deployment_tag, zone_name)
if elb.dns_name not in ELB_BAN_LIST:
dns_records.add(DNSRecord(zone, fqdn, 'CNAME', 600, [elb.dns_name]))
else:
env_tag, deployment_tag, play_tag = get_dns_from_instances(elb) env_tag, deployment_tag, play_tag = get_dns_from_instances(elb)
# Override the play tag if a substring of the elb name
# is in ELB_PLAY_MAPPINGS
for key in ELB_PLAY_MAPPINGS.keys():
if key in elb.name:
play_tag = ELB_PLAY_MAPPINGS[key]
break
fqdn = "{}-{}-{}.{}".format(env_tag, deployment_tag, play_tag, zone_name) fqdn = "{}-{}-{}.{}".format(env_tag, deployment_tag, play_tag, zone_name)
if elb.dns_name not in ELB_BAN_LIST:
# Skip over ELBs if a substring of the ELB name is in
# the ELB_BAN_LIST
if any(name in elb.name for name in ELB_BAN_LIST):
print("Skipping {} because it is on the ELB ban list".format(elb.name))
continue
dns_records.add(DNSRecord(zone, fqdn, 'CNAME', 600, [elb.dns_name])) dns_records.add(DNSRecord(zone, fqdn, 'CNAME', 600, [elb.dns_name]))
stack_rdss = [rds for rds in rds_con.get_all_dbinstances() stack_rdss = [rds for rds in rds_con.get_all_dbinstances()
...@@ -288,6 +304,5 @@ if __name__ == "__main__": ...@@ -288,6 +304,5 @@ if __name__ == "__main__":
# Connect to route53 using the user's .boto file # Connect to route53 using the user's .boto file
r53 = boto.connect_route53() r53 = boto.connect_route53()
zone = get_or_create_hosted_zone(args.zone_name) zone = get_or_create_hosted_zone(args.zone_name)
update_elb_rds_dns(zone) update_elb_rds_dns(zone)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment