Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kypo-ansible-runner
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MUNI-KYPO-CRP
backend-python
kypo-ansible-runner
Commits
6f3ac79c
Commit
6f3ac79c
authored
3 years ago
by
Juraj Paluba
Browse files
Options
Downloads
Patches
Plain Diff
Resolve "Revise user ansible cleanup stage flow"
parent
897a6d60
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
entrypoint.sh
+5
-4
5 additions, 4 deletions
entrypoint.sh
manage_answers.py
+16
-20
16 additions, 20 deletions
manage_answers.py
with
21 additions
and
24 deletions
entrypoint.sh
+
5
−
4
View file @
6f3ac79c
...
...
@@ -63,10 +63,13 @@ ANSWERS_FILE=$(realpath 'answers.json')
echo
{}
>
"
$ANSWERS_FILE
"
VARIABLES_FILE
=
'variables.yml'
PREPARE_ANSWERS_PY
=
'../
manage_answers.py
'
PREPARE_ANSWERS_PY
=
$(
realpath
"
manage_answers.py
"
)
if
[
-f
$VARIABLES_FILE
]
;
then
python3.8
"
$PREPARE_ANSWERS_PY
"
"
$INVENTORY_FILE
"
"
$ANSWERS_FILE
"
"
$ANSWERS_STORAGE_API
"
fi
if
$USER_CLEANUP
;
then
python3.8
"
$PREPARE_ANSWERS_PY
"
"
$INVENTORY_FILE
"
"
$ANSWERS_FILE
"
"
$ANSWERS_STORAGE_API
"
--cleanup
fi
git submodule update
--init
--recursive
||
exit
1
cd
provisioning
||
exit
1
...
...
@@ -89,6 +92,4 @@ if [ -f $PRE_PLAYBOOK_FILE ]; then
fi
PLAYBOOK_FILE
=
"playbook.yml"
if
!
$USER_CLEANUP
;
then
ansible-playbook
$PLAYBOOK_FILE
-i
"
${
INVENTORY_FILE
}
"
-e
"@
$ANSWERS_FILE
"
-vv
||
exit
"
$?
"
fi
\ No newline at end of file
ansible-playbook
$PLAYBOOK_FILE
-i
"
${
INVENTORY_FILE
}
"
-e
"@
$ANSWERS_FILE
"
-vv
||
exit
"
$?
"
This diff is collapsed.
Click to expand it.
manage_answers.py
+
16
−
20
View file @
6f3ac79c
...
...
@@ -50,10 +50,6 @@ def get_post_data_json(sandbox_id, generated_answers):
return
json
.
dumps
(
post_data
,
indent
=
4
)
def
get_answers
(
answers_storage_api
,
sandbox_id
):
return
requests
.
get
(
answers_storage_api
+
'
/sandboxes/
'
+
str
(
sandbox_id
)
+
'
/answers
'
)
def
delete_answers
(
answers_storage_api
,
sandbox_id
):
requests
.
delete
(
answers_storage_api
+
'
/sandboxes/
'
+
str
(
sandbox_id
)).
raise_for_status
()
...
...
@@ -65,37 +61,37 @@ def post_answers(answers_storage_api, sandbox_id, generated_answers):
post_response
.
raise_for_status
()
def
manage_answers
(
inventory_variables
,
generated_answers
,
answers_storage_api
):
sandbox_id
=
inventory_variables
[
'
kypo_global_sandbox_allocation_unit_id
'
]
if
get_answers
(
answers_storage_api
,
sandbox_id
).
status_code
==
404
:
post_answers
(
answers_storage_api
,
sandbox_id
,
generated_answers
)
return
'
post
'
else
:
delete_answers
(
answers_storage_api
,
sandbox_id
)
return
'
delete
'
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'
inventory_path
'
)
parser
.
add_argument
(
'
answers_file_path
'
)
parser
.
add_argument
(
'
answers_storage_api
'
)
parser
.
add_argument
(
'
--cleanup
'
,
action
=
'
store_true
'
)
args
=
parser
.
parse_args
()
inventory_variables
=
load_inventory_variables
(
args
.
inventory_path
)
sandbox_id
=
inventory_variables
[
'
kypo_global_sandbox_allocation_unit_id
'
]
answers_file_path
=
args
.
answers_file_path
answers_storage_api
=
args
.
answers_storage_api
generated_answers
=
generate_answers
(
inventory_variables
)
create_answers_file
(
generated_answers
,
answers_file_path
)
_success_msg
=
"
\n
[OK]: Successful {} upon answers-storage container.
\n
"
_request_error_msg
=
"
\n
[WARNING]: Failed {} upon answers-storage container.
"
\
"
Status code {}.
\n
"
try
:
operation
=
manage_answers
(
inventory_variables
,
generated_answers
,
answers_storage_api
)
print
(
f
'
\n
[OK]: Operation [
{
operation
}
] upon answers-storage container was successful.
\n
'
)
if
args
.
cleanup
:
delete_answers
(
answers_storage_api
,
sandbox_id
)
print
(
_success_msg
.
format
(
'
DELETE
'
))
return
generated_answers
=
generate_answers
(
inventory_variables
)
create_answers_file
(
generated_answers
,
answers_file_path
)
post_answers
(
answers_storage_api
,
sandbox_id
,
generated_answers
)
print
(
_success_msg
.
format
(
'
POST
'
))
except
ConnectionError
:
print
(
'
\n
[Warning]: Service answers-storage is unavailable.
\n
'
)
except
HTTPError
as
exc
:
print
(
f
'
\n
[Warning]: Unable to send generated answers to kypo-answers-storage service,
'
f
'
status code
{
exc
.
response
}
.
\n
'
)
print
(
_request_error_msg
.
format
(
'
DELETE
'
if
args
.
cleanup
else
'
POST
'
,
exc
.
response
))
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment