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
Labels
Merge Requests
18
Merge Requests
18
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
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):
...
@@ -71,7 +71,7 @@ def coalesce(*seq):
return
el
return
el
def
print_table
(
qry
,
tablename
,
skip
=
None
):
def
log_table
(
logger
,
qry
,
tablename
,
skip
=
None
):
if
skip
is
None
:
if
skip
is
None
:
skip
=
set
()
skip
=
set
()
...
@@ -88,19 +88,19 @@ def print_table(qry, tablename, skip=None):
...
@@ -88,19 +88,19 @@ def print_table(qry, tablename, skip=None):
pt
.
add_row
(
row
)
pt
.
add_row
(
row
)
if
rows
:
if
rows
:
print
'table %s:'
%
tablename
,
if
skip
:
if
skip
:
print
'skipping %s'
%
', '
.
join
(
skip
)
logger
.
info
(
'table %s: skipping %s'
,
tablename
,
', '
.
join
(
skip
)
)
else
:
else
:
print
logger
.
info
(
'table %s'
,
tablename
)
else
:
else
:
print
'table %s: empty'
%
tablename
logger
.
info
(
'table %s: empty'
,
tablename
)
return
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
()
cur
=
conn
.
cursor
()
qry
=
cur
.
execute
(
"SELECT reference, partition_reference, software_type, connection_xml FROM %s"
%
tbl_partition
)
qry
=
cur
.
execute
(
"SELECT reference, partition_reference, software_type, connection_xml FROM %s"
%
tbl_partition
)
...
@@ -109,44 +109,44 @@ def print_params(conn):
...
@@ -109,44 +109,44 @@ def print_params(conn):
continue
continue
xml
=
str
(
row
[
'connection_xml'
])
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
)
instance
=
lxml
.
etree
.
fromstring
(
xml
)
for
parameter
in
list
(
instance
):
for
parameter
in
list
(
instance
):
name
=
parameter
.
get
(
'id'
)
name
=
parameter
.
get
(
'id'
)
text
=
parameter
.
text
text
=
parameter
.
text
if
text
and
name
in
(
'ssh-key'
,
'ssh-public-key'
):
if
text
and
name
in
(
'ssh-key'
,
'ssh-public-key'
):
text
=
text
[:
20
]
+
'...'
+
text
[
-
20
:]
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
tbl_computer
=
'computer'
+
DB_VERSION
cur
=
conn
.
cursor
()
cur
=
conn
.
cursor
()
qry
=
cur
.
execute
(
"SELECT * FROM %s"
%
tbl_computer
)
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
tbl_software
=
'software'
+
DB_VERSION
cur
=
conn
.
cursor
()
cur
=
conn
.
cursor
()
qry
=
cur
.
execute
(
"SELECT *, md5(url) as md5 FROM %s"
%
tbl_software
)
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
()
cur
=
conn
.
cursor
()
qry
=
cur
.
execute
(
"SELECT * FROM %s WHERE slap_state<>'free'"
%
tbl_partition
)
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
tbl_slave
=
'slave'
+
DB_VERSION
cur
=
conn
.
cursor
()
cur
=
conn
.
cursor
()
qry
=
cur
.
execute
(
"SELECT * FROM %s"
%
tbl_slave
)
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
tbl_partition_network
=
'partition_network'
+
DB_VERSION
cur
=
conn
.
cursor
()
cur
=
conn
.
cursor
()
addr
=
collections
.
defaultdict
(
list
)
addr
=
collections
.
defaultdict
(
list
)
...
@@ -162,39 +162,31 @@ def print_network(conn):
...
@@ -162,39 +162,31 @@ def print_network(conn):
for
partition_reference
in
sorted
(
addr
.
keys
()):
for
partition_reference
in
sorted
(
addr
.
keys
()):
addresses
=
addr
[
partition_reference
]
addresses
=
addr
[
partition_reference
]
print
'%s: %s'
%
(
partition_reference
,
', '
.
join
(
addresses
))
logger
.
info
(
'%s: %s'
,
partition_reference
,
', '
.
join
(
addresses
))
def
do_show
(
conf
):
def
do_show
(
conf
):
conf
.
logger
.
debug
(
'Using database: %s'
,
conf
.
database_uri
)
conn
=
sqlite3
.
connect
(
conf
.
database_uri
)
conn
=
sqlite3
.
connect
(
conf
.
database_uri
)
conn
.
row_factory
=
sqlite3
.
Row
conn
.
row_factory
=
sqlite3
.
Row
conn
.
create_function
(
'md5'
,
1
,
lambda
s
:
hashlib
.
md5
(
s
).
hexdigest
())
conn
.
create_function
(
'md5'
,
1
,
lambda
s
:
hashlib
.
md5
(
s
).
hexdigest
())
print_all
=
not
any
([
call_table
=
[
conf
.
computers
,
(
conf
.
computers
,
log_computer_table
),
conf
.
software
,
(
conf
.
software
,
log_software_table
),
conf
.
partitions
,
(
conf
.
partitions
,
log_partition_table
),
conf
.
slaves
,
(
conf
.
slaves
,
log_slave_table
),
conf
.
params
,
(
conf
.
params
,
log_params
),
conf
.
network
,
(
conf
.
network
,
log_network
)
])
]
if
print_all
or
conf
.
computers
:
if
not
any
(
flag
for
flag
,
func
in
call_table
):
print_computer_table
(
conn
)
to_call
=
[
func
for
flag
,
func
in
call_table
]
print
else
:
if
print_all
or
conf
.
software
:
to_call
=
[
func
for
flag
,
func
in
call_table
if
flag
]
print_software_table
(
conn
)
print
for
idx
,
func
in
enumerate
(
to_call
):
if
print_all
or
conf
.
partitions
:
func
(
conf
.
logger
,
conn
)
print_partition_table
(
conn
)
if
idx
<
len
(
to_call
)
-
1
:
print
conf
.
logger
.
info
(
' '
)
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
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