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
edx
configuration
Commits
61509b64
Commit
61509b64
authored
Nov 09, 2013
by
Feanil Patel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Be able to create stacks from a list of parameters.
parent
a52c9f6b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
58 deletions
+27
-58
cloudformation_templates/edx-reference-architecture.json
+1
-47
util/vpc-tools/create_stack.py
+26
-11
No files found.
cloudformation_templates/edx-reference-architecture.json
View file @
61509b64
...
...
@@ -4864,52 +4864,6 @@
"Value"
:{
"Ref"
:
"EdxappServerSecurityGroup"
}
},
"DatabaseConfigurationString"
:{
"Description"
:
"JDBC connection string for database"
,
"Value"
:{
"Fn::Join"
:[
""
,
[
"'DATABASES': {
\n
"
,
" 'default': {
\n
"
,
" 'ENGINE': 'django.db.backends.mysql',
\n
"
,
" 'NAME': '"
,
{
"Ref"
:
"DBName"
},
"',
\n
"
,
" 'USER': '"
,
{
"Ref"
:
"DBUsername"
},
"',
\n
"
,
" 'PASSWORD': '"
,
{
"Ref"
:
"DBPassword"
},
"',
\n
"
,
" 'HOST': '"
,
{
"Fn::GetAtt"
:[
"EdxDB"
,
"Endpoint.Address"
]
},
"',
\n
"
,
" 'PORT': '"
,
{
"Fn::GetAtt"
:[
"EdxDB"
,
"Endpoint.Port"
]
},
"'
\n
"
,
" }
\n
"
,
"}
\n
"
]
]
}
}
}
}
}
util/vpc-tools/create_stack.py
View file @
61509b64
import
argparse
import
boto
import
yaml
from
os.path
import
basename
from
time
import
sleep
from
pprint
import
pprint
FAILURE_STATES
=
[
'CREATE_FAILED'
,
...
...
@@ -25,17 +28,21 @@ def upload_file(file_path, bucket_name, key_name):
bucket
=
conn
.
get_bucket
(
bucket_name
,
validate
=
False
)
key
=
boto
.
s3
.
key
.
Key
(
bucket
)
key
.
key
=
key_name
key
.
key
=
key_name
key
.
set_contents_from_filename
(
file_path
)
url
=
'https://s3.amazonaws.com/{}/{}'
.
format
(
bucket_name
,
key_name
)
key
.
set_acl
(
'public-read'
)
url
=
key
.
generate_url
(
300
,
query_auth
=
False
)
return
url
def
create_stack
(
stack_name
,
template
,
region
=
'us-east-1'
,
blocking
=
True
,
temp_bucket
=
'edx-sandbox-devops'
):
def
create_stack
(
stack_name
,
template
,
region
=
'us-east-1'
,
blocking
=
True
,
temp_bucket
=
'edx-sandbox-devops'
,
parameters
=
[]):
cfn
=
boto
.
connect_cloudformation
()
# Upload the template to s3
key_name
=
'cloudformation/auto/{}_{}'
.
format
(
stack_name
,
basename
(
template
))
key_pattern
=
'devops/cloudformation/auto/{}_{}'
key_name
=
key_pattern
.
format
(
stack_name
,
basename
(
template
))
template_url
=
upload_file
(
template
,
temp_bucket
,
key_name
)
# Reference the stack.
...
...
@@ -44,13 +51,14 @@ def create_stack(stack_name, template, region='us-east-1', blocking=True, temp_b
template_url
=
template_url
,
capabilities
=
[
'CAPABILITY_IAM'
],
tags
=
{
'autostack'
:
'true'
},
parameters
=
[(
'KeyName'
,
'continuous-integration'
)]
)
parameters
=
parameters
)
except
Exception
as
e
:
print
(
e
.
message
)
raise
e
status
=
None
remove_file
(
temp_bucket
,
key_name
)
status
=
None
while
blocking
:
sleep
(
5
)
stack_instance
=
cfn
.
describe_stacks
(
stack_id
)[
0
]
...
...
@@ -65,6 +73,9 @@ def create_stack(stack_name, template, region='us-east-1', blocking=True, temp_b
return
stack_id
def
cfn_params_from
(
filename
):
params_dict
=
yaml
.
safe_load
(
open
(
filename
))
return
[
(
key
,
value
)
for
key
,
value
in
params_dict
.
items
()
]
if
__name__
==
'__main__'
:
description
=
'Create a cloudformation stack from a template.'
...
...
@@ -80,15 +91,19 @@ if __name__ == '__main__':
msg
=
'The path to the cloudformation template.'
parser
.
add_argument
(
'-t'
,
'--template'
,
required
=
True
,
help
=
msg
)
msg
=
'The AWS region to build this stack in.'
parser
.
add_argument
(
'-r'
,
'--region'
,
default
=
'us-east-1'
,
help
=
msg
)
args
=
parser
.
parse_args
()
msg
=
'YAML file containing stack build parameters'
parser
.
add_argument
(
'-p'
,
'--parameters'
,
help
=
msg
)
args
=
parser
.
parse_args
()
stack_name
=
args
.
stackname
template
=
args
.
template
region
=
args
.
region
bucket_name
=
args
.
bucketname
parameters
=
cfn_params_from
(
args
.
parameters
)
create_stack
(
stack_name
,
template
,
region
,
bucket_name
)
create_stack
(
stack_name
,
template
,
region
,
temp_bucket
=
bucket_name
,
parameters
=
parameters
)
print
(
'Stack({}) created.'
.
format
(
stack_name
))
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