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
Lu Xu
slapos.core
Commits
51b2e8ef
Commit
51b2e8ef
authored
May 12, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
split into further options, added md5(url)
parent
a70ab87e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
30 deletions
+54
-30
slapos/cli/proxy_show.py
slapos/cli/proxy_show.py
+54
-30
No files found.
slapos/cli/proxy_show.py
View file @
51b2e8ef
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
collections
import
collections
import
hashlib
import
logging
import
logging
import
lxml.etree
import
lxml.etree
...
@@ -25,8 +26,20 @@ class ProxyShowCommand(ConfigCommand):
...
@@ -25,8 +26,20 @@ class ProxyShowCommand(ConfigCommand):
ap
.
add_argument
(
'-u'
,
'--database-uri'
,
ap
.
add_argument
(
'-u'
,
'--database-uri'
,
help
=
'URI for sqlite database'
)
help
=
'URI for sqlite database'
)
ap
.
add_argument
(
'--instances'
,
ap
.
add_argument
(
'--computers'
,
help
=
'view instance information'
,
help
=
'view computer information'
,
action
=
'store_true'
)
ap
.
add_argument
(
'--software'
,
help
=
'view software releases'
,
action
=
'store_true'
)
ap
.
add_argument
(
'--partitions'
,
help
=
'view partitions'
,
action
=
'store_true'
)
ap
.
add_argument
(
'--slaves'
,
help
=
'view slave instances'
,
action
=
'store_true'
)
action
=
'store_true'
)
ap
.
add_argument
(
'--params'
,
ap
.
add_argument
(
'--params'
,
...
@@ -34,7 +47,7 @@ class ProxyShowCommand(ConfigCommand):
...
@@ -34,7 +47,7 @@ class ProxyShowCommand(ConfigCommand):
action
=
'store_true'
)
action
=
'store_true'
)
ap
.
add_argument
(
'--network'
,
ap
.
add_argument
(
'--network'
,
help
=
'view network
information
'
,
help
=
'view network
settings
'
,
action
=
'store_true'
)
action
=
'store_true'
)
return
ap
return
ap
...
@@ -47,11 +60,7 @@ class ProxyShowCommand(ConfigCommand):
...
@@ -47,11 +60,7 @@ class ProxyShowCommand(ConfigCommand):
do_show
(
conf
=
conf
)
do_show
(
conf
=
conf
)
tbl_computer
=
'computer'
+
DB_VERSION
tbl_software
=
'software'
+
DB_VERSION
tbl_partition
=
'partition'
+
DB_VERSION
tbl_partition
=
'partition'
+
DB_VERSION
tbl_partition_network
=
'partition_network'
+
DB_VERSION
tbl_slave
=
'slave'
+
DB_VERSION
def
coalesce
(
*
seq
):
def
coalesce
(
*
seq
):
...
@@ -63,7 +72,6 @@ def coalesce(*seq):
...
@@ -63,7 +72,6 @@ def coalesce(*seq):
def
print_table
(
qry
,
tablename
,
skip
=
None
):
def
print_table
(
qry
,
tablename
,
skip
=
None
):
if
skip
is
None
:
if
skip
is
None
:
skip
=
set
()
skip
=
set
()
...
@@ -81,24 +89,20 @@ def print_table(qry, tablename, skip=None):
...
@@ -81,24 +89,20 @@ def print_table(qry, tablename, skip=None):
if
rows
:
if
rows
:
print
'table %s:'
%
tablename
,
print
'table %s:'
%
tablename
,
if
skip
:
print
'skipping %s'
%
', '
.
join
(
skip
)
else
:
print
else
:
else
:
print
'table %s: empty'
%
tablename
print
'table %s: empty'
%
tablename
return
return
if
skip
:
print
'skipping %s'
%
', '
.
join
(
skip
)
else
:
print
print
pt
.
get_string
(
border
=
True
,
padding_width
=
0
,
vrules
=
prettytable
.
NONE
)
print
pt
.
get_string
(
border
=
True
,
padding_width
=
0
,
vrules
=
prettytable
.
NONE
)
print
def
print_params
(
conn
):
def
print_params
(
conn
):
cur
=
conn
.
cursor
()
cur
=
conn
.
cursor
()
print
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
)
for
row
in
qry
.
fetchall
():
for
row
in
qry
.
fetchall
():
if
not
row
[
'connection_xml'
]:
if
not
row
[
'connection_xml'
]:
...
@@ -113,18 +117,19 @@ def print_params(conn):
...
@@ -113,18 +117,19 @@ def print_params(conn):
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
)
print
' %s = %s'
%
(
name
,
text
)
print
def
print_computer_table
(
conn
):
def
print_computer_table
(
conn
):
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
)
print_table
(
qry
,
tbl_computer
)
def
print_software_table
(
conn
):
def
print_software_table
(
conn
):
tbl_software
=
'software'
+
DB_VERSION
cur
=
conn
.
cursor
()
cur
=
conn
.
cursor
()
qry
=
cur
.
execute
(
"SELECT * FROM %s"
%
tbl_software
)
qry
=
cur
.
execute
(
"SELECT *
, md5(url) as md5
FROM %s"
%
tbl_software
)
print_table
(
qry
,
tbl_software
)
print_table
(
qry
,
tbl_software
)
...
@@ -135,20 +140,14 @@ def print_partition_table(conn):
...
@@ -135,20 +140,14 @@ def print_partition_table(conn):
def
print_slave_table
(
conn
):
def
print_slave_table
(
conn
):
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'
])
print_table
(
qry
,
tbl_slave
,
skip
=
[
'connection_xml'
])
def
print_tables
(
conn
):
print_computer_table
(
conn
)
print_software_table
(
conn
)
print_partition_table
(
conn
)
print_slave_table
(
conn
)
def
print_network
(
conn
):
def
print_network
(
conn
):
print
tbl_partition_network
=
'partition_network'
+
DB_VERSION
cur
=
conn
.
cursor
()
cur
=
conn
.
cursor
()
addr
=
collections
.
defaultdict
(
list
)
addr
=
collections
.
defaultdict
(
list
)
qry
=
cur
.
execute
(
"""
qry
=
cur
.
execute
(
"""
...
@@ -170,11 +169,36 @@ def do_show(conf):
...
@@ -170,11 +169,36 @@ def do_show(conf):
conn
=
sqlite3
.
connect
(
conf
.
database_uri
)
conn
=
sqlite3
.
connect
(
conf
.
database_uri
)
conn
.
row_factory
=
sqlite3
.
Row
conn
.
row_factory
=
sqlite3
.
Row
print_all
=
(
not
conf
.
instances
and
not
conf
.
params
and
not
conf
.
network
)
conn
.
create_function
(
'md5'
,
1
,
lambda
s
:
hashlib
.
md5
(
s
).
hexdigest
())
if
print_all
or
conf
.
instances
:
print_all
=
not
any
(
print_tables
(
conn
)
[
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
:
if
print_all
or
conf
.
params
:
print_params
(
conn
)
print_params
(
conn
)
print
if
print_all
or
conf
.
network
:
if
print_all
or
conf
.
network
:
print_network
(
conn
)
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