Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
akinaka
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
12
Issues
12
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
olindata
akinaka
Commits
cb174486
Verified
Commit
cb174486
authored
Nov 08, 2019
by
Afraz Ahmadzadeh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Explicitly set versions on launch templates
parent
896d566e
Pipeline
#2307
failed with stages
in 23 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
14 deletions
+47
-14
akinaka/update/asg/update_asg.py
akinaka/update/asg/update_asg.py
+46
-13
setup.py
setup.py
+1
-1
No files found.
akinaka/update/asg/update_asg.py
View file @
cb174486
...
...
@@ -53,15 +53,42 @@ class ASG():
inactive_asg
=
self
.
get_inactive_asg
(
asg
)
self
.
scale
(
inactive_asg
,
0
,
0
,
0
)
def
set_asg_launch_template_version
(
self
,
asg
,
lt_id
,
lt_version
):
asg_client
=
aws_client
.
create_client
(
'autoscaling'
,
self
.
region
,
self
.
role_arn
)
asg_client
.
update_auto_scaling_group
(
AutoScalingGroupName
=
asg
,
LaunchTemplate
=
{
"LaunchTemplateId"
:
lt_id
,
"Version"
:
lt_version
}
)
def
do_update
(
self
,
ami
,
asg
=
None
,
loadbalancer
=
None
,
target_group
=
None
):
asg_liveness_info
=
self
.
asgs_by_liveness
(
asg
=
asg
,
loadbalancer
=
loadbalancer
,
target_group
=
target_group
)
inactive_asg
=
asg_liveness_info
[
'inactive_asg'
]
active_asg
=
asg_liveness_info
[
'active_asg'
]
new_ami
=
ami
current_lt_info
=
self
.
get_launch_template_info
(
self
.
get_lt_name
(
inactive_asg
))
logging
.
info
(
"New ASG was worked out as {}. Now updating it's Launch Template"
.
format
(
inactive_asg
))
self
.
update_launch_template
(
inactive_asg
,
new_ami
,
self
.
get_lt_name
(
inactive_asg
))
# Set the current ASG to the current launch template version. Shouldn't actually be necessary,
# since it's done during the previous deploy, but including for completeness and paranoia
self
.
set_asg_launch_template_version
(
asg
=
active_asg
,
lt_id
=
current_lt_info
[
"id"
],
lt_version
=
current_lt_info
[
"version"
],
)
# Update the lt and set the soon to be new ASG to the new launch template version
updated_lt
=
self
.
update_launch_template
(
new_ami
,
self
.
get_lt_name
(
inactive_asg
))
self
.
set_asg_launch_template_version
(
asg
=
inactive_asg
,
lt_id
=
updated_lt
[
"id"
],
lt_version
=
updated_lt
[
"version"
]
)
scale_to
=
self
.
get_current_scale
(
active_asg
)
...
...
@@ -231,7 +258,9 @@ class ASG():
return
"-"
.
join
(
asg_parts
)
def
get_launch_template_id
(
self
,
lt_name
):
def
get_launch_template_info
(
self
,
lt_name
):
"""Returns the [id] and (latest) [version] number for lt_name"""
ec2_client
=
aws_client
.
create_client
(
'ec2'
,
self
.
region
,
self
.
role_arn
)
response
=
ec2_client
.
describe_launch_templates
(
...
...
@@ -244,23 +273,27 @@ class ASG():
]
)
# This is hackish because we are assuming that there is going to be only 1 (one) launch template
#
FIXME:
This is hackish because we are assuming that there is going to be only 1 (one) launch template
return
{
"id"
:
response
[
'LaunchTemplates'
][
0
][
'LaunchTemplateId'
],
"version"
:
response
[
'LaunchTemplates'
][
0
][
'LatestVersionNumber'
]
"version"
:
str
(
response
[
'LaunchTemplates'
][
0
][
'LatestVersionNumber'
])
}
def
update_launch_template
(
self
,
inactive_asg
,
ami
,
lt_name
):
lt
=
self
.
get_launch_template_id
(
lt_name
)
lt_client
=
aws_client
.
create_client
(
'ec2'
,
self
.
region
,
self
.
role_arn
)
def
update_launch_template
(
self
,
ami
,
lt_name
):
"""
Creates a new template version for [lt_name] which uses [ami], and sets the default
default template version to be that version.
lt_id
=
lt
[
'id'
]
lt_source_version
=
str
(
lt
[
'version'
])
Returns [id] and (new) [version] number
"""
lt
=
self
.
get_launch_template_info
(
lt_name
)
lt_client
=
aws_client
.
create_client
(
'ec2'
,
self
.
region
,
self
.
role_arn
)
response
=
lt_client
.
create_launch_template_version
(
DryRun
=
False
,
LaunchTemplateId
=
lt
_id
,
SourceVersion
=
lt_source_version
,
LaunchTemplateId
=
lt
[
'id'
]
,
SourceVersion
=
str
(
lt
[
'version'
])
,
LaunchTemplateData
=
{
"ImageId"
:
ami
}
...
...
@@ -269,12 +302,12 @@ class ASG():
launch_template_new_version
=
str
(
response
[
'LaunchTemplateVersion'
][
'VersionNumber'
])
lt_client
.
modify_launch_template
(
LaunchTemplateId
=
lt
_id
,
LaunchTemplateId
=
lt
[
'id'
]
,
DefaultVersion
=
launch_template_new_version
)
return
{
"id"
:
lt
_id
,
"id"
:
lt
[
'id'
]
,
"version"
:
launch_template_new_version
}
...
...
setup.py
View file @
cb174486
...
...
@@ -8,7 +8,7 @@ with open("README.md", "r") as fh:
setuptools
.
setup
(
name
=
"akinaka"
,
version
=
"0.4.0"
,
version
=
"0.4.0
-alpha
"
,
python_requires
=
'>=3.3.0'
,
author
=
"Afraz"
,
author_email
=
"afraz@olindata.com"
,
...
...
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