Skip to content

Commit

Permalink
Add internal dns records
Browse files Browse the repository at this point in the history
  • Loading branch information
datianshi committed May 16, 2016
1 parent c5991f8 commit 5150dc0
Show file tree
Hide file tree
Showing 5 changed files with 1,991 additions and 45 deletions.
1 change: 1 addition & 0 deletions deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ region: us-east-1
ssh_key_name: pcf-sding
ssh_private_key_path: /Users/sding/work/aws/personal/pcf-sding.pem
ssl_cert_arn: arn:aws:iam::375783000519:server-certificate/shaozhen-certificate
skip_cert_verify: true
stack-name: shaozhen
uid: 0f64e4
_START_INSTALLS_: false
87 changes: 44 additions & 43 deletions dnsmapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,47 @@ def map_ert_domain(stackname, domain, lbname=None,
if not domain.endswith('.'):
domain += '.'

zone = next(
(z for z in route53.list_hosted_zones()['HostedZones']
if domain.endswith(z['Name'])), None)

# based on standard naming
lbname = lbname or stackname + "-pcf-elb"
resp = elb.describe_load_balancers(
LoadBalancerNames=[lbname])

if len(resp.get('LoadBalancerDescriptions', [])) == 0:
raise Exception(lbname + " Loadbalacer could not be found")

dnsname = resp['LoadBalancerDescriptions'][0]['DNSName']

if zone is None:
print domain + " Is not managed in route53"
print "Manually map {} <-- {}".format(dnsname, names)
return

# ensure names are unique
names = set(names)

changes = [
{
'Action': 'UPSERT',
'ResourceRecordSet': {
'Name': name,
'Type': 'CNAME',
'TTL': 300,
'ResourceRecords': [
{
'Value': dnsname
},
],
}
} for name in names]

route53.change_resource_record_sets(
HostedZoneId=zone['Id'],
ChangeBatch={
'Comment': "for stack="+stackname,
'Changes': changes
})
zones = [z for z in route53.list_hosted_zones()['HostedZones'] if domain.endswith(z['Name'])]
for zone in zones:
# based on standard naming
if zone['Config']['PrivateZone'] == False:
lbname = stackname + "-pcf-elb"
if zone['Config']['PrivateZone'] == True:
lbname = stackname + "-pcf-elb-in"
resp = elb.describe_load_balancers(
LoadBalancerNames=[lbname])

if len(resp.get('LoadBalancerDescriptions', [])) == 0:
raise Exception(lbname + " Loadbalacer could not be found")

dnsname = resp['LoadBalancerDescriptions'][0]['DNSName']

if not zones:
print domain + " Is not managed in route53"
print "Manually map {} <-- {}".format(dnsname, names)
return

# ensure names are unique
names = set(names)

changes = [
{
'Action': 'UPSERT',
'ResourceRecordSet': {
'Name': name,
'Type': 'CNAME',
'TTL': 300,
'ResourceRecords': [
{
'Value': dnsname
},
],
}
} for name in names]

route53.change_resource_record_sets(
HostedZoneId=zone['Id'],
ChangeBatch={
'Comment': "for stack="+stackname,
'Changes': changes
})
5 changes: 3 additions & 2 deletions ert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ products:
- az-(( PcfPrivateSubnet2AvailabilityZone ))
- az-(( PcfPrivateSubnet3AvailabilityZone ))
singleton_availability_zone_reference: az-(( PcfPrivateSubnetAvailabilityZone ))
network_reference: (( PcfInfrastructureSubnet ))
properties:
- identifier: logger_endpoint_port
value: 4443
Expand Down Expand Up @@ -75,12 +76,12 @@ products:
value: (( Opts_skip_cert_verify ))
- identifier: ssl_ciphers
- identifier: router
elb_names: (( Opts_stack-name ))-pcf-elb
elb_names: (( Opts_stack-name ))-pcf-elb,(( Opts_stack-name ))-pcf-elb-in
instance:
identifier: instances
value: 2
- identifier: diego_brain
elb_names: (( Opts_stack-name ))-pcf-ssh-elb
elb_names: (( Opts_stack-name ))-pcf-ssh-elb,(( Opts_stack-name ))-pcf-ssh-elb-in
- identifier: nfs_server
instance:
identifier: instances
Expand Down
Loading

0 comments on commit 5150dc0

Please sign in to comment.