Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos-caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Guillaume Hervier
slapos-caddy
Commits
26d287d3
Commit
26d287d3
authored
Jul 31, 2015
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kvm: add check Ansible task promises
parent
ae270044
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
159 additions
and
3 deletions
+159
-3
software/kvm/common.cfg
software/kvm/common.cfg
+21
-2
software/kvm/instance-kvm.cfg.jinja2
software/kvm/instance-kvm.cfg.jinja2
+28
-1
software/kvm/instance-logrotate-base.cfg.in
software/kvm/instance-logrotate-base.cfg.in
+50
-0
software/kvm/instance.cfg.in
software/kvm/instance.cfg.in
+3
-0
software/kvm/template/ansible-promise.in
software/kvm/template/ansible-promise.in
+57
-0
No files found.
software/kvm/common.cfg
View file @
26d287d3
...
...
@@ -87,7 +87,7 @@ command =
[template]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg.in
md5sum =
3bca2c959d19881270c64f94ad1ebba8
md5sum =
98116c0ccac67ca97e5bd1ce2b9008a2
output = ${buildout:directory}/template.cfg
mode = 0644
...
...
@@ -95,7 +95,7 @@ mode = 0644
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/instance-kvm.cfg.jinja2
mode = 644
md5sum =
ea1e8f4a7c1878beec83267fd40728c2
md5sum =
d1598672b2957cf89b63c86c754c7afb
download-only = true
on-update = true
...
...
@@ -168,6 +168,14 @@ md5sum = cdb690495e9eb007d2b7d2f8e12f5c59
output = ${buildout:directory}/template-frontend.cfg
mode = 0644
[template-ansible-promise]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/template/ansible-promise.in
md5sum = d0bd07d5a7799b7aea7720ffdf46f322
mode = 0644
download-only = true
filename = ansible-promise.in
[template-apache-conf]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/template/apache.conf.in
...
...
@@ -186,6 +194,17 @@ md5sum = 822737e483864bf255ad1259237bef2a
download-only = true
on-update = true
[template-logrotate-base]
recipe = slapos.recipe.template:jinja2
filename = instance-logrotate-base.cfg
template = ${:_profile_base_location_}/instance-logrotate-base.cfg.in
rendered = ${buildout:parts-directory}/${:_buildout_section_name_}/instance-logrotate-base.cfg
md5sum = f28fbd310944f321ccb34b2a34c82005
context =
key dcron_location dcron:location
key gzip_location gzip:location
key logrotate_location logrotate:location
[template-httpd]
recipe = slapos.recipe.template:jinja2
filename = template-httpd.cfg
...
...
software/kvm/instance-kvm.cfg.jinja2
View file @
26d287d3
{% set enable_http = slapparameter_dict.get('enable-http-server', 'False').lower() -%}
{% set use_tap = slapparameter_dict.get('use-tap', 'False').lower() -%}
{% set use_nat = slapparameter_dict.get('use-nat', 'True').lower() -%}
{% set name = slapparameter_dict.get('name', 'localhost') -%}
#############################
#
# Instanciate kvm
...
...
@@ -28,11 +29,16 @@ parts =
{% if slapparameter_dict.get('data-to-vm', '') %}
vm-data-content
{% endif -%}
{% if use_tap == 'true' and tap_network_dict.has_key('ipv4') %}
ansible-vm-promise
logrotate-vm-bootstrap
{% endif -%}
{% if slapparameter_dict.get('authorized-key', '') %}
get-authorized-key
{% endif -%}
# extends =
extends =
{{ logrotate_cfg }}
# {{ template_httpd_cfg }}
{% endif -%}
...
...
@@ -412,6 +418,27 @@ shell-path = {{ dash_executable_location }}
6tunnel-path = {{ sixtunnel_executable_location }}
runner-path = ${directory:services}/6tunnel-cluster
[ansible-vm-promise]
recipe = slapos.recipe.template:jinja2
template = {{ ansible_promise_tpl }}
rendered = ${directory:promises}/ansible_{{ name }}
extensions = jinja2.ext.do
context =
key host slap-network-information:tap-ipv4
raw logs ${directory:public}/ansible
raw name {{ name }}
[logrotate-vm-bootstrap]
< = logrotate-entry-base
name = vm-bootstrap
log = ${directory:public}/ansible/vm-bootstrap.log
[logrotate-entry-base]
recipe = slapos.cookbook:logrotate.d
logrotate-entries = ${logrotate:logrotate-entries}
backup = ${logrotate:backup}
[slap-parameter]
# Default values if not specified
frontend-software-type = frontend
...
...
software/kvm/instance-logrotate-base.cfg.in
0 → 100644
View file @
26d287d3
[buildout]
parts =
cron-entry-logrotate
[cron]
recipe = slapos.cookbook:cron
cron-entries = ${logrotate-directory:cron-entries}
dcrond-binary = {{ dcron_location }}/sbin/crond
crontabs = ${logrotate-directory:crontabs}
cronstamps = ${logrotate-directory:cronstamps}
catcher = ${cron-simplelogger:wrapper}
binary = ${logrotate-directory:services}/crond
[cron-simplelogger]
recipe = slapos.cookbook:simplelogger
wrapper = ${logrotate-directory:bin}/cron_simplelogger
log = ${logrotate-directory:log}/cron.log
[logrotate]
recipe = slapos.cookbook:logrotate
logrotate-entries = ${logrotate-directory:logrotate-entries}
backup = ${logrotate-directory:logrotate-backup}
logrotate-binary = {{ logrotate_location }}/usr/sbin/logrotate
gzip-binary = {{ gzip_location }}/bin/gzip
gunzip-binary = {{ gzip_location }}/bin/gunzip
wrapper = ${logrotate-directory:bin}/logrotate
conf = ${logrotate-directory:etc}/logrotate.conf
state-file = ${logrotate-directory:srv}/logrotate.status
[cron-entry-logrotate]
recipe = slapos.cookbook:cron.d
cron-entries = ${cron:cron-entries}
name = logrotate
frequency = 0 0 * * *
command = ${logrotate:wrapper}
[logrotate-directory]
recipe = slapos.cookbook:mkdirectory
cron-entries = ${:etc}/cron.d
cronstamps = ${:etc}/cronstamps
crontabs = ${:etc}/crontabs
logrotate-backup = ${:backup}/logrotate
logrotate-entries = ${:etc}/logrotate.d
bin = ${buildout:directory}/bin
srv = ${buildout:directory}/srv
backup = ${:srv}/backup
etc = ${buildout:directory}/etc
services = ${:etc}/service
log = ${buildout:directory}/var/log
software/kvm/instance.cfg.in
View file @
26d287d3
...
...
@@ -66,6 +66,7 @@ template = ${template-kvm-cluster:location}/instance-kvm-cluster.cfg.jinja2.in
filename = template-kvm-cluster.cfg
extra-context =
section parameter_dict dynamic-template-kvm-cluster-parameters
raw logrotate_cfg ${template-logrotate-base:rendered}
raw template_content ${template-content:location}/${template-content:filename}
raw template_httpd_cfg ${template-httpd:rendered}
...
...
@@ -81,10 +82,12 @@ context =
key slapparameter_dict slap-configuration:configuration
key storage_dict slap-configuration:storage-dict
key tap_network_dict slap-configuration:tap-network-information-dict
raw ansible_promise_tpl ${template-ansible-promise:location}/${template-ansible-promise:filename}
raw curl_executable_location ${curl:location}/bin/curl
raw dash_executable_location ${dash:location}/bin/dash
raw dcron_executable_location ${dcron:location}/sbin/crond
raw debian_amd64_netinst_location ${debian-amd64-netinst.iso:location}/${debian-amd64-netinst.iso:filename}
raw logrotate_cfg ${template-logrotate-base:rendered}
raw novnc_location ${noVNC:location}
raw netcat_bin ${netcat:location}/bin/netcat
raw openssl_executable_location ${openssl:location}/bin/openssl
...
...
software/kvm/template/ansible-promise.in
0 → 100644
View file @
26d287d3
#!/usr/bin/env python
# Parse Ansible result log file and define if execution succeed or not
import
os
import
json
FIELDS
=
[
'cmd'
,
'command'
,
'start'
,
'end'
,
'delta'
,
'msg'
,
'stdout'
,
'stderr'
,
'response'
,
'status_code'
,
'url'
,
'dest'
]
ansible_log_dir
=
'{{ logs }}'
vm_name
=
'{{ name }}'
result_OK
=
'127.0.0.1_OK'
result_failed
=
'127.0.0.1_FAILED'
result_failed_ignore
=
'127.0.0.1_FAILED_IGNORED'
def
get_log
(
res
):
log
=
""
if
type
(
res
)
==
type
(
dict
()):
log
=
'>> Running task: %s, args [%s]
\
n
'
%
(
res
[
'invocation'
][
'module_name'
],
res
[
'invocation'
][
'module_args'
])
for
field
in
FIELDS
:
if
field
in
res
.
keys
():
# use default encoding, check out sys.setdefaultencoding
log
+=
'
\
n
{0}:
\
n
{1}'
.
format
(
field
,
res
[
field
])
return
log
def
file_to_dict
(
filepath
):
content
=
'{}'
with
open
(
filepath
,
'r'
)
as
f
:
content
=
f
.
read
()
return
json
.
loads
(
content
)
def
check_result
():
success_file
=
os
.
path
.
join
(
ansible_log_dir
,
result_OK
)
error_file
=
os
.
path
.
join
(
ansible_log_dir
,
result_failed
)
if
not
len
(
os
.
listdir
(
ansible_log_dir
)):
return
(
0
,
'No Ansible promise uploaded!'
)
if
os
.
path
.
exists
(
error_file
):
result
=
file_to_dict
(
error_file
)
if
len
(
result
)
>
0
:
#there is more that one failed task in the report
message
=
''
for
res
in
result
:
message
+=
'%s
\
n
\
n
'
%
get_log
(
res
)
return
(
0
,
message
)
elif
not
os
.
path
.
exists
(
success_file
):
return
(
0
,
'All Ansible tasks failed to run'
)
return
(
1
,
''
)
if
__name__
==
"__main__"
:
result
=
check_result
()
if
not
result
[
0
]:
raise
Exception
(
'Failed to run Ansible in %s, result is:
\
n
%s'
%
(
vm_name
,
result
[
1
]))
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