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
c263d5de
Commit
c263d5de
authored
3 years ago
by
Juraj Paluba
Browse files
Options
Downloads
Patches
Plain Diff
Resolve "Integrate APG library"
parent
2d182bef
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Dockerfile
+3
-1
3 additions, 1 deletion
Dockerfile
entrypoint.sh
+11
-1
11 additions, 1 deletion
entrypoint.sh
prepare_answers.py
+78
-0
78 additions, 0 deletions
prepare_answers.py
with
92 additions
and
2 deletions
Dockerfile
+
3
−
1
View file @
c263d5de
...
...
@@ -4,16 +4,18 @@ ENV ANSIBLE_STDOUT_CALLBACK=default
ENV
ANSIBLE_RETRY_FILES_ENABLED=0
ENV
ANSIBLE_SSH_RETRIES=20
ENV
ANSIBLE_SSH_ARGS="-o ServerAliveInterval=30 -o ControlMaster=auto -o ControlPersist=60s"
ENV
PIP_EXTRA_INDEX_URL="https://gitlab.ics.muni.cz/api/v4/projects/2358/packages/pypi/simple"
RUN
apt update
&&
apt
install
-y
gnupg2 git autossh
RUN
pip3
install
ansible
==
3.0.0 pypsrp requests[socks]
RUN
pip3
install
ansible
==
3.0.0 pypsrp requests[socks]
automated-problem-generation-lib
RUN
rm
-rf
/var/cache/apt/
RUN
mkdir
-p
/root/.ssh
COPY
./entrypoint.sh /app/
COPY
prepare_answers.py /app/
WORKDIR
/app
...
...
This diff is collapsed.
Click to expand it.
entrypoint.sh
+
11
−
1
View file @
c263d5de
...
...
@@ -54,6 +54,16 @@ cd ansible_repo || exit 1
if
[
$REVISION
]
;
then
git checkout
$REVISION
||
exit
1
fi
ANSWERS_FILE
=
$(
realpath
'answers.json'
)
echo
{}
>
"
$ANSWERS_FILE
"
VARIABLES_FILE
=
'variables.yml'
PREPARE_ANSWERS_PY
=
'../prepare_answers.py'
if
[
-f
$VARIABLES_FILE
]
;
then
python3.8
"
$PREPARE_ANSWERS_PY
"
"
$INVENTORY_FILE
"
"
$ANSWERS_FILE
"
fi
git submodule update
--init
--recursive
||
exit
1
cd
provisioning
||
exit
1
...
...
@@ -75,4 +85,4 @@ if [ -f $PRE_PLAYBOOK_FILE ]; then
fi
PLAYBOOK_FILE
=
"playbook.yml"
ansible-playbook
$PLAYBOOK_FILE
-i
"
${
INVENTORY_FILE
}
"
-vv
||
exit
"
$?
"
ansible-playbook
$PLAYBOOK_FILE
-i
"
${
INVENTORY_FILE
}
"
-e
"@
$ANSWERS_FILE
"
-vv
||
exit
"
$?
"
This diff is collapsed.
Click to expand it.
prepare_answers.py
0 → 100644
+
78
−
0
View file @
c263d5de
import
yaml
import
json
import
requests
import
argparse
from
generator.var_generator
import
generate
from
generator.var_parser
import
parser_var_file
from
requests.exceptions
import
ConnectionError
VARIABLE_FILE_PATH
=
'
variables.yml
'
KYPO_ANSWERS_STORAGE_API_URL
=
'
http://answers-storage:8087/kypo-rest-answers-storage/api/v1
'
HEADERS
=
{
'
accept
'
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
}
def
load_inventory_variables
(
inventory_path
):
with
open
(
inventory_path
,
'
r
'
)
as
file
:
return
yaml
.
full_load
(
file
)[
'
all
'
][
'
vars
'
]
def
create_answers_file
(
generated_answers
,
answers_path
):
with
open
(
answers_path
,
'
w
'
)
as
file
:
json
.
dump
(
generated_answers
,
file
)
def
generate_answers
(
inventory_variables
):
pool_id
=
inventory_variables
[
'
kypo_global_pool_id
'
]
sandbox_id
=
inventory_variables
[
'
kypo_global_sandbox_allocation_unit_id
'
]
seed
=
(
pool_id
+
sandbox_id
)
*
43
with
open
(
VARIABLE_FILE_PATH
,
'
r
'
)
as
file
:
variable_list
=
parser_var_file
(
file
)
return
generate
(
variable_list
,
seed
)
def
get_post_data_json
(
inventory_variables
,
generated_answers
):
sandbox_id
=
inventory_variables
[
'
kypo_global_sandbox_allocation_unit_id
'
]
post_data
=
{
'
sandbox_ref_id
'
:
sandbox_id
,
'
sandbox_answers
'
:
[]
}
for
key
,
item
in
generated_answers
.
items
():
post_data
[
'
sandbox_answers
'
].
append
({
'
answer_content
'
:
item
,
'
answer_identifier
'
:
key
})
return
json
.
dumps
(
post_data
,
indent
=
4
)
def
send_post_request
(
inventory_variables
,
generated_answers
):
post_data_json
=
get_post_data_json
(
inventory_variables
,
generated_answers
)
try
:
requests
.
post
(
KYPO_ANSWERS_STORAGE_API_URL
+
'
/sandboxes
'
,
data
=
post_data_json
,
headers
=
HEADERS
)
except
ConnectionError
:
print
(
'
\n
[Warning]: Service answers-storage is unavailable.
\n
'
)
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'
inventory_path
'
)
parser
.
add_argument
(
'
answers_path
'
)
args
=
parser
.
parse_args
()
inventory_variables
=
load_inventory_variables
(
args
.
inventory_path
)
generated_answers
=
generate_answers
(
inventory_variables
)
create_answers_file
(
generated_answers
,
args
.
answers_path
)
send_post_request
(
inventory_variables
,
generated_answers
)
if
__name__
==
'
__main__
'
:
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