Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
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
Nicolas Wavrant
slapos.toolbox
Commits
f899e43d
Commit
f899e43d
authored
May 27, 2013
by
Vivien Alger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added script for kvm monitoring test + entry point
parent
816b9114
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
113 additions
and
0 deletions
+113
-0
setup.py
setup.py
+1
-0
slapos/test_conso.py
slapos/test_conso.py
+112
-0
No files found.
setup.py
View file @
f899e43d
...
...
@@ -62,6 +62,7 @@ setup(name=name,
'cloudstop = slapos.cloudmgr.stop:main'
,
'equeue = slapos.equeue:main'
,
'killpidfromfile = slapos.systool:killpidfromfile'
,
'kvm-monitor-test = slapos.test_conso:runMonitor'
,
'lampconfigure = slapos.lamp:run [lampconfigure]'
,
'onetimedownload = slapos.onetimedownload:main'
,
'onetimeupload = slapos.onetimeupload:main'
,
...
...
slapos/test_conso.py
0 → 100755
View file @
f899e43d
# -*- coding: utf-8 -*-
from
ConfigParser
import
RawConfigParser
from
lxml.etree
import
Element
,
SubElement
,
ElementTree
from
argparse
import
ArgumentParser
class
MonitorConfig
():
"""
Class used for parsing the configuration file
and returning a dict with the selected options and their values
"""
def
__init__
(
self
,
filepath
,
sections
,
options
):
"""
filepath : path to configuration file that need to be parsed
sections : sections in which the options we need can be found
options : options that we need to check for billing
"""
self
.
filepath
=
filepath
self
.
sections
=
sections
self
.
options
=
options
self
.
parser
=
RawConfigParser
()
self
.
parser
.
optionxform
=
lambda
s
:
s
def
getConfig
(
self
):
"""
Method for parsing the configuration file and
returning the dict of options
"""
result
=
{}
conf_file
=
open
(
self
.
filepath
)
self
.
parser
.
readfp
(
conf_file
)
for
section
in
self
.
sections
:
tmp_dict
=
dict
(
self
.
parser
.
items
(
section
))
for
option
in
self
.
options
:
result
[
option
]
=
tmp_dict
.
get
(
option
,
""
)
conf_file
.
close
()
return
result
class
GenerateXMLFile
():
"""
Class used to serialize the dict of options and output it to XML
"""
def
__init__
(
self
,
xml_filepath
,
conso_dict
):
"""
xml_filepath : path to the XML output file
conso_dict : dict of options
(generated by the previous class method getConfig)
"""
self
.
xml_filepath
=
xml_filepath
self
.
element_tree
=
self
.
_serializeDictToElementTree
(
conso_dict
)
def
_serializeDictToElementTree
(
self
,
info_dict
):
"""
Transform the dict of options into XML
return ElementTree
"""
result
=
ElementTree
(
Element
(
"data"
))
root
=
result
.
getroot
()
for
key
,
value
in
info_dict
.
items
():
tmp
=
SubElement
(
root
,
key
)
tmp
.
text
=
value
return
result
def
outputFile
(
self
):
"""
Write the XML to a file
"""
self
.
element_tree
.
write
(
self
.
xml_filepath
,
encoding
=
"utf-8"
,
xml_declaration
=
True
)
def
parseCli
():
"""
Parser definition for the command line interface
"""
usage
=
""" %(prog)s <filepath> -s [sections] -opts [options] """
parser
=
ArgumentParser
(
prog
=
"test_conso"
,
usage
=
usage
)
parser
.
add_argument
(
"filepath"
,
help
=
"Path to the configuration file with the informations"
)
parser
.
add_argument
(
"-s"
,
"--sections"
,
nargs
=
'+'
,
required
=
True
,
help
=
"Sections in which the informations can be found."
+
"Each section should be separated by a space."
)
parser
.
add_argument
(
"-opts"
,
"--options"
,
nargs
=
'+'
,
required
=
True
,
help
=
"Options that need to be reported by the monitor."
+
"Each option should be separated by a space."
)
return
parser
def
runMonitor
():
"""
Procedure called to run the monitoring (from parsing the configuration file
to the XML output)
"""
parser
=
parseCli
()
args
=
parser
.
parse_args
()
info_dict
=
MonitorConfig
(
args
.
filepath
,
args
.
sections
,
args
.
options
,
).
getConfig
()
serializer
=
GenerateXMLFile
(
"report.xml"
,
info_dict
)
serializer
.
outputFile
()
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