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
ae320738
Commit
ae320738
authored
Oct 21, 2013
by
Feanil Patel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update to 4 spaces.
parent
d97e086c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
60 deletions
+82
-60
util/vpc-tools/vpc_dns.py
+82
-60
No files found.
util/vpc-tools/vpc_dns.py
View file @
ae320738
...
...
@@ -2,90 +2,112 @@ import boto
from
vpcutil
import
vpc_for_stack_name
stack_name
=
'testforumstack9'
r53
=
boto
.
connect_route53
()
# Utility Functions
def
add_zone_to_parent
(
zone
,
parent
):
#Add a reference for the new zone to its parent zone.
parent_name
=
parent
.
Name
[:
-
1
]
zone_name
=
zone
.
Name
[:
-
1
]
change_set
=
boto
.
route53
.
record
.
ResourceRecordSets
()
change
=
change_set
.
add_change
(
'CREATE'
,
zone_name
,
'NS'
,
900
)
change
.
add_value
(
zone
.
NameServers
)
def
get_or_create_hosted_zone
(
zone_name
):
r53
=
boto
.
connect_route53
()
hosted_zone
=
r53
.
get_hosted_zone_by_name
(
zone_name
)
def
get_or_create_hosted_zone
(
zone_name
):
# Get the parent zone.
parent_zone_name
=
"."
.
join
(
zone_name
.
split
(
'.'
)[
1
:])
parent_zone
=
r53
.
get_hosted_zone_by_name
(
parent_zone_name
)
if
not
parent_zone
:
msg
=
"Parent zone({}) does not exist."
raise
Exception
(
msg
.
format
(
parent_zone_name
))
if
not
hosted_zone
:
zone_data
=
r53
.
create_hosted_zone
(
zone_name
,
comment
=
"Created by automation."
)
hosted_zone
=
r53
.
get_hosted_zone_by_name
(
zone_name
)
return
hosted_zone
if
not
hosted_zone
:
r53
.
create_hosted_zone
(
zone_name
,
comment
=
"Created by automation."
)
hosted_zone
=
r53
.
get_hosted_zone_by_name
(
zone_name
)
add_zone_to_parent
(
hosted_zone
,
parent_zone
)
return
hosted_zone
def
elbs_for_stack_name
(
stack_name
):
vpc_id
=
vpc_for_stack_name
(
stack_name
)
elbs
=
boto
.
connect_elb
()
for
elb
in
elbs
.
get_all_load_balancers
():
if
elb
.
vpc_id
==
vpc_id
:
yield
elb
vpc_id
=
vpc_for_stack_name
(
stack_name
)
elbs
=
boto
.
connect_elb
()
for
elb
in
elbs
.
get_all_load_balancers
():
if
elb
.
vpc_id
==
vpc_id
:
yield
elb
def
create_service_dns
(
elb
,
prefix
,
zone
):
# Get all record sets in zone
r53
=
boto
.
connect_route53
(
debug
=
2
)
# Get all record sets in zone
zone_id
=
zone
.
Id
.
replace
(
"/hostedzone/"
,
""
)
records
=
r53
.
get_all_rrsets
(
zone_id
)
zone_id
=
zone
.
Id
.
replace
(
"/hostedzone/"
,
""
)
records
=
r53
.
get_all_rrsets
(
zone_id
)
old_names
=
[
r
.
name
[:
-
1
]
for
r
in
records
]
print
(
old_names
)
old_names
=
[
r
.
name
[:
-
1
]
for
r
in
records
]
print
(
old_names
)
dns_template
=
"{prefix}.{zone_name}"
dns_template
=
"{prefix}.{zone_name}"
# Have to remove the trailing period that is on zone names.
zone_name
=
zone
.
Name
[:
-
1
]
dns_name
=
dns_template
.
format
(
prefix
=
prefix
,
zone_name
=
zone_name
)
# Have to remove the trailing period that is on zone names.
zone_name
=
zone
.
Name
[:
-
1
]
dns_name
=
dns_template
.
format
(
prefix
=
prefix
,
zone_name
=
zone_name
)
change_set
=
boto
.
route53
.
record
.
ResourceRecordSets
()
change_set
=
boto
.
route53
.
record
.
ResourceRecordSets
()
# If the dns name already points to something.
# Delete the existing connection.
print
(
dns_name
)
if
dns_name
in
old_names
:
print
"adding delete"
change
=
change_set
.
add_change
(
'DELETE'
,
dns_name
,
'CNAME'
,
600
)
# If the dns name already points to something.
# Delete the existing connection.
print
(
dns_name
)
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
.
add_value
(
elb
.
dns_name
)
change
=
change_set
.
add_change
(
'CREATE'
,
dns_name
,
'CNAME'
,
600
)
change
=
change_set
.
add_change
(
'CREATE'
,
dns_name
,
'CNAME'
,
600
)
change
.
add_value
(
elb
.
dns_name
)
change
.
add_value
(
elb
.
dns_name
)
print
change_set
.
to_xml
()
print
change_set
.
to_xml
()
r53
.
change_rrsets
(
zone_id
,
change_set
.
to_xml
())
r53
.
change_rrsets
(
zone_id
,
change_set
.
to_xml
())
if
__name__
==
"__main__"
:
# Create DNS for edxapp and xqueue.
dns_settings
=
{
'edxapp'
:
[
'courses'
,
'studio'
],
'xqueue'
:
[
'xqueue'
],
'rabbit'
:
[
'rabbit'
],
'xserver'
:
[
'xserver'
],
'worker'
:
[
'worker'
],
}
# Create DNS for edxapp and xqueue.
dns_settings
=
{
'edxapp'
:
[
'courses'
,
'studio'
],
'xqueue'
:
[
'xqueue'
],
'rabbit'
:
[
'rabbit'
],
'xserver'
:
[
'xserver'
],
'worker'
:
[
'worker'
],
'forum'
:
[
'forum'
],
}
# Create a zone for the stack.
zone_name
=
"{}.vpc.edx.org"
.
format
(
stack_name
)
# Create a zone for the stack.
zone_name
=
"{}.vpc.edx.org"
.
format
(
stack_name
)
zone
=
get_or_create_hosted_zone
(
zone_name
)
zone
=
get_or_create_hosted_zone
(
zone_name
)
stack_elbs
=
elbs_for_stack_name
(
stack_name
)
for
elb
in
stack_elbs
:
for
service
,
dns_prefixes
in
dns_settings
.
items
():
if
service
in
elb
.
dns_name
.
lower
():
for
prefix
in
dns_prefixes
:
create_service_dns
(
elb
,
prefix
,
zone
)
stack_elbs
=
elbs_for_stack_name
(
stack_name
)
for
elb
in
stack_elbs
:
for
service
,
dns_prefixes
in
dns_settings
.
items
():
#FIXME this breaks when the service name is in the stack name ie. testforumstack.
if
service
in
elb
.
dns_name
.
lower
():
for
prefix
in
dns_prefixes
:
create_service_dns
(
elb
,
prefix
,
zone
)
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