Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
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
Roque
slapos.core
Commits
c4d44672
Commit
c4d44672
authored
Jun 05, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proxy show: use logger
parent
123c6ca6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
46 deletions
+38
-46
slapos/cli/proxy_show.py
slapos/cli/proxy_show.py
+38
-46
No files found.
slapos/cli/proxy_show.py
View file @
c4d44672
...
...
@@ -71,7 +71,7 @@ def coalesce(*seq):
return
el
def
print_table
(
qry
,
tablename
,
skip
=
None
):
def
log_table
(
logger
,
qry
,
tablename
,
skip
=
None
):
if
skip
is
None
:
skip
=
set
()
...
...
@@ -88,19 +88,19 @@ def print_table(qry, tablename, skip=None):
pt
.
add_row
(
row
)
if
rows
:
print
'table %s:'
%
tablename
,
if
skip
:
print
'skipping %s'
%
', '
.
join
(
skip
)
logger
.
info
(
'table %s: skipping %s'
,
tablename
,
', '
.
join
(
skip
)
)
else
:
print
logger
.
info
(
'table %s'
,
tablename
)
else
:
print
'table %s: empty'
%
tablename
logger
.
info
(
'table %s: empty'
,
tablename
)
return
print
pt
.
get_string
(
border
=
True
,
padding_width
=
0
,
vrules
=
prettytable
.
NONE
)
for
line
in
pt
.
get_string
(
border
=
True
,
padding_width
=
0
,
vrules
=
prettytable
.
NONE
).
split
(
'
\
n
'
):
logger
.
info
(
line
)
def
print_params
(
conn
):
def
log_params
(
logger
,
conn
):
cur
=
conn
.
cursor
()
qry
=
cur
.
execute
(
"SELECT reference, partition_reference, software_type, connection_xml FROM %s"
%
tbl_partition
)
...
...
@@ -109,44 +109,44 @@ def print_params(conn):
continue
xml
=
str
(
row
[
'connection_xml'
])
print
'%s: %s (type %s)'
%
(
row
[
'reference'
],
row
[
'partition_reference'
],
row
[
'software_type'
])
logger
.
info
(
'%s: %s (type %s)'
,
row
[
'reference'
],
row
[
'partition_reference'
],
row
[
'software_type'
])
instance
=
lxml
.
etree
.
fromstring
(
xml
)
for
parameter
in
list
(
instance
):
name
=
parameter
.
get
(
'id'
)
text
=
parameter
.
text
if
text
and
name
in
(
'ssh-key'
,
'ssh-public-key'
):
text
=
text
[:
20
]
+
'...'
+
text
[
-
20
:]
print
' %s = %s'
%
(
name
,
text
)
logger
.
info
(
' %s = %s'
,
name
,
text
)
def
print_computer_table
(
conn
):
def
log_computer_table
(
logger
,
conn
):
tbl_computer
=
'computer'
+
DB_VERSION
cur
=
conn
.
cursor
()
qry
=
cur
.
execute
(
"SELECT * FROM %s"
%
tbl_computer
)
print_table
(
qry
,
tbl_computer
)
log_table
(
logger
,
qry
,
tbl_computer
)
def
print_software_table
(
conn
):
def
log_software_table
(
logger
,
conn
):
tbl_software
=
'software'
+
DB_VERSION
cur
=
conn
.
cursor
()
qry
=
cur
.
execute
(
"SELECT *, md5(url) as md5 FROM %s"
%
tbl_software
)
print_table
(
qry
,
tbl_software
)
log_table
(
logger
,
qry
,
tbl_software
)
def
print_partition_table
(
conn
):
def
log_partition_table
(
logger
,
conn
):
cur
=
conn
.
cursor
()
qry
=
cur
.
execute
(
"SELECT * FROM %s WHERE slap_state<>'free'"
%
tbl_partition
)
print_table
(
qry
,
tbl_partition
,
skip
=
[
'xml'
,
'connection_xml'
,
'slave_instance_list'
])
log_table
(
logger
,
qry
,
tbl_partition
,
skip
=
[
'xml'
,
'connection_xml'
,
'slave_instance_list'
])
def
print_slave_table
(
conn
):
def
log_slave_table
(
logger
,
conn
):
tbl_slave
=
'slave'
+
DB_VERSION
cur
=
conn
.
cursor
()
qry
=
cur
.
execute
(
"SELECT * FROM %s"
%
tbl_slave
)
print_table
(
qry
,
tbl_slave
,
skip
=
[
'connection_xml'
])
log_table
(
logger
,
qry
,
tbl_slave
,
skip
=
[
'connection_xml'
])
def
print_network
(
conn
):
def
log_network
(
logger
,
conn
):
tbl_partition_network
=
'partition_network'
+
DB_VERSION
cur
=
conn
.
cursor
()
addr
=
collections
.
defaultdict
(
list
)
...
...
@@ -162,39 +162,31 @@ def print_network(conn):
for
partition_reference
in
sorted
(
addr
.
keys
()):
addresses
=
addr
[
partition_reference
]
print
'%s: %s'
%
(
partition_reference
,
', '
.
join
(
addresses
))
logger
.
info
(
'%s: %s'
,
partition_reference
,
', '
.
join
(
addresses
))
def
do_show
(
conf
):
conf
.
logger
.
debug
(
'Using database: %s'
,
conf
.
database_uri
)
conn
=
sqlite3
.
connect
(
conf
.
database_uri
)
conn
.
row_factory
=
sqlite3
.
Row
conn
.
create_function
(
'md5'
,
1
,
lambda
s
:
hashlib
.
md5
(
s
).
hexdigest
())
print_all
=
not
any
([
conf
.
computers
,
conf
.
software
,
conf
.
partitions
,
conf
.
slaves
,
conf
.
params
,
conf
.
network
,
])
if
print_all
or
conf
.
computers
:
print_computer_table
(
conn
)
print
if
print_all
or
conf
.
software
:
print_software_table
(
conn
)
print
if
print_all
or
conf
.
partitions
:
print_partition_table
(
conn
)
print
if
print_all
or
conf
.
slaves
:
print_slave_table
(
conn
)
print
if
print_all
or
conf
.
params
:
print_params
(
conn
)
print
if
print_all
or
conf
.
network
:
print_network
(
conn
)
print
call_table
=
[
(
conf
.
computers
,
log_computer_table
),
(
conf
.
software
,
log_software_table
),
(
conf
.
partitions
,
log_partition_table
),
(
conf
.
slaves
,
log_slave_table
),
(
conf
.
params
,
log_params
),
(
conf
.
network
,
log_network
)
]
if
not
any
(
flag
for
flag
,
func
in
call_table
):
to_call
=
[
func
for
flag
,
func
in
call_table
]
else
:
to_call
=
[
func
for
flag
,
func
in
call_table
if
flag
]
for
idx
,
func
in
enumerate
(
to_call
):
func
(
conf
.
logger
,
conn
)
if
idx
<
len
(
to_call
)
-
1
:
conf
.
logger
.
info
(
' '
)
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