Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
configuration
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
configuration
Commits
b9d6e2ec
Commit
b9d6e2ec
authored
Aug 13, 2013
by
e0d
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #211 from edx/e0d/vpn-dns
initial working version
parents
bc9cc049
f3b0c9e5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
120 additions
and
0 deletions
+120
-0
util/vpc-tools/vpc-dns.py
+120
-0
No files found.
util/vpc-tools/vpc-dns.py
0 → 100644
View file @
b9d6e2ec
"""vpc-dns.py
Usage:
vpc-dns.py create-zone vpc <vpc-id>
vpc-dns.py (-h --help)
vpc-dns.py (-v --version)
Options:
-h --help Show this screen.
-v --version Show version.
"""
import
boto
from
boto.route53.record
import
ResourceRecordSets
from
docopt
import
docopt
class
VPCDns
:
BACKEND_ZONE
=
"Z4AI6ADZTL3HN"
DNS_SUFFIX
=
".vpc.edx.org"
ZONE
=
"{name}"
+
DNS_SUFFIX
def
__init__
(
self
,
vpc_id
=
None
):
self
.
vpc_id
=
vpc_id
self
.
elb
=
boto
.
connect_elb
()
self
.
r53
=
boto
.
connect_route53
()
def
create_zone
(
self
,
vpc_id
):
zone_name
=
self
.
ZONE
.
format
(
name
=
vpc_id
)
print
zone_name
hosted_zone
=
self
.
get_or_create_hosted_zone
(
zone_name
)
elbs
=
self
.
elb
.
get_all_load_balancers
()
for
elb
in
[
x
for
x
in
elbs
if
x
.
vpc_id
==
self
.
vpc_id
]:
self
.
create_service_dns
(
elb
,
self
.
get_zone_id_from_retval
(
hosted_zone
.
Id
),
self
.
vpc_id
)
def
get_zone_id_from_retval
(
self
,
retval
):
"""
The data structure returned by the create_hosted_zone call
pre-pends the string /hostedzone/ to the Id for some reason.
"""
return
retval
.
replace
(
"/hostedzone/"
,
""
)
def
get_or_create_hosted_zone
(
self
,
zone_name
):
hosted_zone
=
self
.
r53
.
get_hosted_zone_by_name
(
zone_name
)
if
not
hosted_zone
:
zone_data
=
self
.
r53
.
create_hosted_zone
(
zone_name
,
comment
=
"Created by automation."
)
hosted_zone
=
self
.
r53
.
get_hosted_zone_by_name
(
zone_name
)
return
hosted_zone
def
get_elb_service
(
self
,
elb
):
services
=
[
"edxapp"
,
"rabbit"
,
"xqueue"
,
"xserver"
,
"worker"
]
for
service
in
services
:
if
service
in
elb
.
dns_name
.
lower
():
return
service
raise
Exception
(
"No service mapping for "
+
elb
.
dns_name
)
def
create_service_dns
(
self
,
elb
,
zone
,
vpc_id
):
"""
"""
records
=
self
.
r53
.
get_all_rrsets
(
zone
)
old_names
=
[
r
.
name
for
r
in
records
]
HOST_TEMPLATE
=
"{service}.{vpc_id}"
+
self
.
DNS_SUFFIX
service
=
self
.
get_elb_service
(
elb
)
dns_name
=
HOST_TEMPLATE
.
format
(
service
=
service
,
vpc_id
=
vpc_id
)
change_set
=
ResourceRecordSets
()
if
dns_name
+
'.'
in
old_names
:
print
"adding delete"
change
=
change_set
.
add_change
(
'DELETE'
,
dns_name
,
'CNAME'
,
600
)
change
.
add_value
(
elb
.
dns_name
)
change
=
change_set
.
add_change
(
'CREATE'
,
dns_name
,
'CNAME'
,
600
)
change
.
add_value
(
elb
.
dns_name
)
print
change_set
.
to_xml
()
self
.
r53
.
change_rrsets
(
zone
,
change_set
.
to_xml
())
VERSION
=
"0.1"
def
dispatch
(
args
):
vpc_id
=
args
.
get
(
"<vpc-id>"
)
c
=
VPCDns
(
vpc_id
=
vpc_id
)
if
args
.
get
(
"create-zone"
):
c
.
create_zone
(
vpc_id
)
if
__name__
==
"__main__"
:
args
=
docopt
(
__doc__
,
version
=
VERSION
)
dispatch
(
args
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment