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
Xiaowu Zhang
slapos.core
Commits
472421c4
Commit
472421c4
authored
May 11, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed tests; totally replaced slapproxy-query with 'slapos proxy show'
parent
1209daa2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
115 deletions
+58
-115
setup.py
setup.py
+3
-3
slapos/cli/proxy_show.py
slapos/cli/proxy_show.py
+45
-105
slapos/cli/proxy_start.py
slapos/cli/proxy_start.py
+2
-2
slapos/cli_legacy/proxy_start.py
slapos/cli_legacy/proxy_start.py
+0
-0
slapos/tests/slapproxy.py
slapos/tests/slapproxy.py
+8
-5
No files found.
setup.py
View file @
472421c4
...
@@ -57,8 +57,7 @@ setup(name=name,
...
@@ -57,8 +57,7 @@ setup(name=name,
'console_scripts'
:
[
'console_scripts'
:
[
# One entry point to control them all
# One entry point to control them all
'slapos-watchdog = slapos.grid.watchdog:main'
,
'slapos-watchdog = slapos.grid.watchdog:main'
,
'slapproxy = slapos.cli_legacy.proxy:main'
,
'slapproxy = slapos.cli_legacy.proxy_start:main'
,
'slapproxy-query = slapos.proxy.query:main'
,
'slapos = slapos.cli.entry:main'
,
'slapos = slapos.cli.entry:main'
,
# Deprecated entry points
# Deprecated entry points
'slapconsole = slapos.cli_legacy.console:console'
,
'slapconsole = slapos.cli_legacy.console:console'
,
...
@@ -86,7 +85,8 @@ setup(name=name,
...
@@ -86,7 +85,8 @@ setup(name=name,
'node software = slapos.cli.slapgrid:SoftwareCommand'
,
'node software = slapos.cli.slapgrid:SoftwareCommand'
,
'node instance = slapos.cli.slapgrid:InstanceCommand'
,
'node instance = slapos.cli.slapgrid:InstanceCommand'
,
'console = slapos.cli.console:ConsoleCommand'
,
'console = slapos.cli.console:ConsoleCommand'
,
'proxy start = slapos.cli.proxy:ProxyCommand'
,
'proxy start = slapos.cli.proxy_start:ProxyStartCommand'
,
'proxy show = slapos.cli.proxy_show:ProxyShowCommand'
,
'supply = slapos.cli.supply:SupplyCommand'
,
'supply = slapos.cli.supply:SupplyCommand'
,
'remove = slapos.cli.remove:RemoveCommand'
,
'remove = slapos.cli.remove:RemoveCommand'
,
'request = slapos.cli.request:RequestCommand'
,
'request = slapos.cli.request:RequestCommand'
,
...
...
slapos/
proxy/query
.py
→
slapos/
cli/proxy_show
.py
View file @
472421c4
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# vim: set et sts=4:
import
collections
import
collections
import
ConfigParser
import
logging
from
optparse
import
OptionParser
,
Option
import
sys
from
slapos.cli.config
import
ConfigCommand
from
slapos.proxy
import
ProxyConfig
import
lxml.etree
import
lxml.etree
import
sqlite3
import
sqlite3
...
@@ -12,70 +12,39 @@ import sqlite3
...
@@ -12,70 +12,39 @@ import sqlite3
from
slapos.proxy.db_version
import
DB_VERSION
from
slapos.proxy.db_version
import
DB_VERSION
class
ProxyShowCommand
(
ConfigCommand
):
class
Parser
(
OptionParser
):
"""
"""
Parse all arguments.
display proxy instances and parameters
"""
"""
def
__init__
(
self
,
usage
=
None
,
version
=
None
):
"""
Initialize all options possibles.
"""
OptionParser
.
__init__
(
self
,
usage
=
usage
,
version
=
version
,
option_list
=
[
Option
(
"-u"
,
"--database-uri"
,
type
=
str
,
help
=
"URI for sqlite database"
),
Option
(
'--show-instances'
,
help
=
"View instance information"
,
default
=
False
,
action
=
"store_true"
),
Option
(
'--show-params'
,
help
=
"View published parameters"
,
default
=
False
,
action
=
"store_true"
),
Option
(
'--show-network'
,
help
=
"View network information"
,
default
=
False
,
action
=
"store_true"
),
Option
(
'--show-all'
,
help
=
"View all information"
,
default
=
False
,
action
=
"store_true"
),
])
def
check_args
(
self
):
"""
Check arguments
"""
(
options
,
args
)
=
self
.
parse_args
()
if
len
(
args
)
<
1
:
self
.
error
(
"Incorrect number of arguments"
)
return
options
,
args
[
0
]
class
Config
:
def
setConfig
(
self
,
option_dict
,
configuration_file_path
):
"""
Set options given by parameters.
"""
# Set options parameters
for
option
,
value
in
option_dict
.
__dict__
.
items
():
setattr
(
self
,
option
,
value
)
# Load configuration file
configuration_parser
=
ConfigParser
.
SafeConfigParser
()
configuration_parser
.
read
(
configuration_file_path
)
# Merges the arguments and configuration
for
section
in
(
"slapproxy"
,
"slapos"
):
configuration_dict
=
dict
(
configuration_parser
.
items
(
section
))
for
key
in
configuration_dict
:
if
not
getattr
(
self
,
key
,
None
):
setattr
(
self
,
key
,
configuration_dict
[
key
])
if
not
self
.
database_uri
:
raise
ValueError
(
'database-uri is required.'
)
log
=
logging
.
getLogger
(
'proxy'
)
def
get_parser
(
self
,
prog_name
):
ap
=
super
(
ProxyShowCommand
,
self
).
get_parser
(
prog_name
)
ap
.
add_argument
(
'-u'
,
'--database-uri'
,
help
=
'URI for sqlite database'
)
ap
.
add_argument
(
'--instances'
,
help
=
'view instance information'
,
action
=
'store_true'
)
ap
.
add_argument
(
'--params'
,
help
=
'view published parameters'
,
action
=
'store_true'
)
ap
.
add_argument
(
'--network'
,
help
=
'view network information'
,
action
=
'store_true'
)
return
ap
def
take_action
(
self
,
args
):
configp
=
self
.
fetch_config
(
args
)
conf
=
ProxyConfig
(
logger
=
self
.
log
)
conf
.
mergeConfig
(
args
,
configp
)
conf
.
setConfig
()
do_show
(
conf
=
conf
)
tbl_computer
=
'computer'
+
DB_VERSION
tbl_computer
=
'computer'
+
DB_VERSION
...
@@ -124,7 +93,7 @@ def print_table(qry, tablename, skip=None):
...
@@ -124,7 +93,7 @@ def print_table(qry, tablename, skip=None):
print
print
print
' | '
.
join
(
hdr
)
print
' | '
.
join
(
hdr
)
print
'-+-'
.
join
(
'-'
*
len
(
h
)
for
h
in
hdr
)
print
'-+-'
.
join
(
'-'
*
len
(
h
)
for
h
in
hdr
)
for
row
in
rows
:
for
row
in
rows
:
cells
=
[
row
[
col
].
ljust
(
max_width
[
col
])
for
col
in
columns
]
cells
=
[
row
[
col
].
ljust
(
max_width
[
col
])
for
col
in
columns
]
...
@@ -170,6 +139,7 @@ def print_partition_table(conn):
...
@@ -170,6 +139,7 @@ def print_partition_table(conn):
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'
])
print_table
(
qry
,
tbl_partition
,
skip
=
[
'xml'
,
'connection_xml'
,
'slave_instance_list'
])
def
print_slave_table
(
conn
):
def
print_slave_table
(
conn
):
cur
=
conn
.
cursor
()
cur
=
conn
.
cursor
()
qry
=
cur
.
execute
(
"SELECT * FROM %s"
%
tbl_slave
)
qry
=
cur
.
execute
(
"SELECT * FROM %s"
%
tbl_slave
)
...
@@ -202,45 +172,15 @@ def print_network(conn):
...
@@ -202,45 +172,15 @@ def print_network(conn):
print
'%s: %s'
%
(
partition_reference
,
', '
.
join
(
addresses
))
print
'%s: %s'
%
(
partition_reference
,
', '
.
join
(
addresses
))
def
do_show
(
conf
):
conn
=
sqlite3
.
connect
(
conf
.
database_uri
)
def
run
(
config
):
conn
=
sqlite3
.
connect
(
config
.
database_uri
)
conn
.
row_factory
=
sqlite3
.
Row
conn
.
row_factory
=
sqlite3
.
Row
fn
=
[]
print_all
=
(
not
conf
.
instances
and
not
conf
.
params
and
not
conf
.
network
)
if
config
.
show_all
or
config
.
show_instances
:
fn
.
append
(
print_tables
)
if
config
.
show_all
or
config
.
show_params
:
fn
.
append
(
print_params
)
if
config
.
show_all
or
config
.
show_network
:
fn
.
append
(
print_network
)
if
fn
:
for
f
in
fn
:
f
(
conn
)
else
:
print
'usage: %s [ --show-params | --show-network | --show-instances | --show-all ]'
%
sys
.
argv
[
0
]
def
main
():
"Run default configuration."
usage
=
"usage: %s [options] CONFIGURATION_FILE"
%
sys
.
argv
[
0
]
try
:
# Parse arguments
config
=
Config
()
config
.
setConfig
(
*
Parser
(
usage
=
usage
).
check_args
())
run
(
config
)
return_code
=
0
except
SystemExit
,
err
:
# Catch exception raise by optparse
return_code
=
err
sys
.
exit
(
return_code
)
if
print_all
or
conf
.
instances
:
print_tables
(
conn
)
if
print_all
or
conf
.
params
:
print_params
(
conn
)
if
print_all
or
conf
.
network
:
print_network
(
conn
)
slapos/cli/proxy.py
→
slapos/cli/proxy
_start
.py
View file @
472421c4
...
@@ -6,7 +6,7 @@ from slapos.cli.config import ConfigCommand
...
@@ -6,7 +6,7 @@ from slapos.cli.config import ConfigCommand
from
slapos.proxy
import
do_proxy
,
ProxyConfig
from
slapos.proxy
import
do_proxy
,
ProxyConfig
class
ProxyCommand
(
ConfigCommand
):
class
Proxy
Start
Command
(
ConfigCommand
):
"""
"""
minimalist, stand-alone SlapOS Master
minimalist, stand-alone SlapOS Master
"""
"""
...
@@ -14,7 +14,7 @@ class ProxyCommand(ConfigCommand):
...
@@ -14,7 +14,7 @@ class ProxyCommand(ConfigCommand):
log
=
logging
.
getLogger
(
'proxy'
)
log
=
logging
.
getLogger
(
'proxy'
)
def
get_parser
(
self
,
prog_name
):
def
get_parser
(
self
,
prog_name
):
ap
=
super
(
ProxyCommand
,
self
).
get_parser
(
prog_name
)
ap
=
super
(
Proxy
Start
Command
,
self
).
get_parser
(
prog_name
)
ap
.
add_argument
(
'-u'
,
'--database-uri'
,
ap
.
add_argument
(
'-u'
,
'--database-uri'
,
help
=
'URI for sqlite database'
)
help
=
'URI for sqlite database'
)
...
...
slapos/cli_legacy/proxy.py
→
slapos/cli_legacy/proxy
_start
.py
View file @
472421c4
File moved
slapos/tests/slapproxy.py
View file @
472421c4
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
#
#
##############################################################################
##############################################################################
import
ConfigParser
import
os
import
os
import
logging
import
logging
import
shutil
import
shutil
...
@@ -86,14 +87,16 @@ database_uri = %(tempdir)s/lib/proxy.db
...
@@ -86,14 +87,16 @@ database_uri = %(tempdir)s/lib/proxy.db
"""
"""
Set config for slapproxy and start it
Set config for slapproxy and start it
"""
"""
config
=
slapos
.
proxy
.
ProxyConfig
()
conf
=
slapos
.
proxy
.
ProxyConfig
(
logger
=
logging
.
getLogger
())
config
.
setConfig
(
*
(
ProxyOption
(
self
.
proxy_db
),
configp
=
ConfigParser
.
SafeConfigParser
()
self
.
slapos_cfg
))
configp
.
read
(
self
.
slapos_cfg
)
conf
.
mergeConfig
(
ProxyOption
(
self
.
proxy_db
),
configp
)
conf
.
setConfig
()
views
.
app
.
config
[
'TESTING'
]
=
True
views
.
app
.
config
[
'TESTING'
]
=
True
views
.
app
.
config
[
'computer_id'
]
=
self
.
computer_id
views
.
app
.
config
[
'computer_id'
]
=
self
.
computer_id
views
.
app
.
config
[
'DATABASE_URI'
]
=
self
.
proxy_db
views
.
app
.
config
[
'DATABASE_URI'
]
=
self
.
proxy_db
views
.
app
.
config
[
'HOST'
]
=
conf
ig
.
host
views
.
app
.
config
[
'HOST'
]
=
conf
.
host
views
.
app
.
config
[
'port'
]
=
conf
ig
.
port
views
.
app
.
config
[
'port'
]
=
conf
.
port
self
.
app
=
views
.
app
.
test_client
()
self
.
app
=
views
.
app
.
test_client
()
def
add_free_partition
(
self
,
partition_amount
):
def
add_free_partition
(
self
,
partition_amount
):
...
...
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