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
7043e457
Commit
7043e457
authored
Oct 23, 2013
by
Feanil Patel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correct indentation and add argument parsing.
parent
00151dbb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
10 deletions
+42
-10
util/jenkins/create_stack.py
+42
-10
No files found.
util/jenkins/create_stack.py
View file @
7043e457
...
...
@@ -3,10 +3,15 @@ import boto
from
os.path
import
basename
from
time
import
sleep
region
=
'us-east-1'
stack_name
=
'testautostack'
bucket_name
=
'edx-sandbox-devops2'
template
=
'/Users/feanil/src/configuration/cloudformation_templates/edx-reference-architecture.json'
FAILURE_STATES
=
[
'CREATE_FAILED'
,
'ROLLBACK_IN_PROGRESS'
,
'ROLLBACK_FAILED'
,
'ROLLBACK_COMPLETE'
,
'DELETE_IN_PROGRESS'
,
'DELETE_FAILED'
,
'DELETE_COMPLETE'
,
]
def
upload_file
(
file_path
,
bucket_name
,
key_name
):
"""
...
...
@@ -22,16 +27,15 @@ def upload_file(file_path, bucket_name, key_name):
key
=
boto
.
s3
.
key
.
Key
(
bucket
)
key
.
key
=
key_name
key
.
set_contents_from_filename
(
file_path
)
# May not be necessary.
url
=
"https://s3.amazonaws.com/{}/{}"
.
format
(
bucket_name
,
key_name
)
url
=
'https://s3.amazonaws.com/{}/{}'
.
format
(
bucket_name
,
key_name
)
return
url
def
create_stack
(
stack_name
,
template
,
region
=
'us-east-1'
,
blocking
=
True
):
cfn
=
boto
.
connect_cloudformation
()
# Upload the template to s3
key_name
=
"cloudformation/auto/{}_{}"
.
format
(
stack_name
,
basename
(
template
))
key_name
=
'cloudformation/auto/{}_{}'
.
format
(
stack_name
,
basename
(
template
))
template_url
=
upload_file
(
template
,
bucket_name
,
key_name
)
# Reference the stack.
...
...
@@ -40,11 +44,13 @@ def create_stack(stack_name, template, region='us-east-1', blocking=True):
template_url
=
template_url
,
capabilities
=
[
'CAPABILITY_IAM'
],
tags
=
{
'autostack'
:
'true'
},
parameters
=
[(
"KeyName"
,
"continuous-integration"
)])
parameters
=
[(
'KeyName'
,
'continuous-integration'
)])
except
Exception
as
e
:
print
(
e
.
message
)
raise
e
status
=
None
while
blocking
:
sleep
(
5
)
stack_instance
=
cfn
.
describe_stacks
(
stack_id
)[
0
]
...
...
@@ -53,8 +59,34 @@ def create_stack(stack_name, template, region='us-east-1', blocking=True):
if
'COMPLETE'
in
status
:
break
if
status
in
FAILURE_STATES
:
raise
Excoption
(
'Creation Failed. Stack Status: {}, ID:{}'
.
format
(
status
,
stack_id
))
return
stack_id
create_stack
(
stack_name
,
template
,
region
)
print
(
'Stack({}) created.'
.
format
(
stack_name
))
if
__name__
==
'__main__'
:
description
=
'Create a cloudformation stack from a template.'
parser
=
argparse
.
ArgumentParser
(
description
)
msg
=
'Name for the cloudformation stack.'
parser
.
add_argument
(
'-n'
,
'--stackname'
,
required
=
True
,
help
=
msg
)
msg
=
'Name of the bucket to use for temporarily uploading the
\
template.'
parser
.
add_argument
(
'-b'
,
'--bucketname'
,
default
=
"edx-sandbox-devops"
,
help
=
msg
)
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
()
stack_name
=
args
.
stackname
template
=
args
.
template
region
=
args
.
region
create_stack
(
stack_name
,
template
,
region
)
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