Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Knot DNS
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
21
Issues
21
List
Boards
Labels
Service Desk
Milestones
Merge Requests
16
Merge Requests
16
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
Knot projects
Knot DNS
Commits
051cd241
Commit
051cd241
authored
Nov 07, 2016
by
Filip Siroky
Committed by
Daniel Salzman
Dec 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python/libknot: add statistics support
parent
707befeb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
1 deletion
+55
-1
python/libknot/control.py
python/libknot/control.py
+55
-1
No files found.
python/libknot/control.py
View file @
051cd241
...
...
@@ -198,7 +198,7 @@ class KnotCtl(object):
return
KnotCtlType
(
data_type
.
value
)
def
send_block
(
self
,
cmd
,
section
=
None
,
item
=
None
,
identifier
=
None
,
zone
=
None
,
owner
=
None
,
ttl
=
None
,
rtype
=
None
,
data
=
None
):
owner
=
None
,
ttl
=
None
,
rtype
=
None
,
data
=
None
,
flags
=
None
):
"""Sends a control query block.
@type cmd: str
...
...
@@ -222,6 +222,7 @@ class KnotCtl(object):
query
[
KnotCtlDataIdx
.
TTL
]
=
ttl
query
[
KnotCtlDataIdx
.
TYPE
]
=
rtype
query
[
KnotCtlDataIdx
.
DATA
]
=
data
query
[
KnotCtlDataIdx
.
FLAGS
]
=
flags
self
.
send
(
KnotCtlType
.
DATA
,
query
)
self
.
send
(
KnotCtlType
.
BLOCK
)
...
...
@@ -296,6 +297,59 @@ class KnotCtl(object):
else
:
out
[
zone
][
owner
][
rtype
][
"data"
].
append
(
data
)
def
_receive_stats
(
self
,
out
,
reply
):
zone
=
reply
[
KnotCtlDataIdx
.
ZONE
]
section
=
reply
[
KnotCtlDataIdx
.
SECTION
]
item
=
reply
[
KnotCtlDataIdx
.
ITEM
]
idx
=
reply
[
KnotCtlDataIdx
.
ID
]
data
=
reply
[
KnotCtlDataIdx
.
DATA
]
# Add the zone if not exists.
if
zone
:
if
"zone"
not
in
out
:
out
[
"zone"
]
=
dict
()
if
zone
not
in
out
[
"zone"
]:
out
[
"zone"
][
zone
]
=
dict
()
section_level
=
out
[
"zone"
][
zone
]
if
zone
else
out
if
section
not
in
section_level
:
section_level
[
section
]
=
dict
()
if
idx
:
if
item
not
in
section_level
[
section
]:
section_level
[
section
][
item
]
=
dict
()
section_level
[
section
][
item
][
idx
]
=
data
else
:
section_level
[
section
][
item
]
=
data
def
receive_stats
(
self
):
"""Receives statistics answer and returns it as a structured dictionary.
@rtype: dict
"""
out
=
dict
()
while
True
:
reply
=
KnotCtlData
()
reply_type
=
self
.
receive
(
reply
)
# Stop if not data type.
if
reply_type
not
in
[
KnotCtlType
.
DATA
,
KnotCtlType
.
EXTRA
]:
break
# Check for an error.
if
reply
[
KnotCtlDataIdx
.
ERROR
]:
raise
Exception
(
reply
[
KnotCtlDataIdx
.
ERROR
])
self
.
_receive_stats
(
out
,
reply
)
return
out
def
receive_block
(
self
):
"""Receives a control answer and returns it as a structured dictionary.
...
...
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